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 package org.apache.directory.shared.ldap.constants;
021
022
023 /**
024 * An enumeration that represents the level of authentication.
025 *
026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
027 * @version $Rev: 725712 $, $Date: 2008-12-11 16:32:04 +0100 (Jeu, 11 déc 2008) $
028 */
029 public enum AuthenticationLevel
030 {
031 /**
032 * Invalid authentication type
033 */
034 INVALID(-1, "invalid" ),
035
036 /**
037 * No authentication (anonymous access)
038 */
039 NONE( 0, "none" ),
040
041 /**
042 * Simple authentication (bound with plain-text credentials)
043 */
044 SIMPLE( 1, "simple" ),
045
046 /**
047 * Strong authentication (bound with encrypted credentials)
048 */
049 STRONG( 2, "strong" ),
050
051 /**
052 * Unauthentication, if the BIND contains a DN but no credentials
053 */
054 UNAUTHENT( 3, "unauthent" );
055
056 private int level;
057
058 private final String name;
059
060 private AuthenticationLevel( int level, String name )
061 {
062 this.level = level;
063 this.name = name;
064 }
065
066 /**
067 * Returns the integer value of this level (greater value, stronger level).
068 */
069 public int getLevel()
070 {
071 return level;
072 }
073
074
075 /**
076 * Returns the name of this level.
077 */
078 public String getName()
079 {
080 return name;
081 }
082
083
084 public String toString()
085 {
086 return name;
087 }
088
089
090 public static AuthenticationLevel getLevel( int val )
091 {
092 switch( val )
093 {
094 case 0: return NONE;
095
096 case 1: return SIMPLE;
097
098 case 2: return STRONG;
099
100 case 3: return UNAUTHENT;
101
102 default:
103 throw new IllegalArgumentException( "Unknown AuthenticationLevel " + val );
104 }
105 }
106 }