001 /*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License"). You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2006-2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.controls;
028 import org.opends.messages.Message;
029
030
031
032 import static org.opends.messages.ProtocolMessages.*;
033
034
035
036 /**
037 * This enumeration defines the set of password policy errors that may be
038 * included in the password policy response control defined in
039 * draft-behera-ldap-password-policy.
040 */
041 public enum PasswordPolicyErrorType
042 {
043 /**
044 * The error type that will be used to indicate that the user's password is
045 * expired.
046 */
047 PASSWORD_EXPIRED(PasswordPolicyErrorType.TYPE_PASSWORD_EXPIRED,
048 INFO_PWPERRTYPE_DESCRIPTION_PASSWORD_EXPIRED.get()),
049
050
051
052 /**
053 * The error type that will be used to indicate that the user's account is
054 * locked.
055 */
056 ACCOUNT_LOCKED(PasswordPolicyErrorType.TYPE_ACCOUNT_LOCKED,
057 INFO_PWPERRTYPE_DESCRIPTION_ACCOUNT_LOCKED.get()),
058
059
060
061 /**
062 * The error type that will be used to indicate that the user's password must
063 * be changed because it has been administratively reset.
064 */
065 CHANGE_AFTER_RESET(PasswordPolicyErrorType.TYPE_CHANGE_AFTER_RESET,
066 INFO_PWPERRTYPE_DESCRIPTION_CHANGE_AFTER_RESET.get()),
067
068
069
070 /**
071 * The error type that will be used to indicate that user password changes are
072 * not allowed.
073 */
074 PASSWORD_MOD_NOT_ALLOWED(
075 PasswordPolicyErrorType.TYPE_PASSWORD_MOD_NOT_ALLOWED,
076 INFO_PWPERRTYPE_DESCRIPTION_PASSWORD_MOD_NOT_ALLOWED.get()),
077
078
079
080 /**
081 * The error type that will be used to indicate that the user's current
082 * password must be provided in order to choose a new password.
083 */
084 MUST_SUPPLY_OLD_PASSWORD(
085 PasswordPolicyErrorType.TYPE_MUST_SUPPLY_OLD_PASSWORD,
086 INFO_PWPERRTYPE_DESCRIPTION_MUST_SUPPLY_OLD_PASSWORD.get()),
087
088
089
090 /**
091 * The error type that will be used to indicate that the provided password is
092 * not acceptable according to the configured password validators.
093 */
094 INSUFFICIENT_PASSWORD_QUALITY(
095 PasswordPolicyErrorType.TYPE_INSUFFICIENT_PASSWORD_QUALITY,
096 INFO_PWPERRTYPE_DESCRIPTION_INSUFFICIENT_PASSWORD_QUALITY.get()),
097
098
099
100 /**
101 * The error type that will be used to indicate that the provided password is
102 * too short.
103 */
104 PASSWORD_TOO_SHORT(PasswordPolicyErrorType.TYPE_PASSWORD_TOO_SHORT,
105 INFO_PWPERRTYPE_DESCRIPTION_PASSWORD_TOO_SHORT.get()),
106
107
108
109 /**
110 * The error type that will be used to indicate that the user's password is
111 * too young (i.e., it was changed too recently to allow it to be changed
112 * again).
113 */
114 PASSWORD_TOO_YOUNG(PasswordPolicyErrorType.TYPE_PASSWORD_TOO_YOUNG,
115 INFO_PWPERRTYPE_DESCRIPTION_PASSWORD_TOO_YOUNG.get()),
116
117
118
119 /**
120 * The error type that will be used to indicate that the provided password is
121 * in the user's password history.
122 */
123 PASSWORD_IN_HISTORY(PasswordPolicyErrorType.TYPE_PASSWORD_IN_HISTORY,
124 INFO_PWPERRTYPE_DESCRIPTION_PASSWORD_IN_HISTORY.get());
125
126
127
128 /**
129 * The value that will be used for the passwordExpired type.
130 */
131 public static final int TYPE_PASSWORD_EXPIRED = 0;
132
133
134
135 /**
136 * The value that will be used for the accountLocked type.
137 */
138 public static final int TYPE_ACCOUNT_LOCKED = 1;
139
140
141
142 /**
143 * The value that will be used for the changeAfterReset type.
144 */
145 public static final int TYPE_CHANGE_AFTER_RESET = 2;
146
147
148
149 /**
150 * The value that will be used for the passwordModNotAllowed type.
151 */
152 public static final int TYPE_PASSWORD_MOD_NOT_ALLOWED = 3;
153
154
155
156 /**
157 * The value that will be used for the mustSupplyOldPassword type.
158 */
159 public static final int TYPE_MUST_SUPPLY_OLD_PASSWORD = 4;
160
161
162
163 /**
164 * The value that will be used for the insufficientPasswordQuality type.
165 */
166 public static final int TYPE_INSUFFICIENT_PASSWORD_QUALITY = 5;
167
168
169
170 /**
171 * The value that will be used for the passwordTooShort type.
172 */
173 public static final int TYPE_PASSWORD_TOO_SHORT = 6;
174
175
176
177 /**
178 * The value that will be used for the passwordTooYoung type.
179 */
180 public static final int TYPE_PASSWORD_TOO_YOUNG = 7;
181
182
183
184 /**
185 * The value that will be used for the passwordInHistory type.
186 */
187 public static final int TYPE_PASSWORD_IN_HISTORY = 8;
188
189
190
191 // The integer value associated with the error type to use in the associated
192 // enumerated element in the password policy response control.
193 private int value;
194
195 // The message ID for the description of this password policy error type.
196 private Message description;
197
198
199
200 /**
201 * Creates a new instance of a password policy error type with the provided
202 * value.
203 *
204 * @param value The integer value associated with the error type to
205 * use in the associated enumerated element in the
206 * password policy response control.
207 * @param description The message for the description of this password
208 * policy error type.
209 */
210 private PasswordPolicyErrorType(int value, Message description)
211 {
212 this.value = value;
213 this.description = description;
214 }
215
216
217
218 /**
219 * Retrieves the integer value associated with the error type to use in the
220 * associated enumerated element in the password policy response control.
221 *
222 * @return The integer value associated with the error type to use in the
223 * associated enumerated element in the password policy response
224 * control.
225 */
226 public int intValue()
227 {
228 return value;
229 }
230
231
232
233 /**
234 * Retrieves the password policy error type for the provided integer value.
235 *
236 * @param value The value for which to retrieve the corresponding error
237 * type.
238 *
239 * @return The requested password policy error type, or <CODE>null</CODE> if
240 * the provided value does not match any error types.
241 */
242 public static PasswordPolicyErrorType valueOf(int value)
243 {
244 switch (value)
245 {
246 case TYPE_PASSWORD_EXPIRED:
247 return PasswordPolicyErrorType.PASSWORD_EXPIRED;
248 case TYPE_ACCOUNT_LOCKED:
249 return PasswordPolicyErrorType.ACCOUNT_LOCKED;
250 case TYPE_CHANGE_AFTER_RESET:
251 return PasswordPolicyErrorType.CHANGE_AFTER_RESET;
252 case TYPE_PASSWORD_MOD_NOT_ALLOWED:
253 return PasswordPolicyErrorType.PASSWORD_MOD_NOT_ALLOWED;
254 case TYPE_MUST_SUPPLY_OLD_PASSWORD:
255 return PasswordPolicyErrorType.MUST_SUPPLY_OLD_PASSWORD;
256 case TYPE_INSUFFICIENT_PASSWORD_QUALITY:
257 return PasswordPolicyErrorType.INSUFFICIENT_PASSWORD_QUALITY;
258 case TYPE_PASSWORD_TOO_SHORT:
259 return PasswordPolicyErrorType.PASSWORD_TOO_SHORT;
260 case TYPE_PASSWORD_TOO_YOUNG:
261 return PasswordPolicyErrorType.PASSWORD_TOO_YOUNG;
262 case TYPE_PASSWORD_IN_HISTORY:
263 return PasswordPolicyErrorType.PASSWORD_IN_HISTORY;
264 default:
265 return null;
266 }
267 }
268
269
270
271 /**
272 * Retrieves a string representation of this password policy error type.
273 *
274 * @return A string representation of this password policy error type.
275 */
276 public String toString()
277 {
278 return description.toString();
279 }
280 }
281