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.shared.kerberos.codec.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   */
43  public enum PrincipalNameType
44  {
45      /** Constant for the "Name type not known" principal name type. */
46      KRB_NT_UNKNOWN(0),
47  
48      /**Constant for the "Just the name of the principal as in DCE, or for users" principal name type. */
49      KRB_NT_PRINCIPAL(1),
50  
51      /** Constant for the "Service and other unique instance (krbtgt)" principal name type. */
52      KRB_NT_SRV_INST(2),
53  
54      /** Constant for the "Service with host name as instance (telnet, rcommands)" principal name type. */
55      KRB_NT_SRV_HST(3),
56  
57      /** Constant for the "Service with host as remaining components" principal name type. */
58      KRB_NT_SRV_XHST(4),
59  
60      /** Constant for the "Unique ID" principal name type. */
61      KRB_NT_UID(5),
62  
63      /** Constant for the "Encoded X.509 Distinguished name [RFC2253]" principal name type. */
64      KRB_NT_X500_PRINCIPAL(6),
65  
66      /** Constant for the "Name in form of SMTP email name (e.g., user@example.com)" principal name type. */
67      KRB_NT_SMTP_NAME(7),
68  
69      /** Constant for the "Enterprise name; may be mapped to principal name" principal name type. */
70      KRB_NT_ENTERPRISE(10);
71  
72      /**
73       * The value/code for the principal name type.
74       */
75      private final int value;
76  
77  
78      /**
79       * Private constructor prevents construction outside of this class.
80       */
81      private PrincipalNameType( int value )
82      {
83          this.value = value;
84      }
85  
86  
87      /**
88       * Returns the principal name type when specified by its ordinal.
89       *
90       * @param type
91       * @return The principal name type.
92       */
93      public static PrincipalNameType getTypeByValue( int type )
94      {
95          switch ( type )
96          {
97              case 0:
98                  return KRB_NT_UNKNOWN;
99              case 1:
100                 return KRB_NT_PRINCIPAL;
101             case 2:
102                 return KRB_NT_SRV_INST;
103             case 3:
104                 return KRB_NT_SRV_HST;
105             case 4:
106                 return KRB_NT_SRV_XHST;
107             case 5:
108                 return KRB_NT_UID;
109             case 6:
110                 return KRB_NT_X500_PRINCIPAL;
111             case 7:
112                 return KRB_NT_SMTP_NAME;
113             case 10:
114                 return KRB_NT_ENTERPRISE;
115             default:
116                 return KRB_NT_UNKNOWN;
117         }
118     }
119 
120 
121     /**
122      * Returns the number associated with this principal name type.
123      *
124      * @return The principal name type ordinal.
125      */
126     public int getValue()
127     {
128         return value;
129     }
130 
131 
132     /**
133      * @see Object#toString()
134      */
135     @Override
136     public String toString()
137     {
138         switch ( this )
139         {
140             case KRB_NT_UNKNOWN:
141                 return "Name type not known" + "(" + value + ")";
142 
143             case KRB_NT_PRINCIPAL:
144                 return "Just the name of the principal as in DCE, or for users" + "(" + value + ")";
145 
146             case KRB_NT_SRV_INST:
147                 return "Service and other unique instance (krbtgt)" + "(" + value + ")";
148 
149             case KRB_NT_SRV_HST:
150                 return "Service with host name as instance (telnet, rcommands)" + "(" + value + ")";
151 
152             case KRB_NT_SRV_XHST:
153                 return "Service with host as remaining components" + "(" + value + ")";
154 
155             case KRB_NT_UID:
156                 return "Unique ID" + "(" + value + ")";
157 
158             case KRB_NT_X500_PRINCIPAL:
159                 return "Encoded X.509 Distinguished name [RFC2253]" + "(" + value + ")";
160 
161             case KRB_NT_SMTP_NAME:
162                 return "Name in form of SMTP email name (e.g., user@example.com)" + "(" + value + ")";
163 
164             case KRB_NT_ENTERPRISE:
165                 return "Enterprise name; may be mapped to principal name" + "(" + value + ")";
166 
167             default:
168                 return "unknown name type" + "(" + value + ")";
169         }
170     }
171 }