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 legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2009 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027package org.opends.server.controls;
028
029import static org.opends.messages.ProtocolMessages.*;
030
031import java.util.HashMap;
032import java.util.Map;
033
034import org.forgerock.i18n.LocalizableMessage;
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 */
041public 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(0,
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(1,
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(2,
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       3,
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       4,
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       5,
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(6,
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(7,
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(8,
124                      INFO_PWPERRTYPE_DESCRIPTION_PASSWORD_IN_HISTORY.get());
125
126
127
128  /** A lookup table for resolving an error type from its integer value. */
129  private static final Map<Integer, PasswordPolicyErrorType> TABLE = new HashMap<>();
130  static
131  {
132    for (PasswordPolicyErrorType type : PasswordPolicyErrorType.values())
133    {
134      TABLE.put(type.value, type);
135      TABLE.put(type.value, type);
136    }
137  }
138
139
140
141  /**
142   * The integer value associated with the error type to use in the associated
143   * enumerated element in the password policy response control.
144   */
145  private int value;
146
147  /** The message ID for the description of this password policy error type. */
148  private LocalizableMessage description;
149
150
151
152  /**
153   * Creates a new instance of a password policy error type with the provided
154   * value.
155   *
156   * @param  value          The integer value associated with the error type to
157   *                        use in the associated enumerated element in the
158   *                        password policy response control.
159   * @param  description    The message for the description of this password
160   *                        policy error type.
161   */
162  private PasswordPolicyErrorType(int value, LocalizableMessage description)
163  {
164    this.value         = value;
165    this.description   = description;
166  }
167
168
169
170  /**
171   * Retrieves the integer value associated with the error type to use in the
172   * associated enumerated element in the password policy response control.
173   *
174   * @return  The integer value associated with the error type to use in the
175   *          associated enumerated element in the password policy response
176   *          control.
177   */
178  public int intValue()
179  {
180    return value;
181  }
182
183
184
185  /**
186   * Retrieves the password policy error type for the provided integer value.
187   *
188   * @param  value  The value for which to retrieve the corresponding error
189   *                type.
190   *
191   * @return  The requested password policy error type, or <CODE>null</CODE> if
192   *          the provided value does not match any error types.
193   */
194  public static PasswordPolicyErrorType valueOf(int value)
195  {
196    return TABLE.get(Integer.valueOf(value));
197  }
198
199
200
201  /**
202   * Retrieves a string representation of this password policy error type.
203   *
204   * @return  A string representation of this password policy error type.
205   */
206  @Override
207  public String toString()
208  {
209    return description.toString();
210  }
211}
212