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