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.server.kerberos.shared.messages.value;
21
22
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.List;
26
27
28 /**
29 * Type safe enumeration of Single-use Authentication Mechanism types
30 *
31 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32 * @version $Rev: 557095 $
33 */
34 public final class SamType implements Comparable<SamType>
35 {
36 /*
37 * Enumeration elements are constructed once upon class loading.
38 * Order of appearance here determines the order of compareTo.
39 */
40
41 /** safe SAM type enum for Enigma Logic */
42 public static final SamType PA_SAM_TYPE_ENIGMA = new SamType( 1, "Enigma Logic" );
43
44 /** safe SAM type enum for Digital Pathways */
45 public static final SamType PA_SAM_TYPE_DIGI_PATH = new SamType( 2, "Digital Pathways" );
46
47 /** safe SAM type enum for S/key where KDC has key 0 */
48 public static final SamType PA_SAM_TYPE_SKEY_K0 = new SamType( 3, "S/key where KDC has key 0" );
49
50 /** safe SAM type enum for Traditional S/Key */
51 public static final SamType PA_SAM_TYPE_SKEY = new SamType( 4, "Traditional S/Key" );
52
53 /** safe SAM type enum for Security Dynamics */
54 public static final SamType PA_SAM_TYPE_SECURID = new SamType( 5, "Security Dynamics" );
55
56 /** safe SAM type enum for CRYPTOCard */
57 public static final SamType PA_SAM_TYPE_CRYPTOCARD = new SamType( 6, "CRYPTOCard" );
58
59 /** safe SAM type enum for Apache Software Foundation */
60 public static final SamType PA_SAM_TYPE_APACHE = new SamType( 7, "Apache Software Foundation" );
61
62 /** Array for building a List of VALUES. */
63 private static final SamType[] values =
64 { PA_SAM_TYPE_ENIGMA, PA_SAM_TYPE_DIGI_PATH, PA_SAM_TYPE_SKEY_K0, PA_SAM_TYPE_SKEY, PA_SAM_TYPE_SECURID,
65 PA_SAM_TYPE_CRYPTOCARD, PA_SAM_TYPE_APACHE };
66
67 /** a list of all the sam type constants */
68 public static final List<SamType> VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
69
70 /** the name of the sam type */
71 private final String name;
72
73 /** the value/code for the sam type */
74 private final int ordinal;
75
76
77 /**
78 * Private constructor prevents construction outside of this class.
79 */
80 private SamType( int ordinal, String name )
81 {
82 this.ordinal = ordinal;
83 this.name = name;
84 }
85
86
87 /**
88 * Returns the name of the SamType.
89 *
90 * @return the name of the SAM type
91 */
92 public String toString()
93 {
94 return name;
95 }
96
97
98 /**
99 * 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 }