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;
021
022
023/**
024 * An enum listing all the Kerberos V5 messages :
025 * 
026 *   AS-REQ    (10) : Authentication Serveur Request
027 *   AS-REP    (11) : Authentication Serveur Response
028 *   TGS-REQ   (12) : Ticket Granting Server Request
029 *   TGS-REP   (13) : Ticket Granting Server Response
030 *   AP-REQ    (14) : Application Request
031 *   AP-REP    (15) : Application Response
032 *   KRB-SAFE  (20) : Safe (checksummed) application message
033 *   KRB-PRIV  (21) : Private (encrypted) application message
034 *   KRB-CRED  (22) : Private (encrypted) message to forward credentials
035 *   ENC_AP_REP_PART (27) : Encrypted application reply part
036 *   ENC_PRIV_PART (28) : Encrypted private message part
037 *   KRB-ERROR (30) : A kerberos error response
038 *   
039 *
040 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
041 */
042public enum KerberosMessageType
043{
044    TICKET(1, "ticket"),
045    AUTHENTICATOR(2, "Authenticator"),
046    ENC_TICKET_PART(3, "EncTicketPart"),
047    AS_REQ(10, "initial authentication request"),
048    AS_REP(11, "initial authentication response"),
049    TGS_REQ(12, "request for authentication based on TGT"),
050    TGS_REP(13, "response to authentication based on TGT"),
051    AP_REQ(14, "application request"),
052    AP_REP(15, "application response"),
053    KRB_SAFE(20, "safe (checksummed) application message"),
054    KRB_PRIV(21, "private (encrypted) application message"),
055    KRB_CRED(22, "private (encrypted) message to forward credentials"),
056    ENC_AS_REP_PART(25, "encrypted authentication reply part"),
057    ENC_TGS_REP_PART(26, "encrypted TGT reply part"),
058    ENC_AP_REP_PART(27, "encrypted application reply part"),
059    ENC_PRIV_PART(28, "encrypted private message part"),
060    KRB_ERROR(30, "error response");
061
062    private int value;
063    private String message;
064
065
066    /**
067     * Creates a new instance of KerberosMessageType.
068     */
069    private KerberosMessageType( int value, String message )
070    {
071        this.value = value;
072        this.message = message;
073    }
074
075
076    /**
077     * Get the int value for this element
078     *
079     * @return The int value of this element
080     */
081    public int getValue()
082    {
083        return value;
084    }
085
086
087    /**
088     * Get the message associated with this element
089     *
090     * @return The message associated with this element
091     */
092    public String getMessage()
093    {
094        return message;
095    }
096
097
098    /**
099     * Get the instance of a KerberosMessageType from an int value
100     *
101     * @param value The int value 
102     * @return A KerberosMessageType associated with this value
103     */
104    public static KerberosMessageType getTypeByValue( int value )
105    {
106        switch ( value )
107        {
108            case 1:
109                return TICKET;
110            case 2:
111                return AUTHENTICATOR;
112            case 3:
113                return ENC_TICKET_PART;
114            case 10:
115                return AS_REQ;
116            case 11:
117                return AS_REP;
118            case 12:
119                return TGS_REQ;
120            case 13:
121                return TGS_REP;
122            case 14:
123                return AP_REQ;
124            case 15:
125                return AP_REP;
126            case 20:
127                return KRB_SAFE;
128            case 21:
129                return KRB_PRIV;
130            case 22:
131                return KRB_CRED;
132            case 27:
133                return ENC_AP_REP_PART;
134            case 28:
135                return ENC_PRIV_PART;
136            case 30:
137                return KRB_ERROR;
138            default:
139                return null;
140        }
141    }
142}