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.components;
21
22
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.List;
26
27
28 /**
29 * Type-safe enumerator for message component types.
30 *
31 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32 * @version $Rev: 557095 $, $Date: 2007-07-18 02:28:32 +0200 (Mi, 18 Jul 2007) $
33 */
34 public class MessageComponentType implements Comparable<MessageComponentType>
35 {
36 /**
37 * Constant for the "null" message component type.
38 */
39 public static final MessageComponentType NULL = new MessageComponentType( 0, "null" );
40
41 /**
42 * Constant for the "ticket" message component type.
43 */
44 public static final MessageComponentType KRB_TKT = new MessageComponentType( 1, "ticket" );
45
46 /**
47 * Constant for the "authenticator" message component type.
48 */
49 public static final MessageComponentType KRB_AUTHENTICATOR = new MessageComponentType( 2, "authenticator" );
50
51 /**
52 * Constant for the "encrypted ticket part" message component type.
53 */
54 public static final MessageComponentType KRB_ENC_TKT_PART = new MessageComponentType( 3, "encrypted ticket part" );
55
56 /**
57 * Constant for the "encrypted initial authentication part" message component type.
58 */
59 public static final MessageComponentType KRB_ENC_AS_REP_PART = new MessageComponentType( 25,
60 "encrypted initial authentication part" );
61
62 /**
63 * Constant for the "encrypted TGS request part" message component type.
64 */
65 public static final MessageComponentType KRB_ENC_TGS_REP_PART = new MessageComponentType( 26,
66 "encrypted TGS request part" );
67
68 /**
69 * Constant for the "encrypted application request part" message component type.
70 */
71 public static final MessageComponentType KRB_ENC_AP_REP_PART = new MessageComponentType( 27,
72 "encrypted application request part" );
73
74 /**
75 * Constant for the "encrypted application message part" message component type.
76 */
77 public static final MessageComponentType KRB_ENC_KRB_PRIV_PART = new MessageComponentType( 28,
78 "encrypted application message part" );
79
80 /**
81 * Constant for the "encrypted credentials forward part" message component type.
82 */
83 public static final MessageComponentType KRB_ENC_KRB_CRED_PART = new MessageComponentType( 29,
84 "encrypted credentials forward part" );
85
86 /**
87 * Array for building a List of VALUES.
88 */
89 private static final MessageComponentType[] values =
90 { NULL, KRB_TKT, KRB_AUTHENTICATOR, KRB_ENC_TKT_PART, KRB_ENC_AS_REP_PART, KRB_ENC_TGS_REP_PART,
91 KRB_ENC_AP_REP_PART, KRB_ENC_KRB_PRIV_PART, KRB_ENC_KRB_CRED_PART };
92
93 /**
94 * A List of all the message component type constants.
95 */
96 public static final List<MessageComponentType> VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
97
98 /**
99 * The name of the message component type.
100 */
101 private final String name;
102
103 /**
104 * The value/code for the message component type.
105 */
106 private final int ordinal;
107
108
109 /**
110 * Private constructor prevents construction outside of this class.
111 */
112 private MessageComponentType( int ordinal, String name )
113 {
114 this.ordinal = ordinal;
115 this.name = name;
116 }
117
118
119 /**
120 * Returns the message component type when specified by its ordinal.
121 *
122 * @param type
123 * @return The message component type.
124 */
125 public static MessageComponentType getTypeByOrdinal( int type )
126 {
127 for ( int ii = 0; ii < values.length; ii++ )
128 {
129 if ( values[ii].ordinal == type )
130 {
131 return values[ii];
132 }
133 }
134
135 return NULL;
136 }
137
138
139 /**
140 * Returns the number associated with this message component type.
141 *
142 * @return The message component type ordinal.
143 */
144 public int getOrdinal()
145 {
146 return ordinal;
147 }
148
149
150 public int compareTo( MessageComponentType that )
151 {
152 return ordinal - that.ordinal;
153 }
154
155
156 public String toString()
157 {
158 return name + " (" + ordinal + ")";
159 }
160 }