001/*
002 * Copyright 2007-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2018 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.util.StaticUtils;
026import com.unboundid.util.ThreadSafety;
027import com.unboundid.util.ThreadSafetyLevel;
028
029
030
031/**
032 * This enum defines a set of error types that may be included in the password
033 * policy response control as defined in draft-behera-ldap-password-policy.
034 * <BR>
035 * <BLOCKQUOTE>
036 *   <B>NOTE:</B>  This class, and other classes within the
037 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
038 *   supported for use against Ping Identity, UnboundID, and Alcatel-Lucent 8661
039 *   server products.  These classes provide support for proprietary
040 *   functionality or for external specifications that are not considered stable
041 *   or mature enough to be guaranteed to work in an interoperable way with
042 *   other types of LDAP servers.
043 * </BLOCKQUOTE>
044 */
045@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
046public enum PasswordPolicyErrorType
047{
048  /**
049   * The error type that indicates the user's password is expired.
050   */
051  PASSWORD_EXPIRED("password expired", 0),
052
053
054
055  /**
056   * The error type that indicates the user's account is locked or disabled.
057   */
058  ACCOUNT_LOCKED("account locked", 1),
059
060
061
062  /**
063   * The error type that indicates the user's password must be changed before
064   * any other operation will be allowed.
065   */
066  CHANGE_AFTER_RESET("change after reset", 2),
067
068
069
070  /**
071   * The error type that indicates that user password changes aren't allowed.
072   */
073  PASSWORD_MOD_NOT_ALLOWED("password mod not allowed", 3),
074
075
076
077  /**
078   * The error type that indicates the user must provide the current password
079   * when attempting to set a new one.
080   */
081  MUST_SUPPLY_OLD_PASSWORD("must supply old password", 4),
082
083
084
085  /**
086   * The error type that indicates the proposed password is too weak to be
087   * acceptable.
088   */
089  INSUFFICIENT_PASSWORD_QUALITY("insufficient password quality", 5),
090
091
092
093  /**
094   * The error type that indicates the proposed password is too short.
095   */
096  PASSWORD_TOO_SHORT("password too short", 6),
097
098
099
100  /**
101   * The error type that indicates the user's password cannot be changed because
102   * it has not been long enough since it was last changed.
103   */
104  PASSWORD_TOO_YOUNG("password too young", 7),
105
106
107
108  /**
109   * The error type that indicates the proposed password is already in the
110   * password history.
111   */
112  PASSWORD_IN_HISTORY("password in history", 8);
113
114
115
116  // The numeric value associated with this password policy error type.
117  private final int value;
118
119  // The human-readable name for this password policy error type.
120  private final String name;
121
122
123
124  /**
125   * Creates a new password policy error type with the provided information.
126   *
127   * @param  name   The human-readable name for this error type.
128   * @param  value  The numeric value associated with this error type.
129   */
130  PasswordPolicyErrorType(final String name, final int value)
131  {
132    this.name  = name;
133    this.value = value;
134  }
135
136
137
138  /**
139   * Retrieves the human-readable name for this password policy error type.
140   *
141   * @return  The human-readable name for this password policy error type.
142   */
143  public String getName()
144  {
145    return name;
146  }
147
148
149
150  /**
151   * Retrieves the integer value for this password policy error type.
152   *
153   * @return  The integer value for this password policy error type.
154   */
155  public int intValue()
156  {
157    return value;
158  }
159
160
161
162  /**
163   * Retrieves the password policy error type with the specified int value.
164   *
165   * @param  intValue  The numeric value associated with the error type.
166   *
167   * @return  The associated error type, or {@code null} if there is no
168   *          password policy error type with the specified set of values.
169   */
170  public static PasswordPolicyErrorType valueOf(final int intValue)
171  {
172    switch (intValue)
173    {
174      case 0:
175        return PASSWORD_EXPIRED;
176
177      case 1:
178        return ACCOUNT_LOCKED;
179
180      case 2:
181        return CHANGE_AFTER_RESET;
182
183      case 3:
184        return PASSWORD_MOD_NOT_ALLOWED;
185
186      case 4:
187        return MUST_SUPPLY_OLD_PASSWORD;
188
189      case 5:
190        return INSUFFICIENT_PASSWORD_QUALITY;
191
192      case 6:
193        return PASSWORD_TOO_SHORT;
194
195      case 7:
196        return PASSWORD_TOO_YOUNG;
197
198      case 8:
199        return PASSWORD_IN_HISTORY;
200
201      default:
202        return null;
203    }
204  }
205
206
207
208  /**
209   * Retrieves the password policy error type with the specified name.
210   *
211   * @param  name  The name of the password policy error type to retrieve.  It
212   *               must not be {@code null}.
213   *
214   * @return  The requested password policy error type, or {@code null} if no
215   *          such type is defined.
216   */
217  public static PasswordPolicyErrorType forName(final String name)
218  {
219    switch (StaticUtils.toLowerCase(name))
220    {
221      case "passwordexpired":
222      case "password-expired":
223      case "password_expired":
224      case "password expired":
225        return PASSWORD_EXPIRED;
226      case "accountlocked":
227      case "account-locked":
228      case "account_locked":
229      case "account locked":
230        return ACCOUNT_LOCKED;
231      case "changeafterreset":
232      case "change-after-reset":
233      case "change_after_reset":
234      case "change after reset":
235        return CHANGE_AFTER_RESET;
236      case "passwordmodnotallowed":
237      case "password-mod-not-allowed":
238      case "password_mod_not_allowed":
239      case "password mod not allowed":
240        return PASSWORD_MOD_NOT_ALLOWED;
241      case "mustsupplyoldpassword":
242      case "must-supply-old-password":
243      case "must_supply_old_password":
244      case "must supply old password":
245        return MUST_SUPPLY_OLD_PASSWORD;
246      case "insufficientpasswordquality":
247      case "insufficient-password-quality":
248      case "insufficient_password_quality":
249      case "insufficient password quality":
250        return INSUFFICIENT_PASSWORD_QUALITY;
251      case "passwordtooshort":
252      case "password-too-short":
253      case "password_too_short":
254      case "password too short":
255        return PASSWORD_TOO_SHORT;
256      case "passwordtooyoung":
257      case "password-too-young":
258      case "password_too_young":
259      case "password too young":
260        return PASSWORD_TOO_YOUNG;
261      case "passwordinhistory":
262      case "password-in-history":
263      case "password_in_history":
264      case "password in history":
265        return PASSWORD_IN_HISTORY;
266      default:
267        return null;
268    }
269  }
270
271
272
273  /**
274   * Retrieves a string representation for this password policy error type.
275   *
276   * @return  A string representation for this password policy error type.
277   */
278  @Override()
279  public String toString()
280  {
281    return name;
282  }
283}