directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1031354 [3/4] - in /directory/apacheds/trunk/kerberos-codec: ./ .settings/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/shared/ src/main/j...
Date Thu, 04 Nov 2010 23:48:50 GMT
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosStatesEnum.java?rev=1031354&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosStatesEnum.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosStatesEnum.java Thu Nov  4 23:48:49 2010
@@ -0,0 +1,121 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec;
+
+
+import org.apache.directory.shared.asn1.ber.grammar.Grammar;
+import org.apache.directory.shared.asn1.ber.grammar.States;
+
+
+/**
+ * This class store the Kerberos grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum KerberosStatesEnum implements States
+{
+    // ~ Static fields/initializers
+    // -----------------------------------------------------------------
+
+    /** The END_STATE */
+    END_STATE,
+
+    // Start
+    START_STATE,
+    
+    // ----- Ticket message --------------------------------------------
+    TICKET_STATE,
+    TICKET_SEQ_STATE,
+    
+    TICKET_VNO_TAG_STATE,
+    TICKET_VNO_STATE,
+    
+    TICKET_REALM_TAG_STATE,
+    TICKET_REALM_STATE,
+    
+    TICKET_SNAME_TAG_STATE,
+
+    TICKET_ENC_PART_TAG_STATE,
+    
+    // End
+    LAST_KERBEROS_STATE;
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "KERBEROS_MESSAGE_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar grammar )
+    {
+        if ( grammar instanceof KerberosMessageGrammar )
+        {
+            return "KERBEROS_MESSAGE_GRAMMAR";
+        }
+        else
+        {
+            return "UNKNOWN GRAMMAR";
+        }
+    }
+
+
+    /**
+     * Get the string representing the state
+     * 
+     * @param state The state number
+     * @return The String representing the state
+     */
+    public String getState( int state )
+    {
+        return ( ( state == END_STATE.ordinal() ) ? "KERBEROS_MESSAGE_END_STATE" : name() );
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == END_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public KerberosStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java?rev=1031354&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java Thu Nov  4 23:48:49 2010
@@ -0,0 +1,331 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.components;
+
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.shared.asn1.AbstractAsn1Object;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A structure storing an encrypted data element. The ASN.1 grammar is :
+ * 
+ * EncryptedData   ::= SEQUENCE {
+ *        etype   [0] Int32 -- EncryptionType --,
+ *        kvno    [1] UInt32 OPTIONAL,
+ *        cipher  [2] OCTET STRING -- ciphertext
+ * }
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncryptedData extends AbstractAsn1Object
+{
+    /** The logger */
+    private static final Logger log = LoggerFactory.getLogger( EncryptedData.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+    /** The used encryption algorithm */
+    private EncryptionType eType;
+
+    /** Version number of the key under which data is encrypted */
+    private int kvno;
+
+    /** A flag used to tell if a kvno has been added, as the kvno is optional. */
+    private boolean hasKvno;
+
+    /** The field containing the enciphered text */
+    private byte[] cipher;
+
+    /** A constant used when the key is not present */
+    public static final boolean HAS_KVNO = true;
+
+    // Storage for computed lengths
+    private transient int eTypeTagLength;
+    private transient int kvnoTagLength;
+    private transient int cipherTagLength;
+    private transient int encryptedDataSeqLength;
+
+
+    /**
+     * Creates a new instance of EncryptedData.
+     */
+    public EncryptedData()
+    {
+        hasKvno = !HAS_KVNO;
+    }
+    
+    /**
+     * Creates a new instance of EncryptedData.
+     *
+     * @param eType The encription algorithm
+     * @param kvno The key version
+     * @param cipher the encrypted text
+     */
+    public EncryptedData( EncryptionType eType, int kvno, byte[] cipher )
+    {
+        this.eType = eType;
+        this.hasKvno = kvno > 0;
+        this.kvno = kvno;
+        this.cipher = cipher;
+    }
+
+
+    /**
+     * Creates a new instance of EncryptedData.
+     *
+     * @param eType The encription algorithm
+     * @param cipher the encrypted text
+     */
+    public EncryptedData( EncryptionType eType, byte[] cipher )
+    {
+        this.eType = eType;
+        this.hasKvno = !HAS_KVNO;
+        kvno = -1;
+        this.cipher = cipher;
+    }
+
+
+    /**
+     * Returns the {@link EncryptionType}.
+     *
+     * @return The {@link EncryptionType}.
+     */
+    public EncryptionType getEType()
+    {
+        return eType;
+    }
+
+
+    /**
+     * Set the EncryptionType
+     * @param eType the EncryptionType
+     */
+    public void setEType( EncryptionType eType )
+    {
+        this.eType = eType;
+    }
+
+    /**
+     * Returns the key version.
+     *
+     * @return The key version.
+     */
+    public int getKvno()
+    {
+        return hasKvno ? kvno : -1;
+    }
+
+    /**
+     * Set the key version
+     * @param kvno The key version
+     */
+    public void setKvno( int kvno )
+    {
+        this.kvno = kvno;
+    }
+
+    /**
+     * Tells if there is a key version.
+     *
+     * @return <code>true</code> if there is a key version.
+     */
+    public boolean hasKvno()
+    {
+        return hasKvno;
+    }
+
+
+    /**
+     * Returns the raw cipher text.
+     *
+     * @return The raw cipher text.
+     */
+    public byte[] getCipher()
+    {
+        return cipher;
+    }
+
+    /**
+     * Set the cipher text
+     * @param cipher The cipher text
+     */
+    public void setCipher( byte[] cipher )
+    {
+        this.cipher = cipher;
+    }
+    
+
+    /**
+     * Compute the EncryptedData length
+     * 
+     * EncryptedData :
+     * 
+     * 0x30 L1 EncryptedData sequence
+     *  |
+     *  +--> 0xA1 L2 etype tag
+     *  |     |
+     *  |     +--> 0x02 L2-1 etype (int)
+     *  |
+     *  +--> [0xA2 L3 kvno tag
+     *  |     |
+     *  |     +--> 0x30 L3-1 kvno (int)] (optional)
+     *  |
+     *  +--> 0xA2 L4 cipher tag
+     *        |
+     *        +--> 0x04 L4-1 cipher (OCTET STRING)
+     */
+    public int computeLength()
+    {
+        encryptedDataSeqLength = 0;
+
+        // Compute the encryption Type length
+        int eTypeLength = Value.getNbBytes( eType.getOrdinal() );
+        eTypeTagLength = 1 + TLV.getNbBytes( eTypeLength ) + eTypeLength;
+        encryptedDataSeqLength = 1 + TLV.getNbBytes( eTypeTagLength ) + eTypeTagLength; 
+
+
+        // Compute the kvno length if any
+        if ( hasKvno )
+        {
+            int kvnoLength = Value.getNbBytes( kvno );
+            kvnoTagLength = 1 + TLV.getNbBytes( kvnoLength ) + kvnoLength;
+            encryptedDataSeqLength += 1 + TLV.getNbBytes( kvnoTagLength ) + kvnoTagLength;
+        }
+        else
+        {
+            kvnoTagLength = 0;
+        }
+
+        // Compute the cipher
+        if ( ( cipher == null ) || ( cipher.length == 0 ) )
+        {
+            cipherTagLength = 1 + 1;
+        }
+        else
+        {
+            cipherTagLength = 1 + TLV.getNbBytes( cipher.length ) + cipher.length;
+        }
+
+        encryptedDataSeqLength += 1 + TLV.getNbBytes( cipherTagLength ) + cipherTagLength;
+
+        // Compute the whole sequence length
+        return 1 + TLV.getNbBytes( encryptedDataSeqLength ) + encryptedDataSeqLength;
+    }
+
+
+    /**
+     * Encode the EncryptedData message to a PDU. 
+     * 
+     * EncryptedData :
+     * 
+     * 0x30 LL
+     *   0xA0 LL 
+     *     0x02 0x01 etype (integer)
+     *   [0xA1 LL 
+     *     0x02 0x01 kvno (integer)] (optional)
+     *   0xA2 LL 
+     *     0x04 LL cipher (OCTET STRING)
+     * 
+     * @param buffer The buffer where to put the PDU. It should have been allocated
+     * before, with the right size.
+     * @return The constructed PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_148 ) );
+        }
+
+        try
+        {
+            // The EncryptedData SEQ Tag
+            buffer.put( UniversalTag.SEQUENCE.getValue() );
+            buffer.put( TLV.getBytes( encryptedDataSeqLength ) );
+
+            // The etype, first the tag, then the value
+            buffer.put( ( byte ) 0xA0 );
+            buffer.put( TLV.getBytes( eTypeTagLength ) );
+
+            Value.encode( buffer, eType.getOrdinal() );
+
+            // The kvno, if any, first the tag, then the value
+            if ( hasKvno )
+            {
+                buffer.put( ( byte ) 0xA1 );
+                buffer.put( TLV.getBytes( kvnoTagLength ) );
+
+                Value.encode( buffer, kvno );
+            }
+
+            // The cipher tag
+            buffer.put( ( byte ) 0xA2 );
+            buffer.put( TLV.getBytes( cipherTagLength ) );
+            Value.encode( buffer, cipher );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            log.error( I18n.err( I18n.ERR_141, 1 + TLV.getNbBytes( encryptedDataSeqLength ) 
+                + encryptedDataSeqLength, buffer.capacity() ) );
+            throw new EncoderException( I18n.err( I18n.ERR_138 ) );
+        }
+
+        if ( IS_DEBUG )
+        {
+            log.debug( "EncryptedData encoding : {}", StringTools.dumpBytes( buffer.array() ) );
+            log.debug( "EncryptedData initial value : {}", toString() );
+        }
+
+        return buffer;
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( "EncryptedData : {\n" );
+        sb.append( "    etype: " ).append( eType ).append( '\n' );
+
+        if ( hasKvno )
+        {
+            sb.append( "    kvno: " ).append( kvno ).append( '\n' );
+        }
+
+        sb.append( "    cipher: " ).append( StringTools.dumpBytes( cipher ) ).append( "\n}\n" );
+
+        return sb.toString();
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptionType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptionType.java?rev=1031354&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptionType.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptionType.java Thu Nov  4 23:48:49 2010
@@ -0,0 +1,278 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.components;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * A type-safe enumeration of Kerberos encryption types.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum EncryptionType
+{
+    /**
+     * The "unknown" encryption type.
+     */
+    UNKNOWN( -1, "UNKNOWN" ),
+
+    /**
+     * The "null" encryption type.
+     */
+    NULL( 0, "null" ),
+
+    /**
+     * The des-cbc-crc encryption type.
+     */
+    DES_CBC_CRC( 1, "des-cbc-crc" ),
+
+    /**
+     * The des-cbc-md4 encryption type.
+     */
+    DES_CBC_MD4( 2, "des-cbc-md4" ),
+
+    /**
+     * The des-cbc-md5 encryption type.
+     */
+    DES_CBC_MD5( 3, "des-cbc-md5" ),
+
+    /**
+     * The reserved (4) encryption type.
+     */
+    RESERVED4( 4, "[reserved]" ),
+
+    /**
+     * The des3-cbc-md5 encryption type.
+     */
+    DES3_CBC_MD5( 5, "des3-cbc-md5" ),
+
+    /**
+     * The reserved (6) encryption type.
+     */
+    RESERVED6( 6, "[reserved]" ),
+
+    /**
+     * The des3-cbc-sha1 encryption type.
+     */
+    DES3_CBC_SHA1( 7, "des3-cbc-sha1" ),
+
+    /**
+     * The dsaWithSHA1-CmsOID encryption type.
+     */
+    DSAWITHSHA1_CMSOID( 9, "dsaWithSHA1-CmsOID" ),
+
+    /**
+     * The md5WithRSAEncryption-CmsOID encryption type.
+     */
+    MD5WITHRSAENCRYPTION_CMSOID( 10, "md5WithRSAEncryption-CmsOID" ),
+
+    /**
+     * The sha1WithRSAEncryption-CmsOID encryption type.
+     */
+    SHA1WITHRSAENCRYPTION_CMSOID( 11, "sha1WithRSAEncryption-CmsOID" ),
+
+    /**
+     * The rc2CBC-EnvOID encryption type.
+     */
+    RC2CBC_ENVOID( 12, "rc2CBC-EnvOID" ),
+
+    /**
+     * The rsaEncryption-EnvOID encryption type.
+     */
+    RSAENCRYPTION_ENVOID( 13, "rsaEncryption-EnvOID" ),
+
+    /**
+     * The rsaES-OAEP-ENV-OID encryption type.
+     */
+    RSAES_OAEP_ENV_OID( 14, "rsaES-OAEP-ENV-OID" ),
+
+    /**
+     * The des-ede3-cbc-Env-OID encryption type.
+     */
+    DES_EDE3_CBC_ENV_OID( 15, "des-ede3-cbc-Env-OID" ),
+
+    /**
+     * The des3-cbc-sha1-kd encryption type.
+     */
+    DES3_CBC_SHA1_KD( 16, "des3-cbc-sha1-kd" ),
+
+    /**
+     * The aes128-cts-hmac-sha1-96 encryption type.
+     */
+    AES128_CTS_HMAC_SHA1_96( 17, "aes128-cts-hmac-sha1-96" ),
+
+    /**
+     * The aes256-cts-hmac-sha1-96 encryption type.
+     */
+    AES256_CTS_HMAC_SHA1_96( 18, "aes256-cts-hmac-sha1-96" ),
+
+    /**
+     * The rc4-hmac encryption type.
+     */
+    RC4_HMAC( 23, "rc4-hmac" ),
+
+    /**
+     * The rc4-hmac-exp encryption type.
+     */
+    RC4_HMAC_EXP( 24, "rc4-hmac-exp" ),
+
+    /**
+     * The subkey-keymaterial encryption type.
+     */
+    SUBKEY_KEYMATERIAL( 65, "subkey-keymaterial" ),
+
+    /**
+     * The rc4-md4 encryption type.
+     */
+    RC4_MD4( -128, "rc4-md4" ),
+
+    /**
+     * The c4-hmac-old encryption type.
+     */
+    RC4_HMAC_OLD( -133, "rc4-hmac-old" ),
+
+    /**
+     * The rc4-hmac-old-exp encryption type.
+     */
+    RC4_HMAC_OLD_EXP( -135, "rc4-hmac-old-exp" );
+
+    /**
+     * The value/code for the encryption type.
+     */
+    private final int ordinal;
+
+    /**
+     * The name
+     */
+    private final String name;
+
+    /** A map containing all the values */
+    private static Map<String, EncryptionType> encryptionTypesByName = new HashMap<String, EncryptionType>();
+
+    /** A map containing all the values */
+    private static Map<Integer, EncryptionType> encryptionTypesByOrdinal = new HashMap<Integer, EncryptionType>();
+
+    /** Initialization of the previous map */
+    static
+    {
+        for ( EncryptionType type : EncryptionType.values() )
+        {
+            encryptionTypesByName.put( type.getName().toLowerCase(), type );
+            encryptionTypesByOrdinal.put( type.getOrdinal(), type );
+        }
+    }
+
+
+    /**
+     * Private constructor prevents construction outside of this class.
+     */
+    private EncryptionType( int ordinal, String name )
+    {
+        this.ordinal = ordinal;
+        this.name = name;
+    }
+
+    
+    /**
+     * Get all the encryption types
+     *
+     * @return A set of encryption types.
+     */
+    public static Collection<EncryptionType> getEncryptionTypes()
+    {
+        return encryptionTypesByName.values();
+    }
+
+    /**
+     * Returns the encryption type when specified by its ordinal.
+     *
+     * @param type
+     * @return The encryption type.
+     */
+    public static EncryptionType getTypeByOrdinal( int type )
+    {
+        if ( encryptionTypesByOrdinal.containsKey( type ) )
+        {
+            return encryptionTypesByOrdinal.get( type );
+        }
+        else
+        {
+            return UNKNOWN;
+        }
+    }
+
+
+    /**
+     * Returns the number associated with this encryption type.
+     *
+     * @return The encryption type number.
+     */
+    public int getOrdinal()
+    {
+        return ordinal;
+    }
+
+
+    /**
+     * Returns the name associated with this encryption type.
+     *
+     * @return The name.
+     */
+    public String getName()
+    {
+        return name;
+    }
+
+    /**
+     * Get the EncryptionType given a String.
+     * @param type The encryption string we want to find
+     * @return The found EncryptionType, or UNKNOWN
+     */
+    public static EncryptionType getByName( String type )
+    {
+        if ( type == null )
+        {
+            return UNKNOWN;
+        }
+        
+        String lcType = type.toLowerCase();
+        
+        if ( encryptionTypesByName.containsKey( lcType ) )
+        {
+            return encryptionTypesByName.get( lcType );
+        }
+        else
+        {
+            return UNKNOWN;
+        }
+    }
+    
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return getName() + " (" + ordinal + ")";
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PrincipalName.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PrincipalName.java?rev=1031354&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PrincipalName.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PrincipalName.java Thu Nov  4 23:48:49 2010
@@ -0,0 +1,478 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+//package org.apache.directory.server.kerberos.shared.messages.value;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ *
+public class PrincipalName
+{
+    private String nameComponent;
+    private int nameType;
+
+
+    /**
+     * Creates a new instance of PrincipalName.
+     *
+     * @param nameComponent
+     * @param nameType
+     *
+    public PrincipalName( String nameComponent, int nameType )
+    {
+        this.nameComponent = nameComponent;
+        this.nameType = nameType;
+    }
+
+
+    /**
+     * Returns the type of the {@link PrincipalName}.
+     *
+     * @return The type of the {@link PrincipalName}.
+     *
+    public int getNameType()
+    {
+        return nameType;
+    }
+
+
+    /**
+     * Returns the name component.
+     *
+     * @return The name component.
+     *
+    public String getNameComponent()
+    {
+        return nameComponent;
+    }
+}*/
+
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.components;
+
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.security.auth.kerberos.KerberosPrincipal;
+
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.shared.asn1.AbstractAsn1Object;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.KerberosUtils;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A principal Name, composed of a type and N names.
+ * 
+ * PrincipalName   ::= SEQUENCE {
+ *        name-type       [0] Int32,
+ *        name-string     [1] SEQUENCE OF KerberosString
+ * }
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PrincipalName extends AbstractAsn1Object
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( PrincipalName.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The type for this principal */
+    private PrincipalNameType nameType;
+
+    /** The principal name - we may have more than one - */
+    private List<String> nameString;
+    
+    /** The principal name as a byte[], for encoding purpose */
+    private transient List<byte[]> nameBytes;
+    
+    // Storage for computed lengths
+    private transient int principalNameSeqLength;
+    private transient int principalTypeTagLength;
+    private transient int principalTypeLength;
+    private transient int principalStringsTagLength;
+    private transient int principalStringsSeqLength;
+
+    /**
+     * Creates a new empty instance of PrincipalName.
+     */
+    public PrincipalName()
+    {
+    }
+
+    /**
+     * Creates a new instance of PrincipalName, given a KerberosPrincipal.
+     * 
+     * We assume that a principal has only one type, even if there are
+     * more than one name component.
+     *
+     * @param principal A Sun kerberosPrincipal instance
+     */
+    public PrincipalName( KerberosPrincipal principal )
+    {
+        try
+        {
+            nameString = KerberosUtils.getNames( principal );
+        }
+        catch ( ParseException pe )
+        {
+            nameString = KerberosUtils.EMPTY_PRINCIPAL_NAME;
+        }
+
+        this.nameType = PrincipalNameType.getTypeByOrdinal( principal.getNameType() );
+    }
+    
+    /**
+     * Creates a new instance of PrincipalName given a String and an 
+     * prinipal type.
+     * 
+     * @param nameString The name string, which can contains more than one nameComponent
+     * @param nameType The principal name
+     */
+    public PrincipalName( String nameString, PrincipalNameType nameType )  throws ParseException
+    {
+        this.nameString = KerberosUtils.getNames( nameString );
+        
+        this.nameType = nameType;
+    }
+
+
+    /**
+     * Creates a new instance of PrincipalName.
+     *
+     * @param nameString
+     * @param nameType
+     */
+    public PrincipalName( String nameString, int nameType ) throws ParseException
+    {
+        this.nameString = KerberosUtils.getNames( nameString );
+        
+        this.nameType = PrincipalNameType.getTypeByOrdinal( nameType );
+    }
+
+
+    /**
+     * Returns the type of the {@link PrincipalName}.
+     *
+     * @return The type of the {@link PrincipalName}.
+     */
+    public PrincipalNameType getNameType()
+    {
+        return nameType;
+    }
+                    
+    /** 
+     * Set the Principal name Type
+     * @param nameType the Principal name Type
+     */
+    public void setNameType( PrincipalNameType nameType )
+    {
+        this.nameType = nameType;
+    }
+
+    /** 
+     * Set the Principal name Type
+     * @param nameType the Principal name Type
+     */
+    public void setNameType( int nameType )
+    {
+        this.nameType = PrincipalNameType.getTypeByOrdinal( nameType );
+    }
+
+    /**
+     * Returns the name components.
+     *
+     * @return The name components.
+     */
+    public List<String> getNames()
+    {
+        return nameString;
+    }
+
+
+    /**
+     * @return A String representing the principal names as a String 
+     */
+    public String getNameString()
+    {
+        if ( ( nameString == null ) || ( nameString.size() == 0 ) )
+        {
+            return "";
+        }
+        else
+        {
+            StringBuilder sb = new StringBuilder();
+            boolean isFirst = true;
+
+            for ( String name : nameString )
+            {
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    sb.append( '/' );
+                }
+
+                sb.append( name );
+            }
+
+            return sb.toString();
+        }
+    }
+
+
+    /**
+     * Add a new name to the PrincipalName
+     * @param name The name to add
+     */
+    public void addName( String name )
+    {
+        if ( nameString == null )
+        {
+            nameString = new ArrayList<String>();
+        }
+
+        nameString.add( name );
+    }
+
+
+    /**
+     * Compute the PrincipalName length
+     * 
+     * PrincipalName :
+     * 
+     * 0x30 L1 PrincipalName sequence
+     *  |
+     *  +--> 0xA1 L2 name-type tag
+     *  |     |
+     *  |     +--> 0x02 L2-1 addressType (int)
+     *  |
+     *  +--> 0xA2 L3 name-string tag
+     *        |
+     *        +--> 0x30 L3-1 name-string (SEQUENCE OF KerberosString)
+     *              |
+     *              +--> 0x1B L4[1] value (KerberosString)
+     *              |
+     *              +--> 0x1B L4[2] value (KerberosString)
+     *              |
+     *              ...
+     *              |
+     *              +--> 0x1B L4[n] value (KerberosString)
+     */
+    public int computeLength()
+    {
+        // The principalName can't be empty.
+        principalTypeLength = Value.getNbBytes( nameType.getOrdinal() );
+        principalTypeTagLength = 1 + TLV.getNbBytes( principalTypeLength ) + principalTypeLength;
+        
+        principalNameSeqLength = 1 + TLV.getNbBytes( principalTypeTagLength ) + principalTypeTagLength;
+
+        // Compute the keyValue
+        if ( ( nameString == null ) || ( nameString.size() == 0 ) )
+        {
+            principalStringsSeqLength = 0;
+        }
+        else
+        {
+            principalStringsSeqLength = 0;
+            nameBytes = new ArrayList<byte[]>( nameString.size() );
+
+            for ( String name : nameString )
+            {
+                if ( name != null )
+                {
+                    byte[] bytes = StringTools.getBytesUtf8( name );
+                    nameBytes.add( bytes );
+                    principalStringsSeqLength += 1 + TLV.getNbBytes( bytes.length ) + bytes.length;
+                }
+                else
+                {
+                    nameBytes.add( StringTools.EMPTY_BYTES );
+                    principalStringsSeqLength += 1 + 1;
+                }
+            }
+        }
+
+        principalStringsTagLength = 1 + TLV.getNbBytes( principalStringsSeqLength ) + principalStringsSeqLength;
+        principalNameSeqLength += 1 + TLV.getNbBytes( principalStringsTagLength ) + principalStringsTagLength;
+
+        // Compute the whole sequence length
+        return 1 + TLV.getNbBytes( principalNameSeqLength ) + principalNameSeqLength;
+    }
+
+
+    /**
+     * Encode the PrincipalName message to a PDU. 
+     * 
+     * PrincipalName :
+     * 
+     * 0x30 LL
+     *   0xA0 LL 
+     *     0x02 0x01 name-type (integer)
+     *   0xA1 LL 
+     *     0x30 LL name-string (SEQUENCE OF KerberosString)
+     *       0x1B LL name-string[1]
+     *       0x1B LL name-string[2]
+     *       ...
+     *       0x1B LL name-string[n]
+     * 
+     * @param buffer The buffer where to put the PDU. It should have been allocated
+     * before, with the right size.
+     * @return The constructed PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_148 ) );
+        }
+
+        try
+        {
+            // The PrincipalName SEQ Tag
+            buffer.put( UniversalTag.SEQUENCE.getValue() );
+            buffer.put( TLV.getBytes( principalNameSeqLength ) );
+
+            // The name-type, first the tag, then the value
+            buffer.put( ( byte ) 0xA0 );
+            buffer.put( TLV.getBytes( principalTypeTagLength ) );
+            Value.encode( buffer, nameType.getOrdinal() );
+
+            // The name-string tag
+            buffer.put( ( byte ) 0xA1 );
+            buffer.put( TLV.getBytes( principalStringsTagLength ) );
+
+            // The name-string sequence
+            buffer.put( UniversalTag.SEQUENCE.getValue() );
+
+            if ( ( nameString == null ) || ( nameString.size() == 0 ) )
+            {
+                buffer.put( ( byte ) 0x00 );
+            }
+            else
+            {
+                buffer.put( TLV.getBytes( principalStringsSeqLength ) );
+
+                // The kerberosStrings
+                for ( byte[] name : nameBytes )
+                {
+                    buffer.put( UniversalTag.GENERAL_STRING.getValue() );
+
+                    if ( ( name == null ) || ( name.length == 0 ) )
+                    {
+                        buffer.put( ( byte ) 0x00 );
+                    }
+                    else
+                    {
+                        buffer.put( TLV.getBytes( name.length ) );
+                        buffer.put( name );
+                    }
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            LOG.error( I18n.err( I18n.ERR_146, 1 + TLV.getNbBytes( principalNameSeqLength )
+                + principalNameSeqLength, buffer.capacity() ) );
+            throw new EncoderException( I18n.err( I18n.ERR_138 ) );
+        }
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "PrinipalName encoding : {}", StringTools.dumpBytes( buffer.array() ) );
+            LOG.debug( "PrinipalName initial value : {}", toString() );
+        }
+
+        return buffer;
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( "PincipalName : {\n" );
+
+        sb.append( "    name-type: " ).append( nameType ).append( '\n' );
+
+        if ( ( nameString != null ) && ( nameString.size() != 0 ) )
+        {
+            sb.append( "    name-string : <" );
+            boolean isFirst = true;
+
+            for ( String name : nameString )
+            {
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    sb.append( ", " );
+                }
+
+                sb.append( '\'' ).append( name ).append( '\'' );
+            }
+
+            sb.append( ">\n}" );
+        }
+        else
+        {
+            sb.append( "    no name-string\n}" );
+        }
+
+        return sb.toString();
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PrincipalNameType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PrincipalNameType.java?rev=1031354&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PrincipalNameType.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PrincipalNameType.java Thu Nov  4 23:48:49 2010
@@ -0,0 +1,177 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.components;
+
+
+/**
+ * An enum describing the differnet types of Principal.
+ * 
+ * Here is the list, taken from RFC 4120 :
+ *  NT-UNKNOWN        0    Name type not known
+ *  NT-PRINCIPAL      1    Just the name of the principal as in DCE,
+ *                           or for users
+ *  NT-SRV-INST       2    Service and other unique instance (krbtgt)
+ *  NT-SRV-HST        3    Service with host name as instance
+ *                           (telnet, rcommands)
+ *  NT-SRV-XHST       4    Service with host as remaining components
+ *  NT-UID            5    Unique ID
+ *  NT-X500-PRINCIPAL 6    Encoded X.509 Distinguished name [RFC2253]
+ *  NT-SMTP-NAME      7    Name in form of SMTP email name
+ *                           (e.g., user@example.com)
+ *  NT-ENTERPRISE    10    Enterprise name - may be mapped to principal
+ *                           name
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum PrincipalNameType
+{
+    /**
+     * Constant for the "Name type not known" principal name type.
+     */
+    KRB_NT_UNKNOWN( 0 ),
+
+    /**
+     * Constant for the "Just the name of the principal as in DCE, or for users" principal name type.
+     */
+    KRB_NT_PRINCIPAL( 1 ),
+
+    /**
+     * Constant for the "Service and other unique instance (krbtgt)" principal name type.
+     */
+    KRB_NT_SRV_INST( 2 ),
+
+    /**
+     * Constant for the "Service with host name as instance (telnet, rcommands)" principal name type.
+     */
+    KRB_NT_SRV_HST( 3 ),
+
+    /**
+     * Constant for the "Service with host as remaining components" principal name type.
+     */
+    KRB_NT_SRV_XHST( 4 ),
+
+    /**
+     * Constant for the "Unique ID" principal name type.
+     */
+    KRB_NT_UID( 5 ),
+
+    /**
+     * Constant for the "Encoded X.509 Distinguished name [RFC2253]" principal name type.
+     */
+    KRB_NT_X500_PRINCIPAL( 6 ),
+
+    /**
+     * Constant for the "Name in form of SMTP email name (e.g., user@example.com)" principal name type.
+     */
+    KRB_NT_SMTP_NAME( 7 ),
+
+    /**
+     * Constant for the "Enterprise name; may be mapped to principal name" principal name type.
+     */
+    KRB_NT_ENTERPRISE( 10 );
+
+    /**
+     * The value/code for the principal name type.
+     */
+    private final int ordinal;
+
+
+    /**
+     * Private constructor prevents construction outside of this class.
+     */
+    private PrincipalNameType( int ordinal )
+    {
+        this.ordinal = ordinal;
+    }
+
+
+    /**
+     * Returns the principal name type when specified by its ordinal.
+     *
+     * @param type
+     * @return The principal name type.
+     */
+    public static PrincipalNameType getTypeByOrdinal( int type )
+    {
+        switch ( type )
+        {
+            case 0 : return KRB_NT_UNKNOWN;
+            case 1 : return KRB_NT_PRINCIPAL;
+            case 2 : return KRB_NT_SRV_INST;
+            case 3 : return KRB_NT_SRV_HST;
+            case 4 : return KRB_NT_SRV_XHST;
+            case 5 : return KRB_NT_UID;
+            case 6 : return KRB_NT_X500_PRINCIPAL;
+            case 7 : return KRB_NT_SMTP_NAME;
+            case 10 : return KRB_NT_ENTERPRISE;
+            default : return KRB_NT_UNKNOWN;
+        }
+    }
+
+
+    /**
+     * Returns the number associated with this principal name type.
+     *
+     * @return The principal name type ordinal.
+     */
+    public int getOrdinal()
+    {
+        return ordinal;
+    }
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        switch ( this )
+        {
+            case KRB_NT_UNKNOWN         : 
+                return "Name type not known" + "(" + ordinal + ")";
+                
+            case KRB_NT_PRINCIPAL       : 
+                return "Just the name of the principal as in DCE, or for users" + "(" + ordinal + ")";
+                
+            case KRB_NT_SRV_INST        : 
+                return "Service and other unique instance (krbtgt)" + "(" + ordinal + ")";
+            
+            case KRB_NT_SRV_HST         : 
+                return "Service with host name as instance (telnet, rcommands)" + "(" + ordinal + ")";
+            
+            case KRB_NT_SRV_XHST        : 
+                return "Service with host as remaining components" + "(" + ordinal + ")";
+            
+            case KRB_NT_UID             : 
+                return "Unique ID" + "(" + ordinal + ")";
+            
+            case KRB_NT_X500_PRINCIPAL  : 
+                return "Encoded X.509 Distinguished name [RFC2253]" + "(" + ordinal + ")";
+            
+            case KRB_NT_SMTP_NAME       : 
+                return "Name in form of SMTP email name (e.g., user@example.com)" + "(" + ordinal + ")";
+            
+            case KRB_NT_ENTERPRISE      : 
+                return "Enterprise name; may be mapped to principal name" + "(" + ordinal + ")";
+            
+            default                     : 
+                return "unknown name type" + "(" + ordinal + ")";
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/exceptions/ErrorType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/exceptions/ErrorType.java?rev=1031354&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/exceptions/ErrorType.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/exceptions/ErrorType.java Thu Nov  4 23:48:49 2010
@@ -0,0 +1,541 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.exceptions;
+
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+
+/**
+ * A type-safe enumeration of Kerberos error types.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class ErrorType implements Comparable<ErrorType>
+{
+ 
+    // TODO Add i18n. Don't no if these error messages are also a response to the client.
+    // If so shall they really be i18n?
+    
+    /**
+     * No error.
+     */
+    public static final ErrorType KDC_ERR_NONE = new ErrorType( 0, "No error" );
+
+    /**
+     * Client's entry in database has expired.
+     */
+    public static final ErrorType KDC_ERR_NAME_EXP = new ErrorType( 1, "Client's entry in database has expired" );
+
+    /**
+     * Server's entry in database has expired.
+     */
+    public static final ErrorType KDC_ERR_SERVICE_EXP = new ErrorType( 2, "Server's entry in database has expired" );
+
+    /**
+     * Requested protocol version number not supported.
+     */
+    public static final ErrorType KDC_ERR_BAD_PVNO = new ErrorType( 3,
+        "Requested protocol version number not supported" );
+
+    /**
+     * Client's key encrypted in old master key.
+     */
+    public static final ErrorType KDC_ERR_C_OLD_MAST_KVNO = new ErrorType( 4,
+        "Client's key encrypted in old master key" );
+
+    /**
+     * Server's key encrypted in old master key.
+     */
+    public static final ErrorType KDC_ERR_S_OLD_MAST_KVNO = new ErrorType( 5,
+        "Server's key encrypted in old master key" );
+
+    /**
+     * Client not found in Kerberos database.
+     */
+    public static final ErrorType KDC_ERR_C_PRINCIPAL_UNKNOWN = new ErrorType( 6,
+        "Client not found in Kerberos database" );
+
+    /**
+     * Server not found in Kerberos database.
+     */
+    public static final ErrorType KDC_ERR_S_PRINCIPAL_UNKNOWN = new ErrorType( 7,
+        "Server not found in Kerberos database" );
+
+    /**
+     * Multiple principal entries in database.
+     */
+    public static final ErrorType KDC_ERR_PRINCIPAL_NOT_UNIQUE = new ErrorType( 8,
+        "Multiple principal entries in database" );
+
+    /**
+     * The client or server has a null key.
+     */
+    public static final ErrorType KDC_ERR_NULL_KEY = new ErrorType( 9, "The client or server has a null key" );
+
+    /**
+     * Ticket not eligible for postdating.
+     */
+    public static final ErrorType KDC_ERR_CANNOT_POSTDATE = new ErrorType( 10, "Ticket not eligible for postdating" );
+
+    /**
+     * Requested start time is later than end time.
+     */
+    public static final ErrorType KDC_ERR_NEVER_VALID = new ErrorType( 11,
+        "Requested start time is later than end time" );
+
+    /**
+     * KDC policy rejects request.
+     */
+    public static final ErrorType KDC_ERR_POLICY = new ErrorType( 12, "KDC policy rejects request" );
+
+    /**
+     * KDC cannot accommodate requested option.
+     */
+    public static final ErrorType KDC_ERR_BADOPTION = new ErrorType( 13, "KDC cannot accommodate requested option" );
+
+    /**
+     * KDC has no support for encryption type.
+     */
+    public static final ErrorType KDC_ERR_ETYPE_NOSUPP = new ErrorType( 14, "KDC has no support for encryption type" );
+
+    /**
+     * KDC has no support for checksum type.
+     */
+    public static final ErrorType KDC_ERR_SUMTYPE_NOSUPP = new ErrorType( 15, "KDC has no support for checksum type" );
+
+    /**
+     * KDC has no support for padata type.
+     */
+    public static final ErrorType KDC_ERR_PADATA_TYPE_NOSUPP = new ErrorType( 16, "KDC has no support for padata type" );
+
+    /**
+     * KDC has no support for transited type.
+     */
+    public static final ErrorType KDC_ERR_TRTYPE_NOSUPP = new ErrorType( 17, "KDC has no support for transited type" );
+
+    /**
+     * Clients credentials have been revoked.
+     */
+    public static final ErrorType KDC_ERR_CLIENT_REVOKED = new ErrorType( 18, "Clients credentials have been revoked" );
+
+    /**
+     * Credentials for server have been revoked.
+     */
+    public static final ErrorType KDC_ERR_SERVICE_REVOKED = new ErrorType( 19,
+        "Credentials for server have been revoked" );
+
+    /**
+     * TGT has been revoked.
+     */
+    public static final ErrorType KDC_ERR_TGT_REVOKED = new ErrorType( 20, "TGT has been revoked" );
+
+    /**
+     * Client not yet valid; try again later.
+     */
+    public static final ErrorType KDC_ERR_CLIENT_NOTYET = new ErrorType( 21, "Client not yet valid; try again later" );
+
+    /**
+     * Server not yet valid; try again later.
+     */
+    public static final ErrorType KDC_ERR_SERVICE_NOTYET = new ErrorType( 22, "Server not yet valid; try again later" );
+
+    /**
+     * Password has expired; change password to reset.
+     */
+    public static final ErrorType KDC_ERR_KEY_EXPIRED = new ErrorType( 23,
+        "Password has expired; change password to reset" );
+
+    /**
+     * Pre-authentication information was invalid.
+     */
+    public static final ErrorType KDC_ERR_PREAUTH_FAILED = new ErrorType( 24,
+        "Pre-authentication information was invalid" );
+
+    /**
+     * Additional pre-authentication required.
+     */
+    public static final ErrorType KDC_ERR_PREAUTH_REQUIRED = new ErrorType( 25,
+        "Additional pre-authentication required" );
+
+    /**
+     * Requested server and ticket don't match.
+     */
+    public static final ErrorType KDC_ERR_SERVER_NOMATCH = new ErrorType( 26, "Requested server and ticket don't match" );
+
+    /**
+     * Server valid for user2user only.
+     */
+    public static final ErrorType KDC_ERR_MUST_USE_USER2USER = new ErrorType( 27, "Server valid for user2user only" );
+
+    /**
+     * KDC Policy rejects transited path.
+     */
+    public static final ErrorType KDC_ERR_PATH_NOT_ACCEPTED = new ErrorType( 28, "KDC Policy rejects transited path" );
+
+    /**
+     * A service is not available.
+     */
+    public static final ErrorType KDC_ERR_SVC_UNAVAILABLE = new ErrorType( 29, "A service is not available" );
+
+    /**
+     * Integrity check on decrypted field failed.
+     */
+    public static final ErrorType KRB_AP_ERR_BAD_INTEGRITY = new ErrorType( 31,
+        "Integrity check on decrypted field failed" );
+
+    /**
+     * Ticket expired.
+     */
+    public static final ErrorType KRB_AP_ERR_TKT_EXPIRED = new ErrorType( 32, "Ticket expired" );
+
+    /**
+     * Ticket not yet valid.
+     */
+    public static final ErrorType KRB_AP_ERR_TKT_NYV = new ErrorType( 33, "Ticket not yet valid" );
+
+    /**
+     * Request is a replay.
+     */
+    public static final ErrorType KRB_AP_ERR_REPEAT = new ErrorType( 34, "Request is a replay" );
+
+    /**
+     * The ticket isn't for us.
+     */
+    public static final ErrorType KRB_AP_ERR_NOT_US = new ErrorType( 35, "The ticket isn't for us" );
+
+    /**
+     * Ticket and authenticator don't match.
+     */
+    public static final ErrorType KRB_AP_ERR_BADMATCH = new ErrorType( 36, "Ticket and authenticator don't match" );
+
+    /**
+     * Clock skew too great.
+     */
+    public static final ErrorType KRB_AP_ERR_SKEW = new ErrorType( 37, "Clock skew too great" );
+
+    /**
+     * Incorrect net address.
+     */
+    public static final ErrorType KRB_AP_ERR_BADADDR = new ErrorType( 38, "Incorrect net address" );
+
+    /**
+     * Protocol version mismatch.
+     */
+    public static final ErrorType KRB_AP_ERR_BADVERSION = new ErrorType( 39, "Protocol version mismatch" );
+
+    /**
+     * Invalid msg type.
+     */
+    public static final ErrorType KRB_AP_ERR_MSG_TYPE = new ErrorType( 40, "Invalid msg type" );
+
+    /**
+     * Message stream modified.
+     */
+    public static final ErrorType KRB_AP_ERR_MODIFIED = new ErrorType( 41, "Message stream modified" );
+
+    /**
+     * Message out of order.
+     */
+    public static final ErrorType KRB_AP_ERR_BADORDER = new ErrorType( 42, "Message out of order" );
+
+    /**
+     * Specified version of key is not available.
+     */
+    public static final ErrorType KRB_AP_ERR_BADKEYVER = new ErrorType( 44, "Specified version of key is not available" );
+
+    /**
+     * Service key not available.
+     */
+    public static final ErrorType KRB_AP_ERR_NOKEY = new ErrorType( 45, "Service key not available" );
+
+    /**
+     * Mutual authentication failed.
+     */
+    public static final ErrorType KRB_AP_ERR_MUT_FAIL = new ErrorType( 46, "Mutual authentication failed" );
+
+    /**
+     * Incorrect message direction.
+     */
+    public static final ErrorType KRB_AP_ERR_BADDIRECTION = new ErrorType( 47, "Incorrect message direction" );
+
+    /**
+     * Alternative authentication method required.
+     */
+    public static final ErrorType KRB_AP_ERR_METHOD = new ErrorType( 48, "Alternative authentication method required" );
+
+    /**
+     * Incorrect sequence number in message.
+     */
+    public static final ErrorType KRB_AP_ERR_BADSEQ = new ErrorType( 49, "Incorrect sequence number in message" );
+
+    /**
+     * Inappropriate type of checksum in message.
+     */
+    public static final ErrorType KRB_AP_ERR_INAPP_CKSUM = new ErrorType( 50,
+        "Inappropriate type of checksum in message" );
+
+    /**
+     * Policy rejects transited path.
+     */
+    public static final ErrorType KRB_AP_PATH_NOT_ACCEPTED = new ErrorType( 51, "Policy rejects transited path" );
+
+    /**
+     * Response too big for UDP; retry with TCP.
+     */
+    public static final ErrorType KRB_ERR_RESPONSE_TOO_BIG = new ErrorType( 52,
+        "Response too big for UDP; retry with TCP" );
+
+    /**
+     * Generic error (description in e-text).
+     */
+    public static final ErrorType KRB_ERR_GENERIC = new ErrorType( 60, "Generic error (description in e-text)" );
+
+    /**
+     * Field is too long for this implementation.
+     */
+    public static final ErrorType KRB_ERR_FIELD_TOOLONG = new ErrorType( 61,
+        "Field is too long for this implementation" );
+
+    /**
+     * Client is not trusted.
+     */
+    public static final ErrorType KDC_ERR_CLIENT_NOT_TRUSTED = new ErrorType( 62, "Client is not trusted" );
+
+    /**
+     * KDC is not trusted.
+     */
+    public static final ErrorType KRB_ERR_KDC_NOT_TRUSTED = new ErrorType( 63, "KDC is not trusted" );
+
+    /**
+     * Signature is invalid.
+     */
+    public static final ErrorType KDC_ERR_INVALID_SIG = new ErrorType( 64, "Signature is invalid" );
+
+    /**
+     * Diffie-Hellman (DH) key parameters not accepted.
+     */
+    public static final ErrorType KDC_ERR_DH_KEY_PARAMETERS_NOT_ACCEPTED = new ErrorType( 65,
+        "Diffie-Hellman (DH) key parameters not accepted." );
+
+    /**
+     * Certificates do not match.
+     */
+    public static final ErrorType KRB_ERR_CERTIFICATE_MISMATCH = new ErrorType( 66, "Certificates do not match" );
+
+    /**
+     * No TGT available to validate USER-TO-USER.
+     */
+    public static final ErrorType KRB_AP_ERR_NO_TGT = new ErrorType( 67, "No TGT available to validate USER-TO-USER" );
+
+    /**
+     * Wrong realm.
+     */
+    public static final ErrorType KRB_ERR_WRONG_REALM = new ErrorType( 68, "Wrong realm" );
+
+    /**
+     * Ticket must be for USER-TO-USER.
+     */
+    public static final ErrorType KRB_AP_ERR_USER_TO_USER_REQUIRED = new ErrorType( 69,
+        "Ticket must be for USER-TO-USER" );
+
+    /**
+     * Can't verify certificate.
+     */
+    public static final ErrorType KDC_ERR_CANT_VERIFY_CERTIFICATE = new ErrorType( 70, "Can't verify certificate" );
+
+    /**
+     * Invalid certificate.
+     */
+    public static final ErrorType KDC_ERR_INVALID_CERTIFICATE = new ErrorType( 71, "Invalid certificate" );
+
+    /**
+     * Revoked certificate.
+     */
+    public static final ErrorType KDC_ERR_REVOKED_CERTIFICATE = new ErrorType( 72, "Revoked certificate" );
+
+    /**
+     * Revocation status unknown.
+     */
+    public static final ErrorType KDC_ERR_REVOCATION_STATUS_UNKNOWN = new ErrorType( 73, "Revocation status unknown" );
+
+    /**
+     * Revocation status unavailable.
+     */
+    public static final ErrorType KRB_ERR_REVOCATION_STATUS_UNAVAILABLE = new ErrorType( 74,
+        "Revocation status unavailable" );
+
+    /**
+     * Client names do not match.
+     */
+    public static final ErrorType KDC_ERR_CLIENT_NAME_MISMATCH = new ErrorType( 75, "Client names do not match" );
+
+    /**
+     * KDC names do not match.
+     */
+    public static final ErrorType KRB_ERR_KDC_NAME_MISMATCH = new ErrorType( 76, "KDC names do not match" );
+
+    /**
+     * Inconsistent key purpose.
+     */
+    public static final ErrorType KDC_ERR_INCONSISTENT_KEY_PURPOSE = new ErrorType( 77, "Inconsistent key purpose" );
+
+    /**
+     * Digest in certificate not accepted.
+     */
+    public static final ErrorType KDC_ERR_DIGEST_IN_CERT_NOT_ACCEPTED = new ErrorType( 78,
+        "Digest in certificate not accepted" );
+
+    /**
+     * PA checksum must be included.
+     */
+    public static final ErrorType KDC_ERR_PA_CHECKSUM_MUST_BE_INCLUDED = new ErrorType( 79,
+        "PA checksum must be included" );
+
+    /**
+     * Digest in signed data not accepted.
+     */
+    public static final ErrorType KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTED = new ErrorType( 80,
+        "Digest in signed data not accepted" );
+
+    /**
+     * Public key encryption not supported.
+     */
+    public static final ErrorType KDC_ERR_PUBLIC_KEY_ENCRYPTION_NOT_SUPPORTED = new ErrorType( 81,
+        "Public key encryption not supported" );
+
+    /**
+     * Array for building a List of VALUES.
+     */
+    private static final ErrorType[] values =
+        { KDC_ERR_NONE, KDC_ERR_NAME_EXP, KDC_ERR_SERVICE_EXP, KDC_ERR_BAD_PVNO, KDC_ERR_C_OLD_MAST_KVNO,
+            KDC_ERR_S_OLD_MAST_KVNO, KDC_ERR_C_PRINCIPAL_UNKNOWN, KDC_ERR_S_PRINCIPAL_UNKNOWN,
+            KDC_ERR_PRINCIPAL_NOT_UNIQUE, KDC_ERR_NULL_KEY, KDC_ERR_CANNOT_POSTDATE, KDC_ERR_NEVER_VALID,
+            KDC_ERR_POLICY, KDC_ERR_BADOPTION, KDC_ERR_ETYPE_NOSUPP, KDC_ERR_SUMTYPE_NOSUPP,
+            KDC_ERR_PADATA_TYPE_NOSUPP, KDC_ERR_TRTYPE_NOSUPP, KDC_ERR_CLIENT_REVOKED, KDC_ERR_SERVICE_REVOKED,
+            KDC_ERR_TGT_REVOKED, KDC_ERR_CLIENT_NOTYET, KDC_ERR_SERVICE_NOTYET, KDC_ERR_KEY_EXPIRED,
+            KDC_ERR_PREAUTH_FAILED, KDC_ERR_PREAUTH_REQUIRED, KDC_ERR_SERVER_NOMATCH, KDC_ERR_MUST_USE_USER2USER,
+            KDC_ERR_PATH_NOT_ACCEPTED, KDC_ERR_SVC_UNAVAILABLE, KRB_AP_ERR_BAD_INTEGRITY, KRB_AP_ERR_TKT_EXPIRED,
+            KRB_AP_ERR_TKT_NYV, KRB_AP_ERR_REPEAT, KRB_AP_ERR_NOT_US, KRB_AP_ERR_BADMATCH, KRB_AP_ERR_SKEW,
+            KRB_AP_ERR_BADADDR, KRB_AP_ERR_BADVERSION, KRB_AP_ERR_MSG_TYPE, KRB_AP_ERR_MODIFIED, KRB_AP_ERR_BADORDER,
+            KRB_AP_ERR_BADKEYVER, KRB_AP_ERR_NOKEY, KRB_AP_ERR_MUT_FAIL, KRB_AP_ERR_BADDIRECTION, KRB_AP_ERR_METHOD,
+            KRB_AP_ERR_BADSEQ, KRB_AP_ERR_INAPP_CKSUM, KRB_AP_PATH_NOT_ACCEPTED, KRB_ERR_RESPONSE_TOO_BIG,
+            KRB_ERR_GENERIC, KRB_ERR_FIELD_TOOLONG, KDC_ERR_CLIENT_NOT_TRUSTED, KRB_ERR_KDC_NOT_TRUSTED,
+            KDC_ERR_INVALID_SIG, KDC_ERR_DH_KEY_PARAMETERS_NOT_ACCEPTED, KRB_ERR_CERTIFICATE_MISMATCH,
+            KRB_AP_ERR_NO_TGT, KRB_ERR_WRONG_REALM, KRB_AP_ERR_USER_TO_USER_REQUIRED, KDC_ERR_CANT_VERIFY_CERTIFICATE,
+            KDC_ERR_INVALID_CERTIFICATE, KDC_ERR_REVOKED_CERTIFICATE, KDC_ERR_REVOCATION_STATUS_UNKNOWN,
+            KRB_ERR_REVOCATION_STATUS_UNAVAILABLE, KDC_ERR_CLIENT_NAME_MISMATCH, KRB_ERR_KDC_NAME_MISMATCH,
+            KDC_ERR_INCONSISTENT_KEY_PURPOSE, KDC_ERR_DIGEST_IN_CERT_NOT_ACCEPTED,
+            KDC_ERR_PA_CHECKSUM_MUST_BE_INCLUDED, KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTED,
+            KDC_ERR_PUBLIC_KEY_ENCRYPTION_NOT_SUPPORTED };
+
+    /**
+     * A List of all the error type constants.
+     */
+    public static final List<ErrorType> VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
+
+    /**
+     * The name of the error type.
+     */
+    private final String name;
+
+    /**
+     * The value/code for the error type.
+     */
+    private final int ordinal;
+
+
+    /**
+     * Private constructor prevents construction outside of this class.
+     */
+    private ErrorType( int ordinal, String name )
+    {
+        this.ordinal = ordinal;
+        this.name = name;
+    }
+
+
+    /**
+     * Returns the message for this Kerberos error.
+     *
+     * @return the message for this Kerberos error.
+     */
+    public String getMessage()
+    {
+        return name;
+    }
+
+
+    /**
+     * Returns the message for this Kerberos error.
+     *
+     * @return the message for this Kerberos error.
+     */
+    public String toString()
+    {
+        return name;
+    }
+
+
+    /**
+     * Compares this type to another object hopefully one that is of the same
+     * type.
+     *
+     * @param that the object to compare this KerberosError to
+     * @return ordinal - ( ( KerberosError ) that ).ordinal;
+     */
+    public int compareTo( ErrorType that )
+    {
+        return ordinal - that.ordinal;
+    }
+
+
+    /**
+     * Gets the ordinal by its ordinal value.
+     *
+     * @param ordinal the ordinal value of the ordinal
+     * @return the type corresponding to the ordinal value
+     */
+    public static ErrorType getTypeByOrdinal( int ordinal )
+    {
+        for ( int ii = 0; ii < values.length; ii++ )
+        {
+            if ( values[ii].ordinal == ordinal )
+            {
+                return values[ii];
+            }
+        }
+
+        return KRB_ERR_GENERIC;
+    }
+
+
+    /**
+     * Gets the ordinal value associated with this Kerberos error.
+     *
+     * @return the ordinal value associated with this Kerberos error
+     */
+    public int getOrdinal()
+    {
+        return ordinal;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/exceptions/InvalidTicketException.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/exceptions/InvalidTicketException.java?rev=1031354&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/exceptions/InvalidTicketException.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/exceptions/InvalidTicketException.java Thu Nov  4 23:48:49 2010
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.exceptions;
+
+
+/**
+ * A exception used when there was an error while creating a Ticket
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */ 
+public class InvalidTicketException extends KerberosException
+{
+    static final long serialVersionUID = 1L;
+
+
+    public InvalidTicketException( ErrorType errorType )
+    {
+        super( errorType );
+    }
+
+
+    public InvalidTicketException( ErrorType errorType, String explanation )
+    {
+        super( errorType, explanation );
+    }
+
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/exceptions/KerberosException.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/exceptions/KerberosException.java?rev=1031354&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/exceptions/KerberosException.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/exceptions/KerberosException.java Thu Nov  4 23:48:49 2010
@@ -0,0 +1,220 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.exceptions;
+
+
+/**
+ * The root of the Kerberos exception hierarchy.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KerberosException extends Exception
+{
+    private static final long serialVersionUID = 2968072183596955597L;
+
+    /**
+     * The Kerberos error code associated with this exception.
+     */
+    private final int errorCode;
+
+    /**
+     * Additional data about the error for use by the application
+     * to help it recover from or handle the error.
+     */
+    private byte[] explanatoryData;
+
+
+    /**
+     * Creates a KerberosException with an {@link ErrorType}.
+     *
+     * @param errorType The error type associated with this KerberosException.
+     */
+    public KerberosException( ErrorType errorType )
+    {
+        super( errorType.getMessage() );
+
+        this.errorCode = errorType.getOrdinal();
+    }
+
+
+    /**
+     * Creates a KerberosException with an {@link ErrorType} and an
+     * underlying {@link Throwable} that caused this fault.
+     *
+     * @param errorType The error type associated with this KerberosException.
+     * @param cause The underlying failure, if any.
+     */
+    public KerberosException( ErrorType errorType, Throwable cause )
+    {
+        super( errorType.getMessage(), cause );
+
+        this.errorCode = errorType.getOrdinal();
+    }
+
+
+    /**
+     * Creates a KerberosException with an {@link ErrorType} and a custom error message.
+     *
+     * @param errorType The {@link ErrorType} associated with this KerberosException.
+     * @param msg A custom error message for this KerberosException.
+     */
+    public KerberosException( ErrorType errorType, String msg )
+    {
+        super( msg );
+
+        this.errorCode = errorType.getOrdinal();
+    }
+
+
+    /**
+     * Creates a KerberosException with an {@link ErrorType}, a custom error message, and an
+     * underlying {@link Throwable} that caused this fault.
+     *
+     * @param errorType The error type associated with this KerberosException.
+     * @param msg A custom error message for this KerberosException.
+     * @param cause The underlying failure, if any.
+     */
+    public KerberosException( ErrorType errorType, String msg, Throwable cause )
+    {
+        super( msg, cause );
+
+        this.errorCode = errorType.getOrdinal();
+    }
+
+
+    /**
+     * Creates a KerberosException with an {@link ErrorType} and data helping to
+     * explain what caused this fault.
+     *
+     * @param errorType The error type associated with this KerberosException.
+     * @param explanatoryData Data helping to explain this fault, if any.
+     */
+    public KerberosException( ErrorType errorType, byte[] explanatoryData )
+    {
+        super( errorType.getMessage() );
+
+        this.errorCode = errorType.getOrdinal();
+        this.explanatoryData = explanatoryData;
+    }
+
+
+    /**
+     * Creates a KerberosException with an {@link ErrorType}, data helping to
+     * explain what caused this fault, and an underlying {@link Throwable} that caused this fault.
+     *
+     * @param errorType The error type associated with this KerberosException.
+     * @param explanatoryData Data helping to explain this fault, if any.
+     * @param cause The underlying failure, if any.
+     */
+    public KerberosException( ErrorType errorType, byte[] explanatoryData, Throwable cause )
+    {
+        super( errorType.getMessage(), cause );
+
+        this.errorCode = errorType.getOrdinal();
+        this.explanatoryData = explanatoryData;
+    }
+
+
+    /**
+     * Gets the protocol error code associated with this KerberosException.
+     *
+     * @return The error code associated with this KerberosException.
+     */
+    public int getErrorCode()
+    {
+        return this.errorCode;
+    }
+
+
+    /**
+     * Gets the explanatory data associated with this KerberosException.
+     *
+     * @return The explanatory data associated with this KerberosException.
+     */
+    public byte[] getExplanatoryData()
+    {
+        return explanatoryData;
+    }
+
+
+    /**
+     * Creates a KerberosException with an error code and a message.
+     *
+     * @param errorCode The error code associated with this KerberosException.
+     * @param msg The standard Kerberos error message for this KerberosException.
+     */
+    protected KerberosException( int errorCode, String msg )
+    {
+        super( msg );
+
+        this.errorCode = errorCode;
+    }
+
+
+    /**
+     * Creates a KerberosException with an error code, a message and an
+     * underlying {@link Throwable} that caused this fault.
+     *
+     * @param errorCode The error code associated with this KerberosException.
+     * @param msg The standard Kerberos error message for this KerberosException.
+     * @param cause The underlying failure, if any.
+     */
+    protected KerberosException( int errorCode, String msg, Throwable cause )
+    {
+        super( msg, cause );
+
+        this.errorCode = errorCode;
+    }
+
+
+    /**
+     * Creates a KerberosException with an error code, a message, and data
+     * helping to explain what caused this fault.
+     *
+     * @param errorCode The error code associated with this KerberosException.
+     * @param msg The standard Kerberos error message for this KerberosException.
+     * @param explanatoryData Data helping to explain this fault, if any.
+     */
+    protected KerberosException( int errorCode, String msg, byte[] explanatoryData )
+    {
+        super( msg );
+
+        this.errorCode = errorCode;
+        this.explanatoryData = explanatoryData;
+    }
+
+
+    /**
+     * Creates a KerberosException with an error code, a message, and data
+     * helping to explain what caused this fault.
+     *
+     * @param errorCode The error code associated with this KerberosException.
+     * @param msg The standard Kerberos error message for this KerberosException.
+     * @param explanatoryData Data helping to explain this fault, if any.
+     * @param cause The underlying failure, if any.
+     */
+    protected KerberosException( int errorCode, String msg, byte[] explanatoryData, Throwable cause )
+    {
+        super( msg, cause );
+
+        this.errorCode = errorCode;
+        this.explanatoryData = explanatoryData;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KerberosMessage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KerberosMessage.java?rev=1031354&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KerberosMessage.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KerberosMessage.java Thu Nov  4 23:48:49 2010
@@ -0,0 +1,108 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.messages;
+
+import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.KerberosMessageType;
+
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KerberosMessage
+{
+    /** The Kerberos protocol version number (5). */
+    public static final int PVNO = KerberosConstants.KERBEROS_V5;
+
+    /** The protocol version (should be 5) */
+    private int protocolVersionNumber = PVNO;
+    
+    /** The message type */
+    private KerberosMessageType messageType;
+
+
+    /**
+     * Creates a new instance of KerberosMessage.
+     *
+     * @param type The message type
+     */
+    public KerberosMessage( KerberosMessageType type )
+    {
+        this( PVNO, type );
+    }
+
+
+    /**
+     * Creates a new instance of KerberosMessage.
+     *
+     * @param versionNumber
+     * @param type
+     */
+    public KerberosMessage( int versionNumber, KerberosMessageType type )
+    {
+        protocolVersionNumber = versionNumber;
+        messageType = type;
+    }
+
+
+    /**
+     * Returns the {@link org.apache.directory.server.kerberos.shared.KerberosMessageType}.
+     *
+     * @return The {@link org.apache.directory.server.kerberos.shared.KerberosMessageType}.
+     */
+    public KerberosMessageType getMessageType()
+    {
+        return messageType;
+    }
+
+
+    /**
+     * Sets the {@link org.apache.directory.server.kerberos.shared.KerberosMessageType}.
+     *
+     * @param type
+     */
+    public void setMessageType( KerberosMessageType type )
+    {
+        messageType = type;
+    }
+
+
+    /**
+     * Returns the protocol version number.
+     *
+     * @return The protocol version number.
+     */
+    public int getProtocolVersionNumber()
+    {
+        return protocolVersionNumber;
+    }
+
+
+    /**
+     * Sets the protocol version number.
+     *
+     * @param versionNumber
+     */
+    public void setProtocolVersionNumber( int versionNumber )
+    {
+        protocolVersionNumber = versionNumber;
+    }
+}



Mime
View raw message