001/*
002 *   Licensed to the Apache Software Foundation (ASF) under one
003 *   or more contributor license agreements.  See the NOTICE file
004 *   distributed with this work for additional information
005 *   regarding copyright ownership.  The ASF licenses this file
006 *   to you under the Apache License, Version 2.0 (the
007 *   "License"); you may not use this file except in compliance
008 *   with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *   Unless required by applicable law or agreed to in writing,
013 *   software distributed under the License is distributed on an
014 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *   KIND, either express or implied.  See the License for the
016 *   specific language governing permissions and limitations
017 *   under the License.
018 *
019 */
020
021package org.apache.directory.api.ldap.extras.controls.ppolicy;
022
023
024/**
025 *  Constants representing PasswordPolicyErrors as stated in the <a href="http://tools.ietf.org/html/draft-behera-ldap-password-policy-10">draft</a>
026 *
027 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
028 */
029public enum PasswordPolicyErrorEnum
030{
031    /** The password has expired */
032    PASSWORD_EXPIRED(0),
033    
034    /** The account is locked */
035    ACCOUNT_LOCKED(1),
036    
037    /** */
038    CHANGE_AFTER_RESET(2),
039    
040    /** the password modification is not allowed */
041    PASSWORD_MOD_NOT_ALLOWED(3),
042    
043    /** The ld password must be supplied */
044    MUST_SUPPLY_OLD_PASSWORD(4),
045    
046    /** The password quality is not sufficient */
047    INSUFFICIENT_PASSWORD_QUALITY(5),
048    
049    /** The password is too short */
050    PASSWORD_TOO_SHORT(6),
051    
052    /** The password has been changed too recently to be used */
053    PASSWORD_TOO_YOUNG(7),
054    
055    /** The password is in history */
056    PASSWORD_IN_HISTORY(8);
057
058    private int value;
059
060
061    PasswordPolicyErrorEnum( int value )
062    {
063        this.value = value;
064    }
065
066
067    /**
068     * Get the PasswordPolicyErrorEnum gien its numeric value
069     * 
070     * @param val The numeric value to retrieve
071     * @return The associated PasswordPolicyErrorEnum
072     */
073    public static PasswordPolicyErrorEnum get( int val )
074    {
075        switch ( val )
076        {
077            case 0:
078                return PASSWORD_EXPIRED;
079
080            case 1:
081                return ACCOUNT_LOCKED;
082
083            case 2:
084                return CHANGE_AFTER_RESET;
085
086            case 3:
087                return PASSWORD_MOD_NOT_ALLOWED;
088
089            case 4:
090                return MUST_SUPPLY_OLD_PASSWORD;
091
092            case 5:
093                return INSUFFICIENT_PASSWORD_QUALITY;
094
095            case 6:
096                return PASSWORD_TOO_SHORT;
097
098            case 7:
099                return PASSWORD_TOO_YOUNG;
100
101            case 8:
102                return PASSWORD_IN_HISTORY;
103
104            default:
105
106                throw new IllegalArgumentException( "unknown password policy error value " + val );
107        }
108    }
109
110
111    /**
112     * @return the PasswordPolicyError interned value
113     */
114    public int getValue()
115    {
116        return value;
117    }
118}