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.server.kerberos.shared.messages.value;
021
022
023 import java.util.Arrays;
024 import java.util.Collections;
025 import java.util.List;
026
027
028 /**
029 * Type safe enumeration of Single-use Authentication Mechanism types
030 *
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 * @version $Rev: 557095 $
033 */
034 public final class SamType implements Comparable<SamType>
035 {
036 /*
037 * Enumeration elements are constructed once upon class loading.
038 * Order of appearance here determines the order of compareTo.
039 */
040
041 /** safe SAM type enum for Enigma Logic */
042 public static final SamType PA_SAM_TYPE_ENIGMA = new SamType( 1, "Enigma Logic" );
043
044 /** safe SAM type enum for Digital Pathways */
045 public static final SamType PA_SAM_TYPE_DIGI_PATH = new SamType( 2, "Digital Pathways" );
046
047 /** safe SAM type enum for S/key where KDC has key 0 */
048 public static final SamType PA_SAM_TYPE_SKEY_K0 = new SamType( 3, "S/key where KDC has key 0" );
049
050 /** safe SAM type enum for Traditional S/Key */
051 public static final SamType PA_SAM_TYPE_SKEY = new SamType( 4, "Traditional S/Key" );
052
053 /** safe SAM type enum for Security Dynamics */
054 public static final SamType PA_SAM_TYPE_SECURID = new SamType( 5, "Security Dynamics" );
055
056 /** safe SAM type enum for CRYPTOCard */
057 public static final SamType PA_SAM_TYPE_CRYPTOCARD = new SamType( 6, "CRYPTOCard" );
058
059 /** safe SAM type enum for Apache Software Foundation */
060 public static final SamType PA_SAM_TYPE_APACHE = new SamType( 7, "Apache Software Foundation" );
061
062 /** Array for building a List of VALUES. */
063 private static final SamType[] values =
064 { PA_SAM_TYPE_ENIGMA, PA_SAM_TYPE_DIGI_PATH, PA_SAM_TYPE_SKEY_K0, PA_SAM_TYPE_SKEY, PA_SAM_TYPE_SECURID,
065 PA_SAM_TYPE_CRYPTOCARD, PA_SAM_TYPE_APACHE };
066
067 /** a list of all the sam type constants */
068 public static final List<SamType> VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
069
070 /** the name of the sam type */
071 private final String name;
072
073 /** the value/code for the sam type */
074 private final int ordinal;
075
076
077 /**
078 * Private constructor prevents construction outside of this class.
079 */
080 private SamType( int ordinal, String name )
081 {
082 this.ordinal = ordinal;
083 this.name = name;
084 }
085
086
087 /**
088 * Returns the name of the SamType.
089 *
090 * @return the name of the SAM type
091 */
092 public String toString()
093 {
094 return name;
095 }
096
097
098 /**
099 * Compares this type to another object hopefully one that is of the same
100 * type.
101 *
102 * @param that the object to compare this SamType to
103 * @return ordinal - ( ( SamType ) that ).ordinal;
104 */
105 public int compareTo( SamType that )
106 {
107 return ordinal - that.ordinal;
108 }
109
110
111 /**
112 * Gets the ordinal by its ordinal value.
113 *
114 * @param ordinal the ordinal value of the ordinal
115 * @return the type corresponding to the ordinal value
116 */
117 public static SamType getTypeByOrdinal( int ordinal )
118 {
119 for ( int ii = 0; ii < values.length; ii++ )
120 {
121 if ( values[ii].ordinal == ordinal )
122 {
123 return values[ii];
124 }
125 }
126
127 return PA_SAM_TYPE_APACHE;
128 }
129
130
131 /**
132 * Gets the ordinal value associated with this SAM type.
133 *
134 * @return the ordinal value associated with this SAM type
135 */
136 public int getOrdinal()
137 {
138 return ordinal;
139 }
140 }