001/* 002 * Copyright 2007-2017 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2015-2017 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.ldap.sdk.unboundidds.controls; 022 023 024 025import com.unboundid.ldap.sdk.Control; 026import com.unboundid.ldap.sdk.LDAPException; 027import com.unboundid.ldap.sdk.ResultCode; 028import com.unboundid.util.NotMutable; 029import com.unboundid.util.ThreadSafety; 030import com.unboundid.util.ThreadSafetyLevel; 031 032import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*; 033 034 035 036/** 037 * This class provides an implementation of the password policy request control 038 * as described in draft-behera-ldap-password-policy. It may be used to request 039 * information related to a user's password policy. In the Ping Identity, 040 * UnboundID, and Alcatel-Lucent 8661 Directory Server, this control may be 041 * included with add, bind, compare, modify, and password modify requests. 042 * <BR> 043 * <BLOCKQUOTE> 044 * <B>NOTE:</B> This class, and other classes within the 045 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 046 * supported for use against Ping Identity, UnboundID, and Alcatel-Lucent 8661 047 * server products. These classes provide support for proprietary 048 * functionality or for external specifications that are not considered stable 049 * or mature enough to be guaranteed to work in an interoperable way with 050 * other types of LDAP servers. 051 * </BLOCKQUOTE> 052 * <BR> 053 * The corresponding {@link PasswordPolicyResponseControl} may include at most 054 * one warning from the set of {@link PasswordPolicyWarningType} values and at 055 * most one error from the set of {@link PasswordPolicyErrorType} values. See 056 * the documentation for those classes for more information on the information 057 * that may be included. 058 * <BR><BR> 059 * <H2>Example</H2> 060 * The following example demonstrates the use of the password policy request 061 * control in conjunction with a bind operation: 062 * <PRE> 063 * SimpleBindRequest bindRequest = new SimpleBindRequest( 064 * "uid=john.doe,ou=People,dc=example,dc=com", "password", 065 * new PasswordPolicyRequestControl()); 066 * 067 * BindResult bindResult; 068 * try 069 * { 070 * bindResult = connection.bind(bindRequest); 071 * } 072 * catch (LDAPException le) 073 * { 074 * // The bind failed. There may be a password policy response control to 075 * // help tell us why. 076 * bindResult = new BindResult(le.toLDAPResult()); 077 * } 078 * 079 * PasswordPolicyResponseControl pwpResponse = 080 * PasswordPolicyResponseControl.get(bindResult); 081 * if (pwpResponse != null) 082 * { 083 * PasswordPolicyErrorType errorType = pwpResponse.getErrorType(); 084 * if (errorType != null) 085 * { 086 * // There was a password policy-related error. 087 * } 088 * 089 * PasswordPolicyWarningType warningType = pwpResponse.getWarningType(); 090 * if (warningType != null) 091 * { 092 * // There was a password policy-related warning. 093 * int value = pwpResponse.getWarningValue(); 094 * switch (warningType) 095 * { 096 * case TIME_BEFORE_EXPIRATION: 097 * // The warning value is the number of seconds until the user's 098 * // password expires. 099 * break; 100 * case GRACE_LOGINS_REMAINING: 101 * // The warning value is the number of grace logins remaining for 102 * // the user. 103 * } 104 * } 105 * } 106 * </PRE> 107 */ 108@NotMutable() 109@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 110public final class PasswordPolicyRequestControl 111 extends Control 112{ 113 /** 114 * The OID (1.3.6.1.4.1.42.2.27.8.5.1) for the password policy request 115 * control. 116 */ 117 public static final String PASSWORD_POLICY_REQUEST_OID = 118 "1.3.6.1.4.1.42.2.27.8.5.1"; 119 120 121 122 /** 123 * The serial version UID for this serializable class. 124 */ 125 private static final long serialVersionUID = 6495056761590890150L; 126 127 128 129 /** 130 * Creates a new password policy request control. The control will not be 131 * marked critical. 132 */ 133 public PasswordPolicyRequestControl() 134 { 135 super(PASSWORD_POLICY_REQUEST_OID, false, null); 136 } 137 138 139 140 /** 141 * Creates a new password policy request control. 142 * 143 * @param isCritical Indicates whether the control should be marked 144 * critical. 145 */ 146 public PasswordPolicyRequestControl(final boolean isCritical) 147 { 148 super(PASSWORD_POLICY_REQUEST_OID, isCritical, null); 149 } 150 151 152 153 /** 154 * Creates a new password policy request control which is decoded from the 155 * provided generic control. 156 * 157 * @param control The generic control to be decoded as a password policy 158 * request control. 159 * 160 * @throws LDAPException If the provided control cannot be decoded as a 161 * password policy request control. 162 */ 163 public PasswordPolicyRequestControl(final Control control) 164 throws LDAPException 165 { 166 super(control); 167 168 if (control.hasValue()) 169 { 170 throw new LDAPException(ResultCode.DECODING_ERROR, 171 ERR_PWP_REQUEST_HAS_VALUE.get()); 172 } 173 } 174 175 176 177 /** 178 * {@inheritDoc} 179 */ 180 @Override() 181 public String getControlName() 182 { 183 return INFO_CONTROL_NAME_PW_POLICY_REQUEST.get(); 184 } 185 186 187 188 /** 189 * {@inheritDoc} 190 */ 191 @Override() 192 public void toString(final StringBuilder buffer) 193 { 194 buffer.append("PasswordPolicyRequestControl(isCritical="); 195 buffer.append(isCritical()); 196 buffer.append(')'); 197 } 198}