View Javadoc

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.types;
21  
22  
23  /**
24   * An enum describing the differnet types of Principal.
25   * 
26   * Here is the list, taken from RFC 4120 :
27   *  NT-UNKNOWN        0    Name type not known
28   *  NT-PRINCIPAL      1    Just the name of the principal as in DCE,
29   *                           or for users
30   *  NT-SRV-INST       2    Service and other unique instance (krbtgt)
31   *  NT-SRV-HST        3    Service with host name as instance
32   *                           (telnet, rcommands)
33   *  NT-SRV-XHST       4    Service with host as remaining components
34   *  NT-UID            5    Unique ID
35   *  NT-X500-PRINCIPAL 6    Encoded X.509 Distinguished name [RFC2253]
36   *  NT-SMTP-NAME      7    Name in form of SMTP email name
37   *                           (e.g., user@example.com)
38   *  NT-ENTERPRISE    10    Enterprise name - may be mapped to principal
39   *                           name
40   *
41   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
42   * @version $Rev: 540371 $, $Date: 2007-05-22 02:00:43 +0200 (Tue, 22 May 2007) $
43   */
44  public enum PrincipalNameType
45  {
46      /**
47       * Constant for the "Name type not known" principal name type.
48       */
49      KRB_NT_UNKNOWN( 0 ),
50  
51      /**
52       * Constant for the "Just the name of the principal as in DCE, or for users" principal name type.
53       */
54      KRB_NT_PRINCIPAL( 1 ),
55  
56      /**
57       * Constant for the "Service and other unique instance (krbtgt)" principal name type.
58       */
59      KRB_NT_SRV_INST( 2 ),
60  
61      /**
62       * Constant for the "Service with host name as instance (telnet, rcommands)" principal name type.
63       */
64      KRB_NT_SRV_HST( 3 ),
65  
66      /**
67       * Constant for the "Service with host as remaining components" principal name type.
68       */
69      KRB_NT_SRV_XHST( 4 ),
70  
71      /**
72       * Constant for the "Unique ID" principal name type.
73       */
74      KRB_NT_UID( 5 ),
75  
76      /**
77       * Constant for the "Encoded X.509 Distinguished name [RFC2253]" principal name type.
78       */
79      KRB_NT_X500_PRINCIPAL( 6 ),
80  
81      /**
82       * Constant for the "Name in form of SMTP email name (e.g., user@example.com)" principal name type.
83       */
84      KRB_NT_SMTP_NAME( 7 ),
85  
86      /**
87       * Constant for the "Enterprise name; may be mapped to principal name" principal name type.
88       */
89      KRB_NT_ENTERPRISE( 10 );
90  
91      /**
92       * The value/code for the principal name type.
93       */
94      private final int ordinal;
95  
96  
97      /**
98       * Private constructor prevents construction outside of this class.
99       */
100     private PrincipalNameType( int ordinal )
101     {
102         this.ordinal = ordinal;
103     }
104 
105 
106     /**
107      * Returns the principal name type when specified by its ordinal.
108      *
109      * @param type
110      * @return The principal name type.
111      */
112     public static PrincipalNameType getTypeByOrdinal( int type )
113     {
114         switch ( type )
115         {
116             case 0 : return KRB_NT_UNKNOWN;
117             case 1 : return KRB_NT_PRINCIPAL;
118             case 2 : return KRB_NT_SRV_INST;
119             case 3 : return KRB_NT_SRV_HST;
120             case 4 : return KRB_NT_SRV_XHST;
121             case 5 : return KRB_NT_UID;
122             case 6 : return KRB_NT_X500_PRINCIPAL;
123             case 7 : return KRB_NT_SMTP_NAME;
124             case 10 : return KRB_NT_ENTERPRISE;
125             default : return KRB_NT_UNKNOWN;
126         }
127     }
128 
129 
130     /**
131      * Returns the number associated with this principal name type.
132      *
133      * @return The principal name type ordinal.
134      */
135     public int getOrdinal()
136     {
137         return ordinal;
138     }
139 
140     /**
141      * @see Object#toString()
142      */
143     public String toString()
144     {
145         switch ( this )
146         {
147             case KRB_NT_UNKNOWN         : 
148                 return "Name type not known" + "(" + ordinal + ")";
149                 
150             case KRB_NT_PRINCIPAL       : 
151                 return "Just the name of the principal as in DCE, or for users" + "(" + ordinal + ")";
152                 
153             case KRB_NT_SRV_INST        : 
154                 return "Service and other unique instance (krbtgt)" + "(" + ordinal + ")";
155             
156             case KRB_NT_SRV_HST         : 
157                 return "Service with host name as instance (telnet, rcommands)" + "(" + ordinal + ")";
158             
159             case KRB_NT_SRV_XHST        : 
160                 return "Service with host as remaining components" + "(" + ordinal + ")";
161             
162             case KRB_NT_UID             : 
163                 return "Unique ID" + "(" + ordinal + ")";
164             
165             case KRB_NT_X500_PRINCIPAL  : 
166                 return "Encoded X.509 Distinguished name [RFC2253]" + "(" + ordinal + ")";
167             
168             case KRB_NT_SMTP_NAME       : 
169                 return "Name in form of SMTP email name (e.g., user@example.com)" + "(" + ordinal + ")";
170             
171             case KRB_NT_ENTERPRISE      : 
172                 return "Enterprise name; may be mapped to principal name" + "(" + ordinal + ")";
173             
174             default                     : 
175                 return "unknown name type" + "(" + ordinal + ")";
176         }
177     }
178 }