directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1039312 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/ main/java/org/apache/directory/shared/kerberos/codec/krbCred/ main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/ ...
Date Fri, 26 Nov 2010 11:16:34 GMT
Author: kayyagari
Date: Fri Nov 26 11:16:33 2010
New Revision: 1039312

URL: http://svn.apache.org/viewvc?rev=1039312&view=rev
Log:
o implementation of KrbCred codec and tests

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/CheckMsgType.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/KrbCredInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StoreEncPart.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StorePvno.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StoreTickets.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbCred.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbCredDecoderTest.java
Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java?rev=1039312&r1=1039311&r2=1039312&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
Fri Nov 26 11:16:33 2010
@@ -128,6 +128,13 @@ public class KerberosConstants
     public static final int KRB_ERR_ETEXT_TAG = 0xAB;
     public static final int KRB_ERR_EDATA_TAG = 0xAC;
 
+    /** KRB-CRED tags */
+    public static final int KRB_CRED_TAG = 0x76;
+    public static final int KRB_CRED_PVNO_TAG = 0xA0;
+    public static final int KRB_CRED_MSGTYPE_TAG = 0xA1;
+    public static final int KRB_CRED_TICKETS_TAG = 0xA2;
+    public static final int KRB_CRED_ENCPART_TAG = 0xA3;
+    
     //-------------------------------------------------------------------------
     // Components
     //-------------------------------------------------------------------------

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredContainer.java?rev=1039312&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredContainer.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredContainer.java
Fri Nov 26 11:16:33 2010
@@ -0,0 +1,67 @@
+/*
+ *  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.krbCred;
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.messages.KrbCred;
+
+
+/**
+ * The KrbCred container stores the KrbCred decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbCredContainer extends AbstractContainer
+{
+    /** An KrbCred container */
+    private KrbCred krbCred;
+    
+    /**
+     * Creates a new KrbErrorContainer object.
+     */
+    public KrbCredContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = KrbCredGrammar.getInstance();
+        setTransition( KrbCredStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the KrbCred.
+     */
+    public KrbCred getKrbCred()
+    {
+        return krbCred;
+    }
+
+    
+    /**
+     * Set a KrbCred Object into the container. It will be completed by the
+     * KerberosDecoder.
+     * 
+     * @param krbCred The KrbCred to set.
+     */
+    public void setKrbCred( KrbCred krbCred )
+    {
+        this.krbCred = krbCred;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredGrammar.java?rev=1039312&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredGrammar.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredGrammar.java
Fri Nov 26 11:16:33 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.krbCred;
+
+
+import org.apache.directory.shared.asn1.ber.grammar.AbstractGrammar;
+import org.apache.directory.shared.asn1.ber.grammar.Grammar;
+import org.apache.directory.shared.asn1.ber.grammar.GrammarTransition;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.codec.actions.CheckNotNullLength;
+import org.apache.directory.shared.kerberos.codec.krbCred.actions.CheckMsgType;
+import org.apache.directory.shared.kerberos.codec.krbCred.actions.KrbCredInit;
+import org.apache.directory.shared.kerberos.codec.krbCred.actions.StoreEncPart;
+import org.apache.directory.shared.kerberos.codec.krbCred.actions.StorePvno;
+import org.apache.directory.shared.kerberos.codec.krbCred.actions.StoreTickets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class implements the KrbCred structure. All the actions are declared
+ * in this class. As it is a singleton, these declaration are only done once. If
+ * an action is to be added or modified, this is where the work is to be done !
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class KrbCredGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( KrbCredGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. KrbCredCredGrammar is a singleton */
+    private static Grammar instance = new KrbCredGrammar();
+
+
+    /**
+     * Creates a new KrbCredGrammar object.
+     */
+    private KrbCredGrammar()
+    {
+        setName( KrbCredGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[KrbCredStatesEnum.LAST_KRB_CRED_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // KrbCred
+        // ============================================================================================
+        
+        super.transitions[KrbCredStatesEnum.START_STATE.ordinal()][KerberosConstants.KRB_CRED_TAG]
= new GrammarTransition(
+            KrbCredStatesEnum.START_STATE, KrbCredStatesEnum.KRB_CRED_TAG_STATE, KerberosConstants.KRB_CRED_TAG,
+            new KrbCredInit());
+        
+        super.transitions[KrbCredStatesEnum.KRB_CRED_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            KrbCredStatesEnum.KRB_CRED_TAG_STATE, KrbCredStatesEnum.KRB_CRED_SEQ_TAG_STATE,
UniversalTag.SEQUENCE.getValue(),
+            new CheckNotNullLength());
+        
+        super.transitions[KrbCredStatesEnum.KRB_CRED_SEQ_TAG_STATE.ordinal()][KerberosConstants.KRB_CRED_PVNO_TAG]
= new GrammarTransition(
+            KrbCredStatesEnum.KRB_CRED_SEQ_TAG_STATE, KrbCredStatesEnum.KRB_CRED_PVNO_TAG_STATE,
KerberosConstants.KRB_CRED_PVNO_TAG,
+            new CheckNotNullLength());
+        
+        super.transitions[KrbCredStatesEnum.KRB_CRED_PVNO_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
+            KrbCredStatesEnum.KRB_CRED_PVNO_TAG_STATE, KrbCredStatesEnum.KRB_CRED_PVNO_STATE,
UniversalTag.INTEGER.getValue(),
+            new StorePvno());
+        
+        super.transitions[KrbCredStatesEnum.KRB_CRED_PVNO_STATE.ordinal()][KerberosConstants.KRB_CRED_MSGTYPE_TAG]
= new GrammarTransition(
+            KrbCredStatesEnum.KRB_CRED_PVNO_STATE, KrbCredStatesEnum.KRB_CRED_MSGTYPE_TAG_STATE,
KerberosConstants.KRB_CRED_MSGTYPE_TAG,
+            new CheckNotNullLength());
+        
+        super.transitions[KrbCredStatesEnum.KRB_CRED_MSGTYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
+            KrbCredStatesEnum.KRB_CRED_MSGTYPE_TAG_STATE, KrbCredStatesEnum.KRB_CRED_MSGTYPE_STATE,
UniversalTag.INTEGER.getValue(),
+            new CheckMsgType());
+        
+        super.transitions[KrbCredStatesEnum.KRB_CRED_MSGTYPE_STATE.ordinal()][KerberosConstants.KRB_CRED_TICKETS_TAG]
= new GrammarTransition(
+            KrbCredStatesEnum.KRB_CRED_MSGTYPE_STATE, KrbCredStatesEnum.KRB_CRED_TICKETS_TAG_STATE,
KerberosConstants.KRB_CRED_TICKETS_TAG,
+            new CheckNotNullLength());
+        
+        super.transitions[KrbCredStatesEnum.KRB_CRED_TICKETS_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            KrbCredStatesEnum.KRB_CRED_TICKETS_TAG_STATE, KrbCredStatesEnum.KRB_CRED_TICKETS_STATE,
UniversalTag.SEQUENCE.getValue(),
+            new CheckNotNullLength());
+        
+        super.transitions[KrbCredStatesEnum.KRB_CRED_TICKETS_STATE.ordinal()][KerberosConstants.TICKET_TAG]
= new GrammarTransition(
+            KrbCredStatesEnum.KRB_CRED_TICKETS_STATE, KrbCredStatesEnum.KRB_CRED_TICKETS_STATE,
KerberosConstants.TICKET_TAG,
+            new StoreTickets());
+        
+        super.transitions[KrbCredStatesEnum.KRB_CRED_TICKETS_STATE.ordinal()][KerberosConstants.KRB_CRED_ENCPART_TAG]
= new GrammarTransition(
+            KrbCredStatesEnum.KRB_CRED_TICKETS_STATE, KrbCredStatesEnum.KRB_CRED_ENCPART_TAG_STATE,
KerberosConstants.KRB_CRED_ENCPART_TAG,
+            new StoreEncPart());
+    }
+
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the KrbCredInfo Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredStatesEnum.java?rev=1039312&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredStatesEnum.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/KrbCredStatesEnum.java
Fri Nov 26 11:16:33 2010
@@ -0,0 +1,118 @@
+/*
+ *  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.krbCred;
+
+
+import org.apache.directory.shared.asn1.ber.grammar.Grammar;
+import org.apache.directory.shared.asn1.ber.grammar.States;
+import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
+
+
+/**
+ * This class store the KrbCred grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum KrbCredStatesEnum implements States
+{
+    // Start
+    START_STATE,                    // 0
+    
+    // ----- KRB-ERROR component --------------------------------------
+    KRB_CRED_TAG_STATE,             // 1
+    
+    KRB_CRED_SEQ_TAG_STATE,         // 2
+    
+    KRB_CRED_PVNO_TAG_STATE,        // 3
+    KRB_CRED_PVNO_STATE,            // 4
+    
+    KRB_CRED_MSGTYPE_TAG_STATE,     // 5
+    KRB_CRED_MSGTYPE_STATE,         // 6
+
+    KRB_CRED_TICKETS_TAG_STATE,     // 7
+    KRB_CRED_TICKETS_STATE,         // 8
+    
+    KRB_CRED_ENCPART_TAG_STATE,     // 9
+
+    // End
+    LAST_KRB_CRED_STATE;            // 10
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "KRB_CRED_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar grammar )
+    {
+        if ( grammar instanceof KerberosMessageGrammar )
+        {
+            return "KRB_CRED_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 == LAST_KRB_CRED_STATE.ordinal() ) ? "LAST_KRB_CRED_STATE" : name()
);
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_KRB_CRED_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public KrbCredStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/CheckMsgType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/CheckMsgType.java?rev=1039312&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/CheckMsgType.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/CheckMsgType.java
Fri Nov 26 11:16:33 2010
@@ -0,0 +1,68 @@
+/*
+ *  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.krbCred.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.kerberos.KerberosMessageType;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadMsgType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to check the msg-type
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CheckMsgType extends AbstractReadMsgType
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( CheckMsgType.class );
+
+
+    /**
+     * Instantiates a new CheckMsgType action.
+     */
+    public CheckMsgType()
+    {
+        super( "KRB-CRED msg-type" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void verifyMsgType( KerberosMessageType krbMsgType, Asn1Container container
) throws DecoderException
+    {
+        // The message type must be the expected one
+        if ( krbMsgType != KerberosMessageType.KRB_CRED )
+        {
+            String msg = "The msg-type should be KRB-CRED";
+            LOG.error( I18n.err( I18n.ERR_04070, krbMsgType, msg ) );
+
+            // This will generate a PROTOCOL_ERROR
+            throw new DecoderException( msg );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/KrbCredInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/KrbCredInit.java?rev=1039312&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/KrbCredInit.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/KrbCredInit.java
Fri Nov 26 11:16:33 2010
@@ -0,0 +1,83 @@
+/*
+ *  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.krbCred.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.kerberos.codec.krbCred.KrbCredContainer;
+import org.apache.directory.shared.kerberos.messages.KrbCred;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the KrbCred object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbCredInit extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( KrbCredInit.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new KrbCredInit action.
+     */
+    public KrbCredInit()
+    {
+        super( "Creates a KrbCred instance" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        KrbCredContainer krbCredContainer = ( KrbCredContainer ) container;
+
+        TLV tlv = krbCredContainer.getCurrentTLV();
+
+        // The Length should not be null
+        if ( tlv.getLength() == 0 )
+        {
+            LOG.error( I18n.err( I18n.ERR_04066 ) );
+
+            // This will generate a PROTOCOL_ERROR
+            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+        }
+
+        KrbCred krbCred = new KrbCred();
+        krbCredContainer.setKrbCred( krbCred );
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "KrbCred created" );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StoreEncPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StoreEncPart.java?rev=1039312&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StoreEncPart.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StoreEncPart.java
Fri Nov 26 11:16:33 2010
@@ -0,0 +1,57 @@
+/*
+ *  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.krbCred.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadEncryptedPart;
+import org.apache.directory.shared.kerberos.codec.krbCred.KrbCredContainer;
+import org.apache.directory.shared.kerberos.components.EncryptedData;
+
+
+/**
+ * The action used to read the EncryptedData
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreEncPart extends AbstractReadEncryptedPart
+{
+
+    /**
+     * Instantiates a new StoreEncPart action.
+     */
+    public StoreEncPart()
+    {
+        super( "KRB-CRED enc-part" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setEncryptedData( EncryptedData encryptedData, Asn1Container container
)
+    {
+        KrbCredContainer krbCredContainer = ( KrbCredContainer ) container;
+        krbCredContainer.getKrbCred().setEncPart( encryptedData );
+
+        container.setGrammarEndAllowed( true );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StorePvno.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StorePvno.java?rev=1039312&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StorePvno.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StorePvno.java
Fri Nov 26 11:16:33 2010
@@ -0,0 +1,55 @@
+/*
+ *  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.krbCred.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadPvno;
+import org.apache.directory.shared.kerberos.codec.krbCred.KrbCredContainer;
+
+
+/**
+ * The action used to store the PVNO
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StorePvno extends AbstractReadPvno
+{
+
+    /**
+     * Instantiates a new StorePvno action.
+     */
+    public StorePvno()
+    {
+        super( "KRB-CRED pvno" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setPvno( int pvno, Asn1Container container )
+    {
+        KrbCredContainer krbCredContainer = ( KrbCredContainer ) container;
+        krbCredContainer.getKrbCred().setProtocolVersionNumber( pvno );
+    }
+
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StoreTickets.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StoreTickets.java?rev=1039312&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StoreTickets.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbCred/actions/StoreTickets.java
Fri Nov 26 11:16:33 2010
@@ -0,0 +1,103 @@
+/*
+ *   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.krbCred.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.kerberos.codec.krbCred.KrbCredContainer;
+import org.apache.directory.shared.kerberos.codec.ticket.TicketContainer;
+import org.apache.directory.shared.kerberos.messages.Ticket;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Store  tickets.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreTickets extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( StoreTickets.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        KrbCredContainer krbCredContainer = ( KrbCredContainer ) container;
+
+        TLV tlv = krbCredContainer.getCurrentTLV();
+
+        // The Length should not be null
+        if ( tlv.getLength() == 0 )
+        {
+            LOG.error( I18n.err( I18n.ERR_04066 ) );
+
+            // This will generate a PROTOCOL_ERROR
+            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+        }
+
+        // decoder for Ticket
+        Asn1Decoder decoder = new Asn1Decoder();
+
+        // Ticket container
+        TicketContainer ticketContainer = new TicketContainer();
+        ticketContainer.setStream( container.getStream() );
+
+        container.rewind();
+        
+        try
+        {
+            // decode Ticket
+            decoder.decode( container.getStream(), ticketContainer );
+        }
+        catch ( DecoderException e )
+        {
+            throw e;
+        }
+
+        Ticket ticket = ticketContainer.getTicket();
+        // add Ticket to the list of tickets
+        krbCredContainer.getKrbCred().addTicket( ticket );
+
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+        // Update the parent
+        container.updateParent();
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "Ticket : {}", ticket );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbCred.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbCred.java?rev=1039312&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbCred.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbCred.java
Fri Nov 26 11:16:33 2010
@@ -0,0 +1,275 @@
+/*
+ *   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 java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.server.i18n.I18n;
+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.KerberosConstants;
+import org.apache.directory.shared.kerberos.KerberosMessageType;
+import org.apache.directory.shared.kerberos.components.EncryptedData;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * KRB-CRED        ::= [APPLICATION 22] SEQUENCE {
+ *         pvno            [0] INTEGER (5),
+ *         msg-type        [1] INTEGER (22),
+ *         tickets         [2] SEQUENCE OF Ticket,
+ *         enc-part        [3] EncryptedData -- EncKrbCredPart
+ * }
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbCred extends KerberosMessage
+{
+    /** The logger */
+    private static final Logger log = LoggerFactory.getLogger( KrbCred.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+    /** list of tickets */
+    private List<Ticket> tickets;
+
+    /** encrypted part of the message */
+    private EncryptedData encPart;
+
+
+    private transient int pvnoLen;
+    private transient int msgTypeLen;
+    private transient int ticketsSeqLen;
+    private transient int ticketsLen;
+    private transient int encPartLen;
+    private transient int krbCredSeqLen;
+    private transient int krbCredLen;
+
+    /**
+     * Creates a new instance of KrbCred.
+     */
+    public KrbCred()
+    {
+        super( 5, KerberosMessageType.KRB_CRED );
+    }
+
+
+    /**
+     * Compute the KRB-CRED length
+     * <pre>
+     * KRB-CRED :
+     * 
+     * 0x76 L1 KRB-CRED APPLICATION[22]
+     *  |
+     *  +--> 0x30 L2 KRB-CRED sequence
+     *        |
+     *        +--> 0xA0 0x03 pvno tag
+     *        |     |
+     *        |     +--> 0x02 0x01 0x05 pvno (5)
+     *        |
+     *        +--> 0xA1 0x03 msg-type tag
+     *        |     |
+     *        |     +--> 0x02 0x01 0x16 msg-type (22)
+     *        |     
+     *        +--> 0xA2 L3 tickets tag
+     *        |     |
+     *        |     +--> 0x30 LL tickets seq tag
+     *        |           |
+     *        |           +--> 0x30 LL1 ticket (Ticket)
+     *        |           .         ...
+     *        |           +--> 0x30 LLn ticket (Ticket)
+     *        |
+     *        +--> 0xA3 L4 enc-part tag
+     *              |
+     *              +--> 0x30 L4-2 enc-part (EncryptedData)
+     */
+    @Override
+    public int computeLength()
+    {
+        pvnoLen = 1 + 1 + 1;
+        krbCredSeqLen = 1 + TLV.getNbBytes( pvnoLen ) + pvnoLen;
+
+        msgTypeLen = 1 + 1 + Value.getNbBytes( getMessageType().getValue() );
+        krbCredSeqLen += 1 + TLV.getNbBytes( msgTypeLen ) + msgTypeLen;
+
+        for ( Ticket t : tickets )
+        {
+            ticketsSeqLen += t.computeLength();
+        }
+
+        ticketsLen = 1 + TLV.getNbBytes( ticketsSeqLen ) + ticketsSeqLen;
+
+        krbCredSeqLen += 1 + TLV.getNbBytes( ticketsLen ) + ticketsLen;
+
+        encPartLen = encPart.computeLength();
+        krbCredSeqLen += 1 + TLV.getNbBytes( encPartLen ) + encPartLen;
+
+        krbCredLen = 1 + TLV.getNbBytes( krbCredSeqLen ) + krbCredSeqLen;
+
+        return 1 + TLV.getNbBytes( krbCredLen ) + krbCredLen;
+    }
+
+
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_148 ) );
+        }
+
+        try
+        {
+            // The KRB-CRED APPLICATION tag
+            buffer.put( ( byte ) KerberosConstants.KRB_CRED_TAG );
+            buffer.put( TLV.getBytes( krbCredLen ) );
+
+            // The KRB-CRED sequence
+            buffer.put( UniversalTag.SEQUENCE.getValue() );
+            buffer.put( TLV.getBytes( krbCredSeqLen ) );
+
+            // pvno tag and value
+            buffer.put( ( byte ) KerberosConstants.KRB_CRED_PVNO_TAG );
+            buffer.put( TLV.getBytes( pvnoLen ) );
+            Value.encode( buffer, getProtocolVersionNumber() );
+
+            // msg-type tag and value
+            buffer.put( ( byte ) KerberosConstants.KRB_CRED_MSGTYPE_TAG );
+            buffer.put( TLV.getBytes( msgTypeLen ) );
+            Value.encode( buffer, getMessageType().getValue() );
+
+            // tickets tag and value
+            buffer.put( ( byte ) KerberosConstants.KRB_CRED_TICKETS_TAG );
+            buffer.put( TLV.getBytes( ticketsLen ) );
+
+            buffer.put( UniversalTag.SEQUENCE.getValue() );
+            buffer.put( TLV.getBytes( ticketsSeqLen ) );
+
+            for ( Ticket t : tickets )
+            {
+                t.encode( buffer );
+            }
+
+            // enc-part tag and value
+            buffer.put( ( byte ) KerberosConstants.KRB_CRED_ENCPART_TAG );
+            buffer.put( TLV.getBytes( encPartLen ) );
+            encPart.encode( buffer );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            log.error( I18n.err( I18n.ERR_741_CANNOT_ENCODE_KRB_CRED, 1 + TLV.getNbBytes(
krbCredLen )
+                + krbCredLen, buffer.capacity() ) );
+            throw new EncoderException( I18n.err( I18n.ERR_138 ) );
+        }
+
+        if ( IS_DEBUG )
+        {
+            log.debug( "KrbCred encoding : {}", StringTools.dumpBytes( buffer.array() ) );
+            log.debug( "KrbCred initial value : {}", toString() );
+        }
+
+        return buffer;
+    }
+
+
+    /**
+     * @return the tickets
+     */
+    public List<Ticket> getTickets()
+    {
+        return tickets;
+    }
+
+
+    /**
+     * @param tickets the tickets to set
+     */
+    public void setTickets( List<Ticket> tickets )
+    {
+        this.tickets = tickets;
+    }
+
+
+    /**
+     * @return the encPart
+     */
+    public EncryptedData getEncPart()
+    {
+        return encPart;
+    }
+
+
+    /**
+     * @param encPart the encPart to set
+     */
+    public void setEncPart( EncryptedData encPart )
+    {
+        this.encPart = encPart;
+    }
+
+
+    /**
+     * adds a Ticket to the ticket list
+     * 
+     * @param ticket the Ticket to be added
+     */
+    public void addTicket( Ticket ticket )
+    {
+        if ( ticket == null )
+        {
+            throw new IllegalArgumentException( "null ticket cannot be added" );
+        }
+
+        if ( tickets == null )
+        {
+            tickets = new ArrayList<Ticket>();
+        }
+
+        tickets.add( ticket );
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( "KRB-CRED : {\n" );
+        sb.append( "    pvno: " ).append( getProtocolVersionNumber() ).append( '\n' );
+        sb.append( "    msg-type: " ).append( getMessageType() ).append( '\n' );
+        sb.append( "    tickets: " ).append( tickets ).append( '\n' );
+        sb.append( "    en-part: " ).append( encPart ).append( '\n' );
+
+        sb.append( "}\n" );
+
+        return sb.toString();
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbCredDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbCredDecoderTest.java?rev=1039312&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbCredDecoderTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbCredDecoderTest.java
Fri Nov 26 11:16:33 2010
@@ -0,0 +1,87 @@
+/*
+ *   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 java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.kerberos.codec.krbCred.KrbCredContainer;
+import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
+import org.apache.directory.shared.kerberos.codec.types.PrincipalNameType;
+import org.apache.directory.shared.kerberos.components.EncryptedData;
+import org.apache.directory.shared.kerberos.components.PrincipalName;
+import org.apache.directory.shared.kerberos.messages.KrbCred;
+import org.apache.directory.shared.kerberos.messages.Ticket;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Test cases for KrbCred codec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbCredDecoderTest
+{
+    @Test
+    public void testDecodeKrebCred() throws Exception
+    {
+        EncryptedData encPart = new EncryptedData( EncryptionType.DES3_CBC_MD5, 0, new byte[]{
0, 1 } );
+        PrincipalName pName = new PrincipalName( "pname", PrincipalNameType.KRB_NT_PRINCIPAL
);
+        
+        String realm = "ticketRealm";
+        Ticket t1 = new Ticket( pName, encPart );
+        t1.setRealm( realm );
+        
+        Ticket t2 = new Ticket( pName, encPart );
+        t2.setRealm( realm );
+        
+        List<Ticket> tickets = new ArrayList<Ticket>();
+        tickets.add( t1 );
+        tickets.add( t2 );
+        
+        KrbCred expected = new KrbCred();
+        expected.setTickets( tickets );
+        expected.setEncPart( encPart );
+        
+        int krbCredLen = expected.computeLength();
+        ByteBuffer stream = ByteBuffer.allocate( krbCredLen );
+        
+        expected.encode( stream );
+        stream.flip();
+        
+        KrbCredContainer container = new KrbCredContainer();
+        container.setStream( stream );
+        
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        decoder.decode( stream, container );
+        
+        KrbCred actual = container.getKrbCred();
+        
+        assertEquals( expected.getProtocolVersionNumber(), actual.getProtocolVersionNumber()
);
+        assertEquals( expected.getMessageType(), actual.getMessageType() );
+        assertEquals( expected.getTickets(), actual.getTickets() );
+        assertEquals( expected.getEncPart(), actual.getEncPart() );
+    }
+}



Mime
View raw message