directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1035433 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/kdcReq/ main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/ main/java/org/apache/directory/shared/kerberos/cod...
Date Mon, 15 Nov 2010 20:34:09 GMT
Author: elecharny
Date: Mon Nov 15 20:34:08 2010
New Revision: 1035433

URL: http://svn.apache.org/viewvc?rev=1035433&view=rev
Log:
o Completed the KdcReq grammmar
o Fixed some errors

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/AddPaData.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/StoreKdcReqBody.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java
Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/AddTicket.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreAddresses.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreCName.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreEncAuthorizationData.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreSName.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketSName.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqGrammar.java?rev=1035433&r1=1035432&r2=1035433&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqGrammar.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqGrammar.java
Mon Nov 15 20:34:08 2010
@@ -26,7 +26,9 @@ import org.apache.directory.shared.asn1.
 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.kdcReq.actions.AddPaData;
 import org.apache.directory.shared.kerberos.codec.kdcReq.actions.KdcReqInit;
+import org.apache.directory.shared.kerberos.codec.kdcReq.actions.StoreKdcReqBody;
 import org.apache.directory.shared.kerberos.codec.kdcReq.actions.StoreMsgType;
 import org.apache.directory.shared.kerberos.codec.kdcReq.actions.StorePvno;
 import org.slf4j.Logger;
@@ -112,7 +114,7 @@ public final class KdcReqGrammar extends
             new StoreMsgType() );
         
         // --------------------------------------------------------------------------------------------
-        // Transition from msg-type value tp padata tag
+        // Transition from msg-type value to padata tag
         // --------------------------------------------------------------------------------------------
         // KDC-REQ         ::= SEQUENCE {
         //         ...
@@ -121,9 +123,55 @@ public final class KdcReqGrammar extends
             KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE, KdcReqStatesEnum.KDC_REQ_PA_DATA_TAG_STATE,
KerberosConstants.KDC_REQ_PA_DATA_TAG,
             new CheckNotNullLength() );
         
+        // --------------------------------------------------------------------------------------------
+        // Transition from msg-type value to KDC-REQ-BODY tag (pa-data is missing)
+        // --------------------------------------------------------------------------------------------
+        // KDC-REQ         ::= SEQUENCE {
+        //         ...
+        //         req-body        [4]
+        super.transitions[KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE.ordinal()][KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG]
= new GrammarTransition(
+            KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE, KdcReqStatesEnum.KDC_REQ_KDC_REQ_BODY_STATE,
KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG,
+            new CheckNotNullLength() );
         
+        // --------------------------------------------------------------------------------------------
+        // Transition from padata tag to pa-data SEQ
+        // --------------------------------------------------------------------------------------------
+        // KDC-REQ         ::= SEQUENCE {
+        //         ...
+        //         padata          [3] SEQUENCE OF
+        super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            KdcReqStatesEnum.KDC_REQ_PA_DATA_TAG_STATE, KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE,
UniversalTag.SEQUENCE.getValue(),
+            new CheckNotNullLength() );
         
+        // --------------------------------------------------------------------------------------------
+        // Transition from pa-data SEQ to pa-data
+        // --------------------------------------------------------------------------------------------
+        // KDC-REQ         ::= SEQUENCE {
+        //         ...
+        //         padata          [3] SEQUENCE OF <PA-DATA>
+        super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE, KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE,
UniversalTag.SEQUENCE.getValue(),
+            new AddPaData() );
         
+        // --------------------------------------------------------------------------------------------
+        // Transition from pa-data to KDC-REQ-BODY tag
+        // --------------------------------------------------------------------------------------------
+        // KDC-REQ         ::= SEQUENCE {
+        //         ...
+        //         req-body        [4]
+        super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE.ordinal()][KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG]
= new GrammarTransition(
+            KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE, KdcReqStatesEnum.KDC_REQ_KDC_REQ_BODY_STATE,
KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG,
+            new StoreKdcReqBody() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from KDC-REQ-BODY tag to KDC-REQ-BODY value
+        // --------------------------------------------------------------------------------------------
+        // KDC-REQ         ::= SEQUENCE {
+        //         ...
+        //         req-body        [4] KDC-REQ-BODY
+        super.transitions[KdcReqStatesEnum.KDC_REQ_KDC_REQ_BODY_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            KdcReqStatesEnum.KDC_REQ_KDC_REQ_BODY_STATE, KdcReqStatesEnum.LAST_KDC_REQ_STATE,
UniversalTag.SEQUENCE.getValue(),
+            new StoreKdcReqBody() );
     }
 
     /**

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/AddPaData.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/AddPaData.java?rev=1035433&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/AddPaData.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/AddPaData.java
Mon Nov 15 20:34:08 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.kdcReq.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.kdcReq.KdcReqContainer;
+import org.apache.directory.shared.kerberos.codec.padata.PaDataContainer;
+import org.apache.directory.shared.kerberos.components.KdcReq;
+import org.apache.directory.shared.kerberos.components.PaData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to add a PaData
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AddPaData extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( AddPaData.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /**
+     * Instantiates a new AddPaData action.
+     */
+    public AddPaData()
+    {
+        super( "KDC-REQ Add PA-DATA" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        KdcReqContainer kdcReqContainer = ( KdcReqContainer ) container;
+
+        TLV tlv = kdcReqContainer.getCurrentTLV();
+
+        // The Length can't 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 ) );
+        }
+
+        // Now, let's decode the PA-DATA
+        Asn1Decoder paDataDecoder = new Asn1Decoder();
+        
+        PaDataContainer paDataContainer = new PaDataContainer();
+        paDataContainer.setStream( container.getStream() );
+
+        // Compute the start position in the stream for the PA-DATA to decode : 
+        // We have to move back to the PA-DATA tag
+        int start = container.getStream().position() - 1 - tlv.getLengthNbBytes();
+        container.getStream().position( start );
+
+        // Decode the PA-DATA PDU
+        try
+        {
+            paDataDecoder.decode( container.getStream(), paDataContainer );
+        }
+        catch ( DecoderException de )
+        {
+            throw de;
+        }
+        
+        // Update the parent
+        TLV parentTlv = tlv.getParent();
+        
+        while ( ( parentTlv != null ) && ( parentTlv.getExpectedLength() == 0 ) )
+        {
+            parentTlv = parentTlv.getParent();
+        }
+        
+        container.setParentTLV( parentTlv );
+
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+        // Store the PData in the container
+        PaData paData = paDataContainer.getPaData();
+        KdcReq kdcReq = kdcReqContainer.getKdcReq();
+        kdcReq.addPaData( paData );
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "Added PA-DATA:  {}", paData );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/StoreKdcReqBody.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/StoreKdcReqBody.java?rev=1035433&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/StoreKdcReqBody.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/StoreKdcReqBody.java
Mon Nov 15 20:34:08 2010
@@ -0,0 +1,109 @@
+/*
+ *  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.kdcReq.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.kdcReq.KdcReqContainer;
+import org.apache.directory.shared.kerberos.codec.kdcReqBody.KdcReqBodyContainer;
+import org.apache.directory.shared.kerberos.components.KdcReq;
+import org.apache.directory.shared.kerberos.components.KdcReqBody;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to store the KDC_REQ-BODY
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreKdcReqBody extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( StoreKdcReqBody.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new StoreKdcReqBody action.
+     */
+    public StoreKdcReqBody()
+    {
+        super( "Stores the KDC-REQ-BODY" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        KdcReqContainer kdcReqContainer = ( KdcReqContainer ) container;
+
+        TLV tlv = kdcReqContainer.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 ) );
+        }
+        
+        // Now, let's decode the KDC-REQ-BODY
+        Asn1Decoder kdcReqBodyDecoder = new Asn1Decoder();
+        
+        KdcReqBodyContainer kdcReqBodyContainer = new KdcReqBodyContainer();
+        kdcReqBodyContainer.setStream( container.getStream() );
+
+        // Decode the KDC-REQ-BODY PDU
+        try
+        {
+            kdcReqBodyDecoder.decode( container.getStream(), kdcReqBodyContainer );
+        }
+        catch ( DecoderException de )
+        {
+            throw de;
+        }
+
+        // Store the KDC-REQ-BODY in the container
+        KdcReqBody kdcReqBody = kdcReqBodyContainer.getKdcReqBody();
+        KdcReq kdcReq = kdcReqContainer.getKdcReq();
+        kdcReq.setKdcReqBody( kdcReqBody );
+        
+        // Update the parent
+        container.setParentTLV( tlv.getParent() );
+        
+        container.setGrammarEndAllowed( true );
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "KDC-REQ-BODY : {}", kdcReqBody );
+        }
+    }
+}

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/AddTicket.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/AddTicket.java?rev=1035433&r1=1035432&r2=1035433&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/AddTicket.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/AddTicket.java
Mon Nov 15 20:34:08 2010
@@ -80,8 +80,8 @@ public class AddTicket extends GrammarAc
         TicketContainer ticketContainer = new TicketContainer();
         ticketContainer.setStream( container.getStream() );
 
-        // Compute the start position in the stream for the HostAdress to decode : 
-        // We have to move back to the HostAddress tag
+        // Compute the start position in the stream for the Ticket to decode : 
+        // We have to move back to the Ticket tag
         int start = container.getStream().position() - 1 - tlv.getLengthNbBytes();
         container.getStream().position( start );
 
@@ -95,6 +95,9 @@ public class AddTicket extends GrammarAc
             throw de;
         }
         
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
         // Update the parent
         container.setParentTLV( tlv.getParent() );
 

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreAddresses.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreAddresses.java?rev=1035433&r1=1035432&r2=1035433&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreAddresses.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreAddresses.java
Mon Nov 15 20:34:08 2010
@@ -99,6 +99,9 @@ public class StoreAddresses extends Gram
         HostAddresses hostAddresses = hostAddressesContainer.getHostAddresses();
         kdcReqBody.setAddresses( hostAddresses );
         
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
         // Update the parent
         container.setParentTLV( tlv.getParent() );
         

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreCName.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreCName.java?rev=1035433&r1=1035432&r2=1035433&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreCName.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreCName.java
Mon Nov 15 20:34:08 2010
@@ -95,6 +95,9 @@ public class StoreCName extends GrammarA
         KdcReqBody kdcReqBody = kdcReqBodyContainer.getKdcReqBody();
         kdcReqBody.setCName( principalName );
         
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
         // Update the parent
         container.setParentTLV( tlv.getParent() );
 

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreEncAuthorizationData.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreEncAuthorizationData.java?rev=1035433&r1=1035432&r2=1035433&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreEncAuthorizationData.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreEncAuthorizationData.java
Mon Nov 15 20:34:08 2010
@@ -99,6 +99,9 @@ public class StoreEncAuthorizationData e
         EncryptedData encryptedData = encryptedDataContainer.getEncryptedData();
         kdcReqBody.setEncAuthorizationData( encryptedData );
         
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
         // Update the parent
         container.setParentTLV( tlv.getParent() );
         

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreSName.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreSName.java?rev=1035433&r1=1035432&r2=1035433&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreSName.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreSName.java
Mon Nov 15 20:34:08 2010
@@ -95,6 +95,9 @@ public class StoreSName extends GrammarA
         KdcReqBody kdcReqBody = kdcReqBodyContainer.getKdcReqBody();
         kdcReqBody.setSName( principalName );
         
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
         // Update the parent
         container.setParentTLV( tlv.getParent() );
 

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketSName.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketSName.java?rev=1035433&r1=1035432&r2=1035433&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketSName.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketSName.java
Mon Nov 15 20:34:08 2010
@@ -96,6 +96,9 @@ public class TicketSName extends Grammar
         Ticket ticket = ticketContainer.getTicket();
         ticket.setSName( principalName );
         
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
         // Update the parent
         container.setParentTLV( tlv.getParent() );
 

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java?rev=1035433&r1=1035432&r2=1035433&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java
Mon Nov 15 20:34:08 2010
@@ -203,9 +203,9 @@ public class KdcReq
 
         // Compute the sequence size.
         kdcReqSeqLength = 1 + TLV.getNbBytes( pvnoLength ) + pvnoLength; 
-        kdcReqSeqLength = 1 + TLV.getNbBytes( msgTypeLength ) + msgTypeLength; 
-        kdcReqSeqLength = 1 + TLV.getNbBytes( paDataLength ) + paDataLength; 
-        kdcReqSeqLength = 1 + TLV.getNbBytes( kdcReqBodyLength ) + kdcReqBodyLength; 
+        kdcReqSeqLength += 1 + TLV.getNbBytes( msgTypeLength ) + msgTypeLength; 
+        kdcReqSeqLength += 1 + TLV.getNbBytes( paDataLength ) + paDataLength; 
+        kdcReqSeqLength += 1 + TLV.getNbBytes( kdcReqBodyLength ) + kdcReqBodyLength; 
         
         // compute the global size
         kdcReqLength = 1 + TLV.getNbBytes( kdcReqSeqLength ) + kdcReqSeqLength;
@@ -290,17 +290,21 @@ public class KdcReq
         {
             sb.append( "AS-REQ" ).append( '\n' );
         }
-        else
+        else if ( msgType == KerberosMessageType.TGS_REQ )
         {
             sb.append( "TGS-REQ" ).append( '\n' );
         }
+        else
+        {
+            sb.append( "Unknown" ).append( '\n' );
+        }
 
         for ( PaData paDataElem : paData )
         {
             sb.append( "padata : " ).append( paDataElem ).append( '\n' );
         }
         
-        sb.append( "kdc-req-body" ).append( kdcReqBody ).append( '\n' );
+        sb.append( "kdc-req-body : " ).append( kdcReqBody ).append( '\n' );
         
         return sb.toString();
     }

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java?rev=1035433&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java
Mon Nov 15 20:34:08 2010
@@ -0,0 +1,514 @@
+/*
+ *  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.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.codec.kdcReq.KdcReqContainer;
+import org.apache.directory.shared.kerberos.codec.kdcReqBody.KdcReqBodyContainer;
+import org.apache.directory.shared.kerberos.components.KdcReq;
+import org.apache.directory.shared.kerberos.components.KdcReqBody;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the decoder for a KdcReq
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class KdcReqDecoderTest
+{
+    /**
+     * Test the decoding of a KdcReqBody message
+     */
+    @Test
+    public void testDecodeFullKdcReqBody() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x18F );
+        
+        stream.put( new byte[]
+        {
+            0x30, (byte)0x82, 0x01, (byte)0x8B,
+              (byte)0xA1, 0x03,
+                0x02, 0x01, 0x05,
+              (byte)0xA2, 0x03,
+                0x02, 0x01, 0x0A,
+              (byte)0xA3, 0x20,
+                0x30, 0x1E,
+                  0x30, 0x0D,
+                    (byte)0xA1,0x03,
+                      0x02, 0x01, 01,
+                    (byte)0xA2, 0x06,
+                      0x04, 0x04, 'a', 'b', 'c', 'd',
+                  0x30, 0x0D,
+                    (byte)0xA1,0x03,
+                      0x02, 0x01, 01,
+                    (byte)0xA2, 0x06,
+                      0x04, 0x04, 'e', 'f', 'g', 'h',
+              (byte)0xA4, (byte)0x82, 0x01, 0x5B,
+                0x30, (byte)0x82, 0x01, 0x57, 
+                  (byte)0xA0, 0x07,
+                    0x03, 0x05, 
+                      0x00, 0x01, 0x04, 0x00, 0x32, 
+                  (byte)0xA1, 0x13, 
+                    0x30, 0x11, 
+                      (byte)0xA0, 0x03, 
+                        0x02, 0x01, 0x0A, 
+                      (byte)0xA1, 0x0A, 
+                        0x30, 0x08, 
+                          0x1B, 0x06, 
+                            'c', 'l', 'i', 'e', 'n', 't', 
+                  (byte)0xA2, 0x0D, 
+                    0x1B, 0x0B, 
+                      'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M', 
+                  (byte)0xA3, 0x13, 
+                    0x30, 0x11, 
+                      (byte)0xA0, 0x03, 
+                        0x02, 0x01, 0x0A, 
+                      (byte)0xA1, 0x0A, 
+                        0x30, 0x08, 
+                          0x1B, 0x06, 
+                            's', 'e', 'r', 'v', 'e', 'r', 
+                  (byte)0xA4, 0x11, 
+                    0x18, 0x0F, 
+                      '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5',
'Z', 
+                  (byte)0xA5, 0x11, 
+                    0x18, 0x0F, 
+                      '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5',
'Z', 
+                  (byte)0xA6, 0x11, 
+                    0x18, 0x0F, 
+                      '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5',
'Z', 
+                  (byte)0xA7, 0x04, 
+                    0x02, 0x02, 
+                      0x30, 0x39, 
+                  (byte)0xA8, 0x0B, 
+                    0x30, 0x09, 
+                      0x02, 0x01, 0x06, 
+                      0x02, 0x01, 0x11, 
+                      0x02, 0x01, 0x12, 
+                  (byte)0xA9, 0x2E, 
+                    0x30, 0x2C, 
+                      0x30, 0x14, 
+                        (byte)0xA0, 0x03, 
+                          0x02, 0x01, 0x02, 
+                        (byte)0xA1, 0x0D, 
+                          0x04, 0x0B, 
+                            '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '1', 
+                      0x30, 0x14, 
+                        (byte)0xA0, 0x03, 
+                          0x02, 0x01, 0x02, 
+                        (byte)0xA1, 0x0D, 
+                          0x04, 0x0B, 
+                            '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '2', 
+                  (byte)0xAA, 0x11, 
+                    0x30, 0x0F, 
+                      (byte)0xA0, 0x03, 
+                        0x02, 0x01, 0x11, 
+                      (byte)0xA2, 0x08, 
+                        0x04, 0x06, 
+                          'a', 'b', 'c', 'd', 'e', 'f', 
+                  (byte)0xAB, (byte)0x81, (byte)0x83, 
+                    0x30, (byte)0x81, (byte)0x80, 
+                      0x61, 0x3E, 
+                        0x30, 0x3C, 
+                          (byte)0xA0, 0x03, 
+                            0x02, 0x01, 0x05, 
+                          (byte)0xA1, 0x0D, 
+                            0x1B, 0x0B, 
+                              'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M', 
+                          (byte)0xA2, 0x13, 
+                            0x30, 0x11, 
+                              (byte)0xA0, 0x03, 
+                                0x02, 0x01, 0x01, 
+                              (byte)0xA1, 0x0A, 
+                                0x30, 0x08, 
+                                  0x1B, 0x06, 
+                                    'c', 'l', 'i', 'e', 'n', 't', 
+                          (byte)0xA3, 0x11, 
+                            0x30, 0x0F, 
+                              (byte)0xA0, 0x03, 
+                                0x02, 0x01, 0x11, 
+                              (byte)0xA2, 0x08, 
+                                0x04, 0x06, 
+                                  'a', 'b', 'c', 'd', 'e', 'f', 
+                      0x61, 0x3E, 
+                        0x30, 0x3C, 
+                          (byte)0xA0, 0x03, 
+                            0x02, 0x01, 0x05, 
+                          (byte)0xA1, 0x0D, 
+                            0x1B, 0x0B, 
+                              'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+                          (byte)0xA2, 0x13, 
+                            0x30, 0x11, 
+                              (byte)0xA0, 0x03, 
+                                0x02, 0x01, 0x01, 
+                              (byte)0xA1, 0x0A, 
+                                0x30, 0x08, 
+                                  0x1B, 0x06, 
+                                    's', 'e', 'r', 'v', 'e', 'r', 
+                          (byte)0xA3, 0x11, 
+                            0x30, 0x0F, 
+                              (byte)0xA0, 0x03, 
+                                0x02, 0x01, 0x11, 
+                              (byte)0xA2, 0x08, 
+                                0x04, 0x06, 
+                                  'a', 'b', 'c', 'd', 'e', 'f'
+        });
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a KdcReq Container
+        KdcReqContainer kdcReqContainer = new KdcReqContainer();
+        kdcReqContainer.setStream( stream );
+        
+        // Decode the KdcReq PDU
+        try
+        {
+            kerberosDecoder.decode( stream, kdcReqContainer );
+        }
+        catch ( DecoderException de )
+        {
+            fail( de.getMessage() );
+        }
+
+        KdcReq kdcReq = kdcReqContainer.getKdcReq();
+        
+        // Check the encoding
+        int length = kdcReq.computeLength();
+
+        // Check the length
+        assertEquals( 0x18F, length );
+        
+        // Check the encoding
+        ByteBuffer encodedPdu = ByteBuffer.allocate( length );
+        
+        try
+        {
+            encodedPdu = kdcReq.encode( encodedPdu );
+    
+            // Check the length
+            assertEquals( 0x18F, encodedPdu.limit() );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
+    
+    
+    /**
+     * Test the decoding of a KDC-REQ-BODY with nothing in it
+     */
+    @Test( expected = DecoderException.class)
+    public void testKdcReqBodyEmpty() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+        
+        stream.put( new byte[]
+            { 0x30, 0x00 } );
+
+        stream.flip();
+
+        // Allocate a KDC-REQ-BODY Container
+        Asn1Container kdcReqBodyContainer = new KdcReqBodyContainer();
+
+        // Decode the KDC-REQ-BODY PDU
+        kerberosDecoder.decode( stream, kdcReqBodyContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test the decoding of a KDC-REQ-BODY with empty options tag
+     */
+    @Test( expected = DecoderException.class)
+    public void testKdcReqBodyEmptyOptionTag() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x04 );
+        
+        stream.put( new byte[]
+            { 
+                0x30, 0x02,
+                  (byte)0xA0, 0x00
+            } );
+
+        stream.flip();
+
+        // Allocate a KDC-REQ-BODY Container
+        Asn1Container kdcReqBodyContainer = new KdcReqBodyContainer();
+
+        // Decode the KDC-REQ-BODY PDU
+        kerberosDecoder.decode( stream, kdcReqBodyContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test the decoding of a KDC-REQ-BODY with empty options value
+     */
+    @Test( expected = DecoderException.class)
+    public void testKdcReqBodyEmptyOptionValue() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x06 );
+        
+        stream.put( new byte[]
+            { 
+                0x30, 0x04,
+                  (byte)0xA0, 0x02,
+                    0x02, 0x00
+            } );
+
+        stream.flip();
+
+        // Allocate a KDC-REQ-BODY Container
+        Asn1Container kdcReqBodyContainer = new KdcReqBodyContainer();
+
+        // Decode the KDC-REQ-BODY PDU
+        kerberosDecoder.decode( stream, kdcReqBodyContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test the decoding of a KDC-REQ-BODY with no options
+     */
+    @Test( expected = DecoderException.class)
+    public void testKdcReqBodyNoOptions() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x152 );
+        
+        stream.put( new byte[]
+             {
+                 0x30, (byte)0x82, 0x01, 0x4E, 
+                   (byte)0xA1, 0x13, 
+                     0x30, 0x11, 
+                       (byte)0xA0, 0x03, 
+                         0x02, 0x01, 0x0A, 
+                       (byte)0xA1, 0x0A, 
+                         0x30, 0x08, 
+                           0x1B, 0x06, 
+                             'c', 'l', 'i', 'e', 'n', 't', 
+                   (byte)0xA2, 0x0D, 
+                     0x1B, 0x0B, 
+                       'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M', 
+                   (byte)0xA3, 0x13, 
+                     0x30, 0x11, 
+                       (byte)0xA0, 0x03, 
+                         0x02, 0x01, 0x0A, 
+                       (byte)0xA1, 0x0A, 
+                         0x30, 0x08, 
+                           0x1B, 0x06, 
+                             's', 'e', 'r', 'v', 'e', 'r', 
+                   (byte)0xA4, 0x11, 
+                     0x18, 0x0F, 
+                       '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5',
'Z', 
+                   (byte)0xA5, 0x11, 
+                     0x18, 0x0F, 
+                       '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5',
'Z', 
+                   (byte)0xA6, 0x11, 
+                     0x18, 0x0F, 
+                       '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5',
'Z', 
+                   (byte)0xA7, 0x04, 
+                     0x02, 0x02, 
+                       0x30, 0x39, 
+                   (byte)0xA8, 0x0B, 
+                     0x30, 0x09, 
+                       0x02, 0x01, 0x06, 
+                       0x02, 0x01, 0x11, 
+                       0x02, 0x01, 0x12, 
+                   (byte)0xA9, 0x2E, 
+                     0x30, 0x2C, 
+                       0x30, 0x14, 
+                         (byte)0xA0, 0x03, 
+                           0x02, 0x01, 0x02, 
+                         (byte)0xA1, 0x0D, 
+                           0x04, 0x0B, 
+                             '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '1', 
+                       0x30, 0x14, 
+                         (byte)0xA0, 0x03, 
+                           0x02, 0x01, 0x02, 
+                         (byte)0xA1, 0x0D, 
+                           0x04, 0x0B, 
+                             '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '2', 
+                   (byte)0xAA, 0x11, 
+                     0x30, 0x0F, 
+                       (byte)0xA0, 0x03, 
+                         0x02, 0x01, 0x11, 
+                       (byte)0xA2, 0x08, 
+                         0x04, 0x06, 
+                           'a', 'b', 'c', 'd', 'e', 'f', 
+                   (byte)0xAB, (byte)0x81, (byte)0x83, 
+                     0x30, (byte)0x81, (byte)0x80, 
+                       0x61, 0x3E, 
+                         0x30, 0x3C, 
+                           (byte)0xA0, 0x03, 
+                             0x02, 0x01, 0x05, 
+                           (byte)0xA1, 0x0D, 
+                             0x1B, 0x0B, 
+                               'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M', 
+                           (byte)0xA2, 0x13, 
+                             0x30, 0x11, 
+                               (byte)0xA0, 0x03, 
+                                 0x02, 0x01, 0x01, 
+                               (byte)0xA1, 0x0A, 
+                                 0x30, 0x08, 
+                                   0x1B, 0x06, 
+                                     'c', 'l', 'i', 'e', 'n', 't', 
+                           (byte)0xA3, 0x11, 
+                             0x30, 0x0F, 
+                               (byte)0xA0, 0x03, 
+                                 0x02, 0x01, 0x11, 
+                               (byte)0xA2, 0x08, 
+                                 0x04, 0x06, 
+                                   'a', 'b', 'c', 'd', 'e', 'f', 
+                       0x61, 0x3E, 
+                         0x30, 0x3C, 
+                           (byte)0xA0, 0x03, 
+                             0x02, 0x01, 0x05, 
+                           (byte)0xA1, 0x0D, 
+                             0x1B, 0x0B, 
+                               'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+                           (byte)0xA2, 0x13, 
+                             0x30, 0x11, 
+                               (byte)0xA0, 0x03, 
+                                 0x02, 0x01, 0x01, 
+                               (byte)0xA1, 0x0A, 
+                                 0x30, 0x08, 
+                                   0x1B, 0x06, 
+                                     's', 'e', 'r', 'v', 'e', 'r', 
+                           (byte)0xA3, 0x11, 
+                             0x30, 0x0F, 
+                               (byte)0xA0, 0x03, 
+                                 0x02, 0x01, 0x11, 
+                               (byte)0xA2, 0x08, 
+                                 0x04, 0x06, 
+                                   'a', 'b', 'c', 'd', 'e', 'f'
+             });
+
+        stream.flip();
+
+        // Allocate a KDC-REQ-BODY Container
+        Asn1Container kdcReqBodyContainer = new KdcReqBodyContainer();
+
+        // Decode the KDC-REQ-BODY PDU
+        kerberosDecoder.decode( stream, kdcReqBodyContainer );
+        fail();
+    }
+
+
+    /**
+     * Test the decoding of a KdcReqBody message with no optional value
+     * ( we only have options, realm, till, nonce and etype )
+     */
+    @Test
+    public void testDecodeKdcReqBodyNoOptionalValue() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x40 );
+        
+        stream.put( new byte[]
+        {
+            0x30, (byte)0x3E, 
+              (byte)0xA0, 0x07,
+                0x03, 0x05, 
+                  0x00, 0x01, 0x04, 0x00, 0x32, 
+              (byte)0xA2, 0x0D, 
+                0x1B, 0x0B, 
+                  'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M', 
+              (byte)0xA5, 0x11, 
+                0x18, 0x0F, 
+                  '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z',

+              (byte)0xA7, 0x04, 
+                0x02, 0x02, 
+                  0x30, 0x39, 
+              (byte)0xA8, 0x0B, 
+                0x30, 0x09, 
+                  0x02, 0x01, 0x06, 
+                  0x02, 0x01, 0x11, 
+                  0x02, 0x01, 0x12
+        });
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a KdcReqBody Container
+        KdcReqBodyContainer kdcReqBodyContainer = new KdcReqBodyContainer();
+        kdcReqBodyContainer.setStream( stream );
+        
+        // Decode the KdcReqBody PDU
+        try
+        {
+            kerberosDecoder.decode( stream, kdcReqBodyContainer );
+        }
+        catch ( DecoderException de )
+        {
+            fail( de.getMessage() );
+        }
+
+        KdcReqBody body = kdcReqBodyContainer.getKdcReqBody();
+        
+        assertNotNull( body );
+        
+        // Check the encoding
+        ByteBuffer bb = ByteBuffer.allocate( body.computeLength() );
+
+        try
+        {
+            bb = body.encode( bb );
+    
+            // Check the length
+            assertEquals( 0x40, bb.limit() );
+
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+            
+            assertEquals( decodedPdu, encodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
+}

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java?rev=1035433&r1=1035432&r2=1035433&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java
Mon Nov 15 20:34:08 2010
@@ -22,7 +22,6 @@ package org.apache.directory.shared.kerb
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -33,7 +32,6 @@ import org.apache.directory.junit.tools.
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
 import org.apache.directory.shared.asn1.ber.Asn1Container;
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
-import org.apache.directory.shared.asn1.ber.tlv.TLVStateEnum;
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.kerberos.codec.ticket.TicketContainer;
@@ -506,7 +504,7 @@ public class TicketDecoderTest
     /**
      * Test the decoding of a ticket with no enc-part
      */
-    @Test
+    @Test( expected=DecoderException.class)
     public void testDecodeTicketNoEncPart() throws Exception
     {
         Asn1Decoder kerberosDecoder = new Asn1Decoder();
@@ -538,8 +536,6 @@ public class TicketDecoderTest
 
         // Decode the Ticket PDU
         kerberosDecoder.decode( stream, ticketContainer );
-
-        assertNotSame( TLVStateEnum.PDU_DECODED, ticketContainer.getState() );
     }
 
 



Mime
View raw message