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
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2006-2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.controls;
028    import org.opends.messages.Message;
029    
030    
031    
032    import static org.opends.messages.ProtocolMessages.*;
033    
034    
035    
036    /**
037     * This enumeration defines the set of password policy warnings that may be
038     * included in the password policy response control defined in
039     * draft-behera-ldap-password-policy.
040     */
041    public enum PasswordPolicyWarningType
042    {
043      /**
044       * The warning type that will be used to indicate that the password will
045       * expire in the near future and to provide the length of time in seconds
046       * until expiration.
047       */
048      TIME_BEFORE_EXPIRATION(PasswordPolicyWarningType.TYPE_TIME_BEFORE_EXPIRATION,
049                         INFO_PWPWARNTYPE_DESCRIPTION_TIME_BEFORE_EXPIRATION.get()),
050    
051    
052    
053      /**
054       * The warning type that will be used to indicate that the user is
055       * authenticating using a grace login and to provide the number of grace
056       * logins that the user has left.
057       */
058      GRACE_LOGINS_REMAINING(PasswordPolicyWarningType.TYPE_GRACE_LOGINS_REMAINING,
059                         INFO_PWPWARNTYPE_DESCRIPTION_GRACE_LOGINS_REMAINING.get());
060    
061    
062    
063      /**
064       * The BER type that will be used for the time before expiration type.
065       */
066      public static final byte TYPE_TIME_BEFORE_EXPIRATION = (byte) 0x80;
067    
068    
069    
070      /**
071       * The BER type that will be used for the grace logins remaining type.
072       */
073      public static final byte TYPE_GRACE_LOGINS_REMAINING = (byte) 0x81;
074    
075    
076    
077      // The BER type to use for the associated element in the password policy
078      // control.
079      private byte type;
080    
081      // The message ID for the description of this password policy error type.
082      private Message description;
083    
084    
085    
086      /**
087       * Creates a new instance of a password policy warning type with the provided
088       * BER type.
089       *
090       * @param  type           The BER type to use for the associated element in
091       *                        the password policy control.
092       * @param  description    The message for the description of this password
093       *                        policy error type.
094       */
095      private PasswordPolicyWarningType(byte type, Message description)
096      {
097        this.type          = type;
098        this.description   = description;
099      }
100    
101    
102    
103      /**
104       * Retrieves the BER type to use for the associated element in the password
105       * policy control.
106       *
107       * @return  The BER type to use for the associated element in the password
108       *          policy control.
109       */
110      public byte getType()
111      {
112        return type;
113      }
114    
115    
116    
117      /**
118       * Retrieves the password policy warning type for the provided BER type.
119       *
120       * @param  type  The BER type for which to retrieve the corresponding password
121       *               policy warning type.
122       *
123       * @return  The requested password policy warning type, or <CODE>null</CODE>
124       *          if none of the defined warning types have the provided BER type.
125       */
126      public static PasswordPolicyWarningType valueOf(byte type)
127      {
128        switch (type)
129        {
130          case TYPE_TIME_BEFORE_EXPIRATION:
131            return PasswordPolicyWarningType.TIME_BEFORE_EXPIRATION;
132          case TYPE_GRACE_LOGINS_REMAINING:
133            return PasswordPolicyWarningType.GRACE_LOGINS_REMAINING;
134          default:
135            return null;
136        }
137      }
138    
139    
140    
141      /**
142       * Retrieves a string representation of this password policy warning type.
143       *
144       * @return  A string representation of this password policy warning type.
145       */
146      public String toString()
147      {
148        return Message.toString(description);
149      }
150    }
151