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 */
020package org.apache.directory.api.ldap.model.constants;
021
022
023import org.apache.directory.api.i18n.I18n;
024
025
026/**
027 * An enumeration that represents the level of authentication. We have 4 
028 * different levels :
029 * <ul>
030 * <li>NONE : anonymous</li>
031 * <li>SIMPLE : Simple authentication</li>
032 * <li>STRONG : SASL or external authentication</li>
033 * <li>UNAUTHENT : A special case when just doing some auditing</li>
034 * </ul>
035 * 
036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
037 */
038public enum AuthenticationLevel
039{
040    /**
041     * No authentication (anonymous access)
042     */
043    NONE(0, "none"),
044
045    /**
046     * Simple authentication (bound with plain-text credentials)
047     */
048    SIMPLE(1, "simple"),
049
050    /**
051     * Strong authentication (bound with encrypted credentials)
052     */
053    STRONG(2, "strong"),
054
055    /**
056     * Unauthentication, if the BIND contains a Dn but no credentials
057     */
058    UNAUTHENT(3, "unauthent");
059
060    /** The internal numeric value */
061    private int level;
062
063    /** The level name */
064    private final String name;
065
066
067    /**
068     * Creates a new instance of AuthenticationLevel.
069     *
070     * @param level The level
071     * @param name The associated name
072     */
073    AuthenticationLevel( int level, String name )
074    {
075        this.level = level;
076        this.name = name;
077    }
078
079
080    /**
081     * @return the integer value of this level (greater value, stronger level).
082     */
083    public int getLevel()
084    {
085        return level;
086    }
087
088
089    /**
090     * @return the name of this level.
091     */
092    public String getName()
093    {
094        return name;
095    }
096
097
098    /**
099     * {@inheritDoc}
100     */
101    public String toString()
102    {
103        return name;
104    }
105
106
107    /**
108     * Return the AuthenticationLevel  associated with the given numeric level. This
109     * is used by the serialization process.
110     *
111     * @param val The numeric level we are looking at
112     * @return The associated AuthenticationLevel
113     */
114    public static AuthenticationLevel getLevel( int val )
115    {
116        switch ( val )
117        {
118            case 0:
119                return NONE;
120
121            case 1:
122                return SIMPLE;
123
124            case 2:
125                return STRONG;
126
127            case 3:
128                return UNAUTHENT;
129
130            default:
131                throw new IllegalArgumentException( I18n.err( I18n.ERR_05001_UNKNOWN_AUTHENT_LEVEL, val ) );
132        }
133    }
134}