001/*
002 * Copyright 2007-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2007-2020 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2015-2020 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.controls;
037
038
039
040import com.unboundid.util.StaticUtils;
041import com.unboundid.util.ThreadSafety;
042import com.unboundid.util.ThreadSafetyLevel;
043
044
045
046/**
047 * This enum defines a set of error types that may be included in the password
048 * policy response control as defined in draft-behera-ldap-password-policy.
049 * <BR>
050 * <BLOCKQUOTE>
051 *   <B>NOTE:</B>  This class, and other classes within the
052 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
053 *   supported for use against Ping Identity, UnboundID, and
054 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
055 *   for proprietary functionality or for external specifications that are not
056 *   considered stable or mature enough to be guaranteed to work in an
057 *   interoperable way with other types of LDAP servers.
058 * </BLOCKQUOTE>
059 */
060@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
061public enum PasswordPolicyErrorType
062{
063  /**
064   * The error type that indicates the user's password is expired.
065   */
066  PASSWORD_EXPIRED("password expired", 0),
067
068
069
070  /**
071   * The error type that indicates the user's account is locked or disabled.
072   */
073  ACCOUNT_LOCKED("account locked", 1),
074
075
076
077  /**
078   * The error type that indicates the user's password must be changed before
079   * any other operation will be allowed.
080   */
081  CHANGE_AFTER_RESET("change after reset", 2),
082
083
084
085  /**
086   * The error type that indicates that user password changes aren't allowed.
087   */
088  PASSWORD_MOD_NOT_ALLOWED("password mod not allowed", 3),
089
090
091
092  /**
093   * The error type that indicates the user must provide the current password
094   * when attempting to set a new one.
095   */
096  MUST_SUPPLY_OLD_PASSWORD("must supply old password", 4),
097
098
099
100  /**
101   * The error type that indicates the proposed password is too weak to be
102   * acceptable.
103   */
104  INSUFFICIENT_PASSWORD_QUALITY("insufficient password quality", 5),
105
106
107
108  /**
109   * The error type that indicates the proposed password is too short.
110   */
111  PASSWORD_TOO_SHORT("password too short", 6),
112
113
114
115  /**
116   * The error type that indicates the user's password cannot be changed because
117   * it has not been long enough since it was last changed.
118   */
119  PASSWORD_TOO_YOUNG("password too young", 7),
120
121
122
123  /**
124   * The error type that indicates the proposed password is already in the
125   * password history.
126   */
127  PASSWORD_IN_HISTORY("password in history", 8);
128
129
130
131  // The numeric value associated with this password policy error type.
132  private final int value;
133
134  // The human-readable name for this password policy error type.
135  private final String name;
136
137
138
139  /**
140   * Creates a new password policy error type with the provided information.
141   *
142   * @param  name   The human-readable name for this error type.
143   * @param  value  The numeric value associated with this error type.
144   */
145  PasswordPolicyErrorType(final String name, final int value)
146  {
147    this.name  = name;
148    this.value = value;
149  }
150
151
152
153  /**
154   * Retrieves the human-readable name for this password policy error type.
155   *
156   * @return  The human-readable name for this password policy error type.
157   */
158  public String getName()
159  {
160    return name;
161  }
162
163
164
165  /**
166   * Retrieves the integer value for this password policy error type.
167   *
168   * @return  The integer value for this password policy error type.
169   */
170  public int intValue()
171  {
172    return value;
173  }
174
175
176
177  /**
178   * Retrieves the password policy error type with the specified int value.
179   *
180   * @param  intValue  The numeric value associated with the error type.
181   *
182   * @return  The associated error type, or {@code null} if there is no
183   *          password policy error type with the specified set of values.
184   */
185  public static PasswordPolicyErrorType valueOf(final int intValue)
186  {
187    switch (intValue)
188    {
189      case 0:
190        return PASSWORD_EXPIRED;
191
192      case 1:
193        return ACCOUNT_LOCKED;
194
195      case 2:
196        return CHANGE_AFTER_RESET;
197
198      case 3:
199        return PASSWORD_MOD_NOT_ALLOWED;
200
201      case 4:
202        return MUST_SUPPLY_OLD_PASSWORD;
203
204      case 5:
205        return INSUFFICIENT_PASSWORD_QUALITY;
206
207      case 6:
208        return PASSWORD_TOO_SHORT;
209
210      case 7:
211        return PASSWORD_TOO_YOUNG;
212
213      case 8:
214        return PASSWORD_IN_HISTORY;
215
216      default:
217        return null;
218    }
219  }
220
221
222
223  /**
224   * Retrieves the password policy error type with the specified name.
225   *
226   * @param  name  The name of the password policy error type to retrieve.  It
227   *               must not be {@code null}.
228   *
229   * @return  The requested password policy error type, or {@code null} if no
230   *          such type is defined.
231   */
232  public static PasswordPolicyErrorType forName(final String name)
233  {
234    switch (StaticUtils.toLowerCase(name))
235    {
236      case "passwordexpired":
237      case "password-expired":
238      case "password_expired":
239      case "password expired":
240        return PASSWORD_EXPIRED;
241      case "accountlocked":
242      case "account-locked":
243      case "account_locked":
244      case "account locked":
245        return ACCOUNT_LOCKED;
246      case "changeafterreset":
247      case "change-after-reset":
248      case "change_after_reset":
249      case "change after reset":
250        return CHANGE_AFTER_RESET;
251      case "passwordmodnotallowed":
252      case "password-mod-not-allowed":
253      case "password_mod_not_allowed":
254      case "password mod not allowed":
255        return PASSWORD_MOD_NOT_ALLOWED;
256      case "mustsupplyoldpassword":
257      case "must-supply-old-password":
258      case "must_supply_old_password":
259      case "must supply old password":
260        return MUST_SUPPLY_OLD_PASSWORD;
261      case "insufficientpasswordquality":
262      case "insufficient-password-quality":
263      case "insufficient_password_quality":
264      case "insufficient password quality":
265        return INSUFFICIENT_PASSWORD_QUALITY;
266      case "passwordtooshort":
267      case "password-too-short":
268      case "password_too_short":
269      case "password too short":
270        return PASSWORD_TOO_SHORT;
271      case "passwordtooyoung":
272      case "password-too-young":
273      case "password_too_young":
274      case "password too young":
275        return PASSWORD_TOO_YOUNG;
276      case "passwordinhistory":
277      case "password-in-history":
278      case "password_in_history":
279      case "password in history":
280        return PASSWORD_IN_HISTORY;
281      default:
282        return null;
283    }
284  }
285
286
287
288  /**
289   * Retrieves a string representation for this password policy error type.
290   *
291   * @return  A string representation for this password policy error type.
292   */
293  @Override()
294  public String toString()
295  {
296    return name;
297  }
298}