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 */
020package org.apache.directory.shared.kerberos.codec.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 */
043public enum PrincipalNameType
044{
045    /** Constant for the "Name type not known" principal name type. */
046    KRB_NT_UNKNOWN(0),
047
048    /**Constant for the "Just the name of the principal as in DCE, or for users" principal name type. */
049    KRB_NT_PRINCIPAL(1),
050
051    /** Constant for the "Service and other unique instance (krbtgt)" principal name type. */
052    KRB_NT_SRV_INST(2),
053
054    /** Constant for the "Service with host name as instance (telnet, rcommands)" principal name type. */
055    KRB_NT_SRV_HST(3),
056
057    /** Constant for the "Service with host as remaining components" principal name type. */
058    KRB_NT_SRV_XHST(4),
059
060    /** Constant for the "Unique ID" principal name type. */
061    KRB_NT_UID(5),
062
063    /** Constant for the "Encoded X.509 Distinguished name [RFC2253]" principal name type. */
064    KRB_NT_X500_PRINCIPAL(6),
065
066    /** Constant for the "Name in form of SMTP email name (e.g., user@example.com)" principal name type. */
067    KRB_NT_SMTP_NAME(7),
068
069    /** Constant for the "Enterprise name; may be mapped to principal name" principal name type. */
070    KRB_NT_ENTERPRISE(10);
071
072    /**
073     * The value/code for the principal name type.
074     */
075    private final int value;
076
077
078    /**
079     * Private constructor prevents construction outside of this class.
080     */
081    private PrincipalNameType( int value )
082    {
083        this.value = value;
084    }
085
086
087    /**
088     * Returns the principal name type when specified by its ordinal.
089     *
090     * @param type
091     * @return The principal name type.
092     */
093    public static PrincipalNameType getTypeByValue( int type )
094    {
095        switch ( type )
096        {
097            case 0:
098                return KRB_NT_UNKNOWN;
099            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}