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
023import org.apache.directory.api.i18n.I18n;
024
025/**
026 *  constants representing PasswordPolicyErrorS as stated in the <a href="http://tools.ietf.org/html/draft-behera-ldap-password-policy-10">draft</a>
027 *
028 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
029 */
030public enum PasswordPolicyErrorEnum
031{
032    /** The password has expired */
033    PASSWORD_EXPIRED(0),
034    
035    /** The account is locked */
036    ACCOUNT_LOCKED(1),
037    
038    /** */
039    CHANGE_AFTER_RESET(2),
040    
041    /** the password modification is not allowed */
042    PASSWORD_MOD_NOT_ALLOWED(3),
043    
044    /** The ld password must be supplied */
045    MUST_SUPPLY_OLD_PASSWORD(4),
046    
047    /** The password quality is not sufficient */
048    INSUFFICIENT_PASSWORD_QUALITY(5),
049    
050    /** The password is too short */
051    PASSWORD_TOO_SHORT(6),
052    
053    /** The password has been changed too recently to be used */
054    PASSWORD_TOO_YOUNG(7),
055    
056    /** The password is in history */
057    PASSWORD_IN_HISTORY(8);
058
059    private int value;
060
061
062    PasswordPolicyErrorEnum( int value )
063    {
064        this.value = value;
065    }
066
067
068    /**
069     * Get the PasswordPolicyErrorEnum gien its numeric value
070     * 
071     * @param val The numeric value to retrieve
072     * @return The associated PasswordPolicyErrorEnum
073     */
074    public static PasswordPolicyErrorEnum get( int val )
075    {
076        switch ( val )
077        {
078            case 0:
079                return PASSWORD_EXPIRED;
080
081            case 1:
082                return ACCOUNT_LOCKED;
083
084            case 2:
085                return CHANGE_AFTER_RESET;
086
087            case 3:
088                return PASSWORD_MOD_NOT_ALLOWED;
089
090            case 4:
091                return MUST_SUPPLY_OLD_PASSWORD;
092
093            case 5:
094                return INSUFFICIENT_PASSWORD_QUALITY;
095
096            case 6:
097                return PASSWORD_TOO_SHORT;
098
099            case 7:
100                return PASSWORD_TOO_YOUNG;
101
102            case 8:
103                return PASSWORD_IN_HISTORY;
104
105            default:
106
107                throw new IllegalArgumentException( I18n.err( I18n.ERR_9100_UNKNOWN_PASSWORD_POLICY_ERROR, val ) );
108        }
109    }
110
111
112    /**
113     * @return the PasswordPolicyError interned value
114     */
115    public int getValue()
116    {
117        return value;
118    }
119}