View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.model.constants;
21  
22  
23  import org.apache.directory.api.i18n.I18n;
24  
25  
26  /**
27   * An enumeration that represents the level of authentication. We have 4 
28   * different levels :
29   * <ul>
30   * <li>NONE : anonymous</li>
31   * <li>SIMPLE : Simple authentication</li>
32   * <li>STRONG : SASL or external authentication</li>
33   * <li>UNAUTHENT : A special case when just doing some auditing</li>
34   * </ul>
35   * 
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   */
38  public enum AuthenticationLevel
39  {
40      /**
41       * No authentication (anonymous access)
42       */
43      NONE(0, "none"),
44  
45      /**
46       * Simple authentication (bound with plain-text credentials)
47       */
48      SIMPLE(1, "simple"),
49  
50      /**
51       * Strong authentication (bound with encrypted credentials)
52       */
53      STRONG(2, "strong"),
54  
55      /**
56       * Unauthentication, if the BIND contains a Dn but no credentials
57       */
58      UNAUTHENT(3, "unauthent");
59  
60      /** The internal numeric value */
61      private int level;
62  
63      /** The level name */
64      private final String name;
65  
66  
67      /**
68       * Creates a new instance of AuthenticationLevel.
69       *
70       * @param level The level
71       * @param name The associated name
72       */
73      AuthenticationLevel( int level, String name )
74      {
75          this.level = level;
76          this.name = name;
77      }
78  
79  
80      /**
81       * @return the integer value of this level (greater value, stronger level).
82       */
83      public int getLevel()
84      {
85          return level;
86      }
87  
88  
89      /**
90       * @return the name of this level.
91       */
92      public String getName()
93      {
94          return name;
95      }
96  
97  
98      /**
99       * {@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 }