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 import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
28
29
30 /**
31 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32 * @version $Rev: 586528 $, $Date: 2007-10-19 18:47:06 +0200 (Fr, 19 Okt 2007) $
33 */
34 public final class LastRequestType implements Comparable<LastRequestType>
35 {
36 /**
37 * Constant for the "none" last request type.
38 */
39 public static final LastRequestType NONE = new LastRequestType( 0, AuthenticationLevel.NONE.toString() );
40
41 /**
42 * Constant for the "time of initial ticket" last request type.
43 */
44 public static final LastRequestType TIME_OF_INITIAL_TGT = new LastRequestType( 1, "time of initial ticket" );
45
46 /**
47 * Constant for the "time of initial request" last request type.
48 */
49 public static final LastRequestType TIME_OF_INITIAL_REQ = new LastRequestType( 2, "time of initial request" );
50
51 /**
52 * Constant for the "time of newest ticket" last request type.
53 */
54 public static final LastRequestType TIME_OF_NEWEST_TGT = new LastRequestType( 3, "time of newest ticket" );
55
56 /**
57 * Constant for the "time of last renewal" last request type.
58 */
59 public static final LastRequestType TIME_OF_LAST_RENEWAL = new LastRequestType( 4, "time of last renewal" );
60
61 /**
62 * Constant for the "time of last request" last request type.
63 */
64 public static final LastRequestType TIME_OF_LAST_REQ = new LastRequestType( 5, "time of last request" );
65
66 /**
67 * Constant for the "time of password expiration" last request type.
68 */
69 public static final LastRequestType TIME_OF_PASSWORD_EXP = new LastRequestType( 6, "time of password expiration" );
70
71 /**
72 * Array for building a List of VALUES.
73 */
74 private static final LastRequestType[] values =
75 { NONE, TIME_OF_INITIAL_TGT, TIME_OF_INITIAL_REQ, TIME_OF_NEWEST_TGT, TIME_OF_LAST_RENEWAL, TIME_OF_LAST_REQ,
76 TIME_OF_PASSWORD_EXP };
77
78 /**
79 * A List of all the last request type constants.
80 */
81 public static final List<LastRequestType> VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
82
83 /**
84 * The name of the checksum type.
85 */
86 private final String name;
87
88 /**
89 * The value/code for the checksum type.
90 */
91 private final int ordinal;
92
93
94 /**
95 * Private constructor prevents construction outside of this class.
96 */
97 private LastRequestType( int ordinal, String name )
98 {
99 this.ordinal = ordinal;
100 this.name = name;
101 }
102
103
104 /**
105 * Returns the last request type when specified by its ordinal.
106 *
107 * @param type
108 * @return The last request type.
109 */
110 public static LastRequestType getTypeByOrdinal( int type )
111 {
112 for ( int ii = 0; ii < values.length; ii++ )
113 {
114 if ( values[ii].ordinal == type )
115 {
116 return values[ii];
117 }
118 }
119
120 return NONE;
121 }
122
123
124 /**
125 * Returns the number associated with this last request type.
126 *
127 * @return The last request type ordinal.
128 */
129 public int getOrdinal()
130 {
131 return ordinal;
132 }
133
134
135 public int compareTo( LastRequestType that )
136 {
137 return ordinal - that.ordinal;
138 }
139
140
141 public String toString()
142 {
143 return name + " (" + ordinal + ")";
144 }
145 }