001    /*
002     * Copyright 2007-2015 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2015 UnboundID Corp.
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     */
021    package com.unboundid.ldap.sdk.unboundidds.controls;
022    
023    
024    
025    import com.unboundid.util.ThreadSafety;
026    import com.unboundid.util.ThreadSafetyLevel;
027    
028    
029    
030    /**
031     * <BLOCKQUOTE>
032     *   <B>NOTE:</B>  This class is part of the Commercial Edition of the UnboundID
033     *   LDAP SDK for Java.  It is not available for use in applications that
034     *   include only the Standard Edition of the LDAP SDK, and is not supported for
035     *   use in conjunction with non-UnboundID products.
036     * </BLOCKQUOTE>
037     * This enum defines a set of error types that may be included in the password
038     * policy response control as defined in draft-behera-ldap-password-policy.
039     */
040    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
041    public enum PasswordPolicyErrorType
042    {
043      /**
044       * The error type that indicates the user's password is expired.
045       */
046      PASSWORD_EXPIRED("password expired", 0),
047    
048    
049    
050      /**
051       * The error type that indicates the user's account is locked or disabled.
052       */
053      ACCOUNT_LOCKED("account locked", 1),
054    
055    
056    
057      /**
058       * The error type that indicates the user's password must be changed before
059       * any other operation will be allowed.
060       */
061      CHANGE_AFTER_RESET("change after reset", 2),
062    
063    
064    
065      /**
066       * The error type that indicates that user password changes aren't allowed.
067       */
068      PASSWORD_MOD_NOT_ALLOWED("password mod not allowed", 3),
069    
070    
071    
072      /**
073       * The error type that indicates the user must provide the current password
074       * when attempting to set a new one.
075       */
076      MUST_SUPPLY_OLD_PASSWORD("must supply old password", 4),
077    
078    
079    
080      /**
081       * The error type that indicates the proposed password is too weak to be
082       * acceptable.
083       */
084      INSUFFICIENT_PASSWORD_QUALITY("insufficient password quality", 5),
085    
086    
087    
088      /**
089       * The error type that indicates the proposed password is too short.
090       */
091      PASSWORD_TOO_SHORT("password too short", 6),
092    
093    
094    
095      /**
096       * The error type that indicates the user's password cannot be changed because
097       * it has not been long enough since it was last changed.
098       */
099      PASSWORD_TOO_YOUNG("password too young", 7),
100    
101    
102    
103      /**
104       * The error type that indicates the proposed password is already in the
105       * password history.
106       */
107      PASSWORD_IN_HISTORY("password in history", 8);
108    
109    
110    
111      // The numeric value associated with this password policy error type.
112      private final int value;
113    
114      // The human-readable name for this password policy error type.
115      private final String name;
116    
117    
118    
119      /**
120       * Creates a new password policy error type with the provided information.
121       *
122       * @param  name   The human-readable name for this error type.
123       * @param  value  The numeric value associated with this error type.
124       */
125      private PasswordPolicyErrorType(final String name, final int value)
126      {
127        this.name  = name;
128        this.value = value;
129      }
130    
131    
132    
133      /**
134       * Retrieves the human-readable name for this password policy error type.
135       *
136       * @return  The human-readable name for this password policy error type.
137       */
138      public String getName()
139      {
140        return name;
141      }
142    
143    
144    
145      /**
146       * Retrieves the integer value for this password policy error type.
147       *
148       * @return  The integer value for this password policy error type.
149       */
150      public int intValue()
151      {
152        return value;
153      }
154    
155    
156    
157      /**
158       * Retrieves the password policy error type with the specified int value.
159       *
160       * @param  intValue  The numeric value associated with the error type.
161       *
162       * @return  The associated error type, or {@code null} if there is no
163       *          password policy error type with the specified set of values.
164       */
165      public static PasswordPolicyErrorType valueOf(final int intValue)
166      {
167        switch (intValue)
168        {
169          case 0:
170            return PASSWORD_EXPIRED;
171    
172          case 1:
173            return ACCOUNT_LOCKED;
174    
175          case 2:
176            return CHANGE_AFTER_RESET;
177    
178          case 3:
179            return PASSWORD_MOD_NOT_ALLOWED;
180    
181          case 4:
182            return MUST_SUPPLY_OLD_PASSWORD;
183    
184          case 5:
185            return INSUFFICIENT_PASSWORD_QUALITY;
186    
187          case 6:
188            return PASSWORD_TOO_SHORT;
189    
190          case 7:
191            return PASSWORD_TOO_YOUNG;
192    
193          case 8:
194            return PASSWORD_IN_HISTORY;
195    
196          default:
197            return null;
198        }
199      }
200    
201    
202    
203      /**
204       * Retrieves a string representation for this password policy error type.
205       *
206       * @return  A string representation for this password policy error type.
207       */
208      @Override()
209      public String toString()
210      {
211        return name;
212      }
213    }