directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1039167 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/ main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/ test/java/org/apache/directory/sha...
Date Thu, 25 Nov 2010 20:44:48 GMT
Author: kayyagari
Date: Thu Nov 25 20:44:47 2010
New Revision: 1039167

URL: http://svn.apache.org/viewvc?rev=1039167&view=rev
Log:
o implementation of EncKrbCredPart grammar and tests

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/EncKrbCredPartInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreNonce.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreRecipientAddress.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreSenderAddress.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreTicketInfo.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreTimestamp.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreUsec.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbCredPartDecoderTest.java

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartContainer.java?rev=1039167&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartContainer.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartContainer.java
Thu Nov 25 20:44:47 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.encKrbCredPart;
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.components.EncKrbCredPart;
+
+
+/**
+ * The EncKrbCredPart container stores the EncKrbCredPart decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncKrbCredPartContainer extends AbstractContainer
+{
+    /** An EncKrbCredPart container */
+    private EncKrbCredPart encKrbCredPart;
+    
+    /**
+     * Creates a new EncKrbCredPartContainer object.
+     */
+    public EncKrbCredPartContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = EncKrbCredPartGrammar.getInstance();
+        setTransition( EncKrbCredPartStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the EncKrbCredPart.
+     */
+    public EncKrbCredPart getEncKrbCredPart()
+    {
+        return encKrbCredPart;
+    }
+
+    
+    /**
+     * Set a EncKrbCredPart Object into the container. It will be completed by the
+     * KerberosDecoder.
+     * 
+     * @param encKrbCredPart The EncKrbCredPart to set.
+     */
+    public void setEncKrbCredPart( EncKrbCredPart encKrbCredPart )
+    {
+        this.encKrbCredPart = encKrbCredPart;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartGrammar.java?rev=1039167&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartGrammar.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartGrammar.java
Thu Nov 25 20:44:47 2010
@@ -0,0 +1,135 @@
+/*
+ *  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.encKrbCredPart;
+
+
+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.encKrbCredPart.actions.EncKrbCredPartInit;
+import org.apache.directory.shared.kerberos.codec.encKrbCredPart.actions.StoreNonce;
+import org.apache.directory.shared.kerberos.codec.encKrbCredPart.actions.StoreRecipientAddress;
+import org.apache.directory.shared.kerberos.codec.encKrbCredPart.actions.StoreSenderAddress;
+import org.apache.directory.shared.kerberos.codec.encKrbCredPart.actions.StoreTicketInfo;
+import org.apache.directory.shared.kerberos.codec.encKrbCredPart.actions.StoreTimestamp;
+import org.apache.directory.shared.kerberos.codec.encKrbCredPart.actions.StoreUsec;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the EncKrbCredPart 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 EncKrbCredPartGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( EncKrbCredPartGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. EncKrbCredPartGrammar is a singleton */
+    private static Grammar instance = new EncKrbCredPartGrammar();
+
+
+    /**
+     * Creates a new EncKrbCredPartGrammar object.
+     */
+    private EncKrbCredPartGrammar()
+    {
+        setName( EncKrbCredPartGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[EncKrbCredPartStatesEnum.LAST_ENC_KRB_CRED_PART_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // EncKrbCredPart 
+        // ============================================================================================
+        super.transitions[EncKrbCredPartStatesEnum.START_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.START_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_TAG,
+            new EncKrbCredPartInit());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TAG_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_SEQ_TAG_STATE,
UniversalTag.SEQUENCE.getValue(),
+            new CheckNotNullLength());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_SEQ_TAG_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_TICKET_INFO_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_SEQ_TAG_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_TICKET_INFO_TAG,
+            new CheckNotNullLength());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_TAG_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE,
UniversalTag.SEQUENCE.getValue(),
+            new CheckNotNullLength());
+
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE,
UniversalTag.SEQUENCE.getValue(),
+            new StoreTicketInfo());
+
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_NONCE_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_NONCE_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_NONCE_TAG,
+            new CheckNotNullLength());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_NONCE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_NONCE_TAG_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_NONCE_STATE,
UniversalTag.INTEGER.getValue(),
+            new StoreNonce());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_NONCE_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_TIMESTAMP_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_NONCE_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TIMESTAMP_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_TIMESTAMP_TAG,
+            new CheckNotNullLength());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TIMESTAMP_TAG_STATE.ordinal()][UniversalTag.GENERALIZED_TIME.getValue()]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TIMESTAMP_TAG_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TIMESTAMP_STATE,
UniversalTag.GENERALIZED_TIME.getValue(),
+            new StoreTimestamp());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TIMESTAMP_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_USEC_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TIMESTAMP_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_USEC_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_USEC_TAG,
+            new CheckNotNullLength());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_USEC_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_USEC_TAG_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_USEC_STATE,
UniversalTag.INTEGER.getValue(),
+            new StoreUsec());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_USEC_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_USEC_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG,
+            new StoreSenderAddress());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG,
+            new StoreRecipientAddress());
+    }
+
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the EncKrbCredPart Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartStatesEnum.java?rev=1039167&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartStatesEnum.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartStatesEnum.java
Thu Nov 25 20:44:47 2010
@@ -0,0 +1,123 @@
+/*
+ *  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.encKrbCredPart;
+
+
+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 stores the EncKrbCredPart grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum EncKrbCredPartStatesEnum implements States
+{
+    // Start
+    START_STATE, // 0
+
+    // ----- EncKrbPrivPart component --------------------------------------
+
+    ENC_KRB_CRED_PART_TAG_STATE, // 1
+
+    ENC_KRB_CRED_PART_SEQ_TAG_STATE, // 2
+
+    ENC_KRB_CRED_PART_TICKET_INFO_TAG_STATE, // 3
+    ENC_KRB_CRED_PART_TICKET_INFO_STATE, // 4
+    
+    ENC_KRB_CRED_PART_NONCE_TAG_STATE, // 5
+    ENC_KRB_CRED_PART_NONCE_STATE, // 6
+
+    ENC_KRB_CRED_PART_TIMESTAMP_TAG_STATE, // 7
+    ENC_KRB_CRED_PART_TIMESTAMP_STATE, // 8
+
+    ENC_KRB_CRED_PART_USEC_TAG_STATE, // 9
+    ENC_KRB_CRED_PART_USEC_STATE, // 10
+
+    ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG_STATE, // 11
+
+    ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG_STATE, // 12
+
+    // End
+    LAST_ENC_KRB_CRED_PART_STATE; // 13
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "ENC_KRB_CRED_PART_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar grammar )
+    {
+        if ( grammar instanceof KerberosMessageGrammar )
+        {
+            return "ENC_KRB_CRED_PART_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_ENC_KRB_CRED_PART_STATE.ordinal() ) ? "LAST_ENC_KRB_CRED_PART_STATE"
: name() );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_ENC_KRB_CRED_PART_STATE;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public EncKrbCredPartStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/EncKrbCredPartInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/EncKrbCredPartInit.java?rev=1039167&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/EncKrbCredPartInit.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/EncKrbCredPartInit.java
Thu Nov 25 20:44:47 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.encKrbCredPart.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.encKrbCredPart.EncKrbCredPartContainer;
+import org.apache.directory.shared.kerberos.components.EncKrbCredPart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the EncKrbCredPart object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncKrbCredPartInit extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( EncKrbCredPartInit.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new EncKrbCredPartInit action.
+     */
+    public EncKrbCredPartInit()
+    {
+        super( "Creates a EncKrbCredPart instance" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        EncKrbCredPartContainer encKrbCredPartContainer = ( EncKrbCredPartContainer ) container;
+
+        TLV tlv = encKrbCredPartContainer.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 ) );
+        }
+        
+        EncKrbCredPart encKrbCredPart = new EncKrbCredPart();
+        encKrbCredPartContainer.setEncKrbCredPart( encKrbCredPart );
+        
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "EncKrbCredPart created" );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreNonce.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreNonce.java?rev=1039167&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreNonce.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreNonce.java
Thu Nov 25 20:44:47 2010
@@ -0,0 +1,54 @@
+/*
+ *  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.encKrbCredPart.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadInteger;
+import org.apache.directory.shared.kerberos.codec.encKrbCredPart.EncKrbCredPartContainer;
+
+
+/**
+ * The action used to store the Nonce
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreNonce extends AbstractReadInteger
+{
+    /**
+     * Instantiates a new StoreNonce action.
+     */
+    public StoreNonce()
+    {
+        super( "EncKrbCredPart nonce" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setIntegerValue( int value, Asn1Container container )
+    {
+        EncKrbCredPartContainer encKrbCredPartContainer = ( EncKrbCredPartContainer ) container;
+        encKrbCredPartContainer.getEncKrbCredPart().setNonce( value );
+        
+        container.setGrammarEndAllowed( true );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreRecipientAddress.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreRecipientAddress.java?rev=1039167&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreRecipientAddress.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreRecipientAddress.java
Thu Nov 25 20:44:47 2010
@@ -0,0 +1,56 @@
+/*
+ *   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.encKrbCredPart.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadHostAddress;
+import org.apache.directory.shared.kerberos.codec.encKrbCredPart.EncKrbCredPartContainer;
+import org.apache.directory.shared.kerberos.components.HostAddress;
+
+
+/**
+ * Store the r-address of EncKrbCredPart.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreRecipientAddress extends AbstractReadHostAddress
+{
+
+    public StoreRecipientAddress()
+    {
+        super( "EncKrbCredPart r-address" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setAddress( HostAddress hostAddress, Asn1Container container )
+    {
+        EncKrbCredPartContainer encKrbCredPartContainer = ( EncKrbCredPartContainer ) container;
+        encKrbCredPartContainer.getEncKrbCredPart().setRecipientAddress( hostAddress );
+        
+        container.setGrammarEndAllowed( true );
+    }
+
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreSenderAddress.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreSenderAddress.java?rev=1039167&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreSenderAddress.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreSenderAddress.java
Thu Nov 25 20:44:47 2010
@@ -0,0 +1,56 @@
+/*
+ *   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.encKrbCredPart.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadHostAddress;
+import org.apache.directory.shared.kerberos.codec.encKrbCredPart.EncKrbCredPartContainer;
+import org.apache.directory.shared.kerberos.components.HostAddress;
+
+
+/**
+ * Store the s-address of EncKrbCredPart.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreSenderAddress extends AbstractReadHostAddress
+{
+
+    public StoreSenderAddress()
+    {
+        super( "EncKrbCredPart s-address" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setAddress( HostAddress hostAddress, Asn1Container container )
+    {
+        EncKrbCredPartContainer encKrbCredPartContainer = ( EncKrbCredPartContainer ) container;
+        encKrbCredPartContainer.getEncKrbCredPart().setSenderAddress( hostAddress );
+        
+        container.setGrammarEndAllowed( true );
+    }
+
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreTicketInfo.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreTicketInfo.java?rev=1039167&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreTicketInfo.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreTicketInfo.java
Thu Nov 25 20:44:47 2010
@@ -0,0 +1,105 @@
+/*
+ *   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.encKrbCredPart.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.encKrbCredPart.EncKrbCredPartContainer;
+import org.apache.directory.shared.kerberos.codec.krbCredInfo.KrbCredInfoContainer;
+import org.apache.directory.shared.kerberos.components.KrbCredInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Store EncKrbCredInfo ticket-info.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreTicketInfo extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( StoreTicketInfo.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        EncKrbCredPartContainer encKrbCredPartContainer = ( EncKrbCredPartContainer ) container;
+
+        TLV tlv = encKrbCredPartContainer.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 KrbCredInfo
+        Asn1Decoder decoder = new Asn1Decoder();
+
+        // KrbCredInfo container
+        KrbCredInfoContainer ticketInfoContainer = new KrbCredInfoContainer();
+        ticketInfoContainer.setStream( container.getStream() );
+
+        container.rewind();
+        
+        try
+        {
+            // decode KrbCredInfo
+            decoder.decode( container.getStream(), ticketInfoContainer );
+        }
+        catch ( DecoderException e )
+        {
+            throw e;
+        }
+
+        KrbCredInfo ticketInfo = ticketInfoContainer.getKrbCredInfo();
+        // add KrbCredInfo to the list of ticket-info
+        encKrbCredPartContainer.getEncKrbCredPart().addTicketInfo( ticketInfo );
+
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+        // Update the parent
+        container.updateParent();
+
+        container.setGrammarEndAllowed( true );
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "KrbCredInfo : {}", ticketInfo );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreTimestamp.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreTimestamp.java?rev=1039167&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreTimestamp.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreTimestamp.java
Thu Nov 25 20:44:47 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.encKrbCredPart.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.KerberosTime;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadKerberosTime;
+import org.apache.directory.shared.kerberos.codec.encKrbCredPart.EncKrbCredPartContainer;
+
+
+/**
+ * The action used to store the EncKrbCredPart timemstamp
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreTimestamp extends AbstractReadKerberosTime
+{
+
+    /**
+     * Instantiates a new StoreCTime action.
+     */
+    public StoreTimestamp()
+    {
+        super( "EncKrbCredPart timemstamp" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setKerberosTime( KerberosTime krbtime, Asn1Container container )
+    {
+        EncKrbCredPartContainer encKrbCredPartContainer = ( EncKrbCredPartContainer ) container;
+        encKrbCredPartContainer.getEncKrbCredPart().setTimestamp( krbtime );
+        
+        container.setGrammarEndAllowed( true );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreUsec.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreUsec.java?rev=1039167&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreUsec.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/actions/StoreUsec.java
Thu Nov 25 20:44:47 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.encKrbCredPart.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadInteger;
+import org.apache.directory.shared.kerberos.codec.encKrbCredPart.EncKrbCredPartContainer;
+
+
+/**
+ * The action used to store the EncKrbCredPart usec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreUsec extends AbstractReadInteger
+{
+
+    /**
+     * Instantiates a new StoreUsec action.
+     */
+    public StoreUsec()
+    {
+        super( "EncKrbCredPart usec" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setIntegerValue( int value, Asn1Container container )
+    {
+        EncKrbCredPartContainer encKrbCredPartContainer = ( EncKrbCredPartContainer ) container;
+        encKrbCredPartContainer.getEncKrbCredPart().setUsec( value );
+        
+        container.setGrammarEndAllowed( true );
+    }
+
+}

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbCredPartDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbCredPartDecoderTest.java?rev=1039167&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbCredPartDecoderTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbCredPartDecoderTest.java
Thu Nov 25 20:44:47 2010
@@ -0,0 +1,211 @@
+/*
+ *   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 static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.kerberos.KerberosTime;
+import org.apache.directory.shared.kerberos.codec.encKrbCredPart.EncKrbCredPartContainer;
+import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
+import org.apache.directory.shared.kerberos.components.EncKrbCredPart;
+import org.apache.directory.shared.kerberos.components.EncryptionKey;
+import org.apache.directory.shared.kerberos.components.HostAddress;
+import org.apache.directory.shared.kerberos.components.KrbCredInfo;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * test cases for EncKrbCredPart codec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncKrbCredPartDecoderTest
+{
+    private List<KrbCredInfo> ticketInfo;
+    private int nonce;
+    private KerberosTime timestamp;
+    private int usec;
+    private HostAddress senderAddress;
+    private HostAddress recipientAddress;
+
+    private List<FieldValueHolder> optionalFieldValueList;
+
+    class FieldValueHolder
+    {
+        String fieldName;
+        Object value;
+
+
+        FieldValueHolder( String fieldName, Object value )
+        {
+            this.fieldName = fieldName;
+            this.value = value;
+        }
+
+
+        @Override
+        public String toString()
+        {
+            return "FieldValueHolder [fieldName=" + fieldName + ", value=" + value + "]";
+        }
+    }
+
+
+    @Before
+    public void setup() throws Exception
+    {
+        optionalFieldValueList = new ArrayList<FieldValueHolder>();
+
+        ticketInfo = new ArrayList<KrbCredInfo>();
+        KrbCredInfo info1 = new KrbCredInfo();
+        info1.setKey( new EncryptionKey( EncryptionType.DES3_CBC_MD5, new byte[]
+            { 0, 1 } ) );
+        ticketInfo.add( info1 );
+
+        KrbCredInfo info2 = new KrbCredInfo();
+        info2.setKey( new EncryptionKey( EncryptionType.AES128_CTS_HMAC_SHA1_96, new byte[]
+            { 2, 3 } ) );
+        ticketInfo.add( info2 );
+
+        nonce = 100;
+        optionalFieldValueList.add( new FieldValueHolder( "nonce", nonce ) );
+
+        timestamp = new KerberosTime( new Date().getTime() );
+        optionalFieldValueList.add( new FieldValueHolder( "timestamp", timestamp ) );
+
+        usec = 1;
+        optionalFieldValueList.add( new FieldValueHolder( "usec", usec ) );
+
+        senderAddress = new HostAddress( InetAddress.getByName( "localhost" ) );
+        optionalFieldValueList.add( new FieldValueHolder( "senderAddress", senderAddress
) );
+
+        recipientAddress = new HostAddress( InetAddress.getByName( "localhost" ) );
+        optionalFieldValueList.add( new FieldValueHolder( "recipientAddress", recipientAddress
) );
+    }
+    
+    
+    @Test
+    public void testEncKrbCredPart() throws Exception
+    {
+        int size = optionalFieldValueList.size();
+        for ( int i = 0; i < 1; i++ ) // FIXME i < 1 should be changed to i < size
after adding optional transitions
+        {
+            EncKrbCredPart expected = new EncKrbCredPart();
+            expected.setTicketInfo( ticketInfo );
+            
+            Map<String, Field> EncKrbCrePartFieldNameMap = getFieldMap( expected );
+
+            List<FieldValueHolder> presentFieldList = new ArrayList<FieldValueHolder>();
+
+            FieldValueHolder fieldValHolder = optionalFieldValueList.get( i );
+            presentFieldList.add( fieldValHolder );
+
+            Field f = EncKrbCrePartFieldNameMap.get( fieldValHolder.fieldName.toLowerCase()
);
+            f.set( expected, fieldValHolder.value );
+
+            for ( int j = i + 1; j < size; j++ )
+            {
+                fieldValHolder = optionalFieldValueList.get( j );
+                presentFieldList.add( fieldValHolder );
+                f = EncKrbCrePartFieldNameMap.get( fieldValHolder.fieldName.toLowerCase()
);
+                f.set( expected, fieldValHolder.value );
+            }
+
+            ByteBuffer stream = ByteBuffer.allocate( expected.computeLength() );
+            expected.encode( stream );
+            stream.flip();
+
+            Asn1Decoder decoder = new Asn1Decoder();
+            EncKrbCredPartContainer container = new EncKrbCredPartContainer();
+            container.setStream( stream );
+
+            try
+            {
+                decoder.decode( stream, container );
+            }
+            catch ( DecoderException e )
+            {
+                // NOTE: keep this sysout for easy debugging (no need to setup a logger)
+                System.out.println( "failed sequence:\n" + expected );
+                throw e;
+            }
+
+            EncKrbCredPart actual = container.getEncKrbCredPart();
+            assertValues( presentFieldList, actual );
+        }
+    }
+    
+    /**
+     * compare the values that are inserted into the EncKrbCredPart objects before encoding
to
+     * those that are obtained from decoded EncKrbCredPart
+     * 
+     * @param presentFieldList the list of values that were inserted in the EncKrbCredPart
class before encoding
+     * @param decoded the decoded EncKrbCredPart object 
+     */
+    private void assertValues( List<FieldValueHolder> presentFieldList, EncKrbCredPart
decoded ) throws Exception
+    {
+        Map<String, Field> fieldNameMap = getFieldMap( decoded );
+        for ( FieldValueHolder fh : presentFieldList )
+        {
+            Field actualField = fieldNameMap.get( fh.fieldName.toLowerCase() );
+            Object decodedValue = actualField.get( decoded );
+
+            //System.out.println( fh.fieldName + " expected: " + fh.value + " , actual: "
+ decodedValue );
+
+            assertTrue( decodedValue.equals( fh.value ) );
+        }
+    }
+
+
+    /**
+     * create a map with the field's name and field objects of the KrbCreInfo
+     * 
+     * @param source the EncKrbCredPart object
+     */
+    private Map<String, Field> getFieldMap( EncKrbCredPart source )
+    {
+        Field[] fields = source.getClass().getDeclaredFields();
+
+        Map<String, Field> fieldNameMap = new HashMap<String, Field>();
+
+        for ( Field f : fields )
+        {
+            f.setAccessible( true );
+            fieldNameMap.put( f.getName().toLowerCase(), f );
+        }
+
+        return fieldNameMap;
+    }
+
+}



Mime
View raw message