001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with the License.  You may obtain a copy of the License at
009     *  
010     *    http://www.apache.org/licenses/LICENSE-2.0
011     *  
012     *  Unless required by applicable law or agreed to in writing,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License. 
018     *  
019     */
020    package org.apache.directory.server.kerberos.shared.messages.value.types;
021    
022    
023    /**
024     * An enum describing the differnet types of Principal.
025     * 
026     * Here is the list, taken from RFC 4120 :
027     *  NT-UNKNOWN        0    Name type not known
028     *  NT-PRINCIPAL      1    Just the name of the principal as in DCE,
029     *                           or for users
030     *  NT-SRV-INST       2    Service and other unique instance (krbtgt)
031     *  NT-SRV-HST        3    Service with host name as instance
032     *                           (telnet, rcommands)
033     *  NT-SRV-XHST       4    Service with host as remaining components
034     *  NT-UID            5    Unique ID
035     *  NT-X500-PRINCIPAL 6    Encoded X.509 Distinguished name [RFC2253]
036     *  NT-SMTP-NAME      7    Name in form of SMTP email name
037     *                           (e.g., user@example.com)
038     *  NT-ENTERPRISE    10    Enterprise name - may be mapped to principal
039     *                           name
040     *
041     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
042     * @version $Rev: 540371 $, $Date: 2007-05-22 02:00:43 +0200 (Tue, 22 May 2007) $
043     */
044    public enum PrincipalNameType
045    {
046        /**
047         * Constant for the "Name type not known" principal name type.
048         */
049        KRB_NT_UNKNOWN( 0 ),
050    
051        /**
052         * Constant for the "Just the name of the principal as in DCE, or for users" principal name type.
053         */
054        KRB_NT_PRINCIPAL( 1 ),
055    
056        /**
057         * Constant for the "Service and other unique instance (krbtgt)" principal name type.
058         */
059        KRB_NT_SRV_INST( 2 ),
060    
061        /**
062         * Constant for the "Service with host name as instance (telnet, rcommands)" principal name type.
063         */
064        KRB_NT_SRV_HST( 3 ),
065    
066        /**
067         * Constant for the "Service with host as remaining components" principal name type.
068         */
069        KRB_NT_SRV_XHST( 4 ),
070    
071        /**
072         * Constant for the "Unique ID" principal name type.
073         */
074        KRB_NT_UID( 5 ),
075    
076        /**
077         * Constant for the "Encoded X.509 Distinguished name [RFC2253]" principal name type.
078         */
079        KRB_NT_X500_PRINCIPAL( 6 ),
080    
081        /**
082         * Constant for the "Name in form of SMTP email name (e.g., user@example.com)" principal name type.
083         */
084        KRB_NT_SMTP_NAME( 7 ),
085    
086        /**
087         * Constant for the "Enterprise name; may be mapped to principal name" principal name type.
088         */
089        KRB_NT_ENTERPRISE( 10 );
090    
091        /**
092         * The value/code for the principal name type.
093         */
094        private final int ordinal;
095    
096    
097        /**
098         * Private constructor prevents construction outside of this class.
099         */
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    }