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