directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1039225 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/ main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/actions/ main/java/org/apache/directory/shared/...
Date Thu, 25 Nov 2010 23:37:54 GMT
Author: elecharny
Date: Thu Nov 25 23:37:53 2010
New Revision: 1039225

URL: http://svn.apache.org/viewvc?rev=1039225&view=rev
Log:
o Added the EncTgsRepPart grammar
o Some minor fixes

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/actions/StoreEncTgsRepPart.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncTgsRepPart.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncTgsRepPartDecoderTest.java
Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/actions/StoreEncAsRepPart.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncAsRepPart.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncAsRepPartDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartGrammar.java?rev=1039225&r1=1039224&r2=1039225&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartGrammar.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartGrammar.java
Thu Nov 25 23:37:53 2010
@@ -59,10 +59,10 @@ public final class EncAsRepPartGrammar e
         super.transitions = new GrammarTransition[EncAsRepPartStatesEnum.LAST_ENC_AS_REP_PART_STATE.ordinal()][256];
 
         // ============================================================================================
-        // AS-REP 
+        // EncAsRepPart 
         // ============================================================================================
         // --------------------------------------------------------------------------------------------
-        // Transition from AS-REP init to KDC-REP
+        // Transition from EncAsRepPart init to EncKDCRepPart
         // --------------------------------------------------------------------------------------------
         // EncASRepPart    ::= [APPLICATION 25] EncKDCRepPart
         super.transitions[EncAsRepPartStatesEnum.START_STATE.ordinal()][KerberosConstants.ENC_AS_REP_PART_TAG]
= new GrammarTransition(

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/actions/StoreEncAsRepPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/actions/StoreEncAsRepPart.java?rev=1039225&r1=1039224&r2=1039225&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/actions/StoreEncAsRepPart.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/actions/StoreEncAsRepPart.java
Thu Nov 25 23:37:53 2010
@@ -103,7 +103,7 @@ public class StoreEncAsRepPart extends G
 
         if ( IS_DEBUG )
         {
-            LOG.debug( "AS-REP : {}", encKdcRepPart );
+            LOG.debug( "EncAsRepPart : {}", encKdcRepPart );
         }
         
         container.setGrammarEndAllowed( true );

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartContainer.java?rev=1039225&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartContainer.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartContainer.java
Thu Nov 25 23:37:53 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.encTgsRepPart;
+
+import org.apache.directory.shared.kerberos.codec.kdcReq.KdcReqContainer;
+import org.apache.directory.shared.kerberos.messages.EncTgsRepPart;
+
+
+/**
+ * The EncTgsRepPart container stores the EncTgsRepPart decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncTgsRepPartContainer extends KdcReqContainer
+{
+    /** An EncTgsRepPart container */
+    private EncTgsRepPart encTgsRepPart = new EncTgsRepPart();
+
+    /**
+     * Creates a new EncTgsRepPartContainer object.
+     */
+    public EncTgsRepPartContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = EncTgsRepPartGrammar.getInstance();
+        setTransition( EncTgsRepPartStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the EncTgsRepPart.
+     */
+    public EncTgsRepPart getEncTgsRepPart()
+    {
+        return encTgsRepPart;
+    }
+
+    
+    /**
+     * Set an EncTgsRepPart Object into the container. It will be completed by the
+     * KerberosDecoder.
+     * 
+     * @param encTgsRepPart The EncTgsRepPart to set.
+     */
+    public void setEncTgsRepPart( EncTgsRepPart encTgsRepPart )
+    {
+        this.encTgsRepPart = encTgsRepPart;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartGrammar.java?rev=1039225&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartGrammar.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartGrammar.java
Thu Nov 25 23:37:53 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.encTgsRepPart;
+
+
+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.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.codec.encTgsRepPart.actions.StoreEncTgsRepPart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the EncTgsRepPart 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 EncTgsRepPartGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( EncTgsRepPartGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. EncTgsRepPartGrammar is a singleton */
+    private static Grammar instance = new EncTgsRepPartGrammar();
+
+
+    /**
+     * Creates a new EncTgsRepPartGrammar object.
+     */
+    private EncTgsRepPartGrammar()
+    {
+        setName( EncTgsRepPartGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[EncTgsRepPartStatesEnum.LAST_ENC_TGS_REP_PART_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // EncTgsRepPart 
+        // ============================================================================================
+        // --------------------------------------------------------------------------------------------
+        // Transition from EncTgsRepPart init to EncKDCRepPart
+        // --------------------------------------------------------------------------------------------
+        // EncASRepPart    ::= [APPLICATION 25] EncKDCRepPart
+        super.transitions[EncTgsRepPartStatesEnum.START_STATE.ordinal()][KerberosConstants.ENC_TGS_REP_PART_TAG]
= new GrammarTransition(
+            EncTgsRepPartStatesEnum.START_STATE, EncTgsRepPartStatesEnum.ENC_TGS_REP_PART_STATE,
KerberosConstants.ENC_TGS_REP_PART_TAG,
+            new StoreEncTgsRepPart() );
+    }
+
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the EncAsRepPart Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartStatesEnum.java?rev=1039225&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartStatesEnum.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/EncTgsRepPartStatesEnum.java
Thu Nov 25 23:37:53 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.encTgsRepPart;
+
+
+import org.apache.directory.shared.asn1.ber.grammar.Grammar;
+import org.apache.directory.shared.asn1.ber.grammar.States;
+import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
+
+
+/**
+ * This class store the EncTgsRepPart grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum EncTgsRepPartStatesEnum implements States
+{
+    // Start
+    START_STATE,                            // 0
+    
+    // ----- EncTgsRepPart message --------------------------------------
+    ENC_TGS_REP_PART_STATE,                  // 1
+    
+    // End
+    LAST_ENC_TGS_REP_PART_STATE;             // 2
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "ENC_TGS_REP_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_TGS_REP_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_TGS_REP_PART_STATE.ordinal() ) ? "ENC_TGS_REP_PART_END_STATE"
: name() );
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_ENC_TGS_REP_PART_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public EncTgsRepPartStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/actions/StoreEncTgsRepPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/actions/StoreEncTgsRepPart.java?rev=1039225&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/actions/StoreEncTgsRepPart.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encTgsRepPart/actions/StoreEncTgsRepPart.java
Thu Nov 25 23:37:53 2010
@@ -0,0 +1,111 @@
+/*
+ *  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.encTgsRepPart.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.KerberosMessageGrammar;
+import org.apache.directory.shared.kerberos.codec.EncKdcRepPart.EncKdcRepPartContainer;
+import org.apache.directory.shared.kerberos.codec.encTgsRepPart.EncTgsRepPartContainer;
+import org.apache.directory.shared.kerberos.components.EncKdcRepPart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to add a EncTgsRepPart object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreEncTgsRepPart extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class
);
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new EncTgsRepPart action.
+     */
+    public StoreEncTgsRepPart()
+    {
+        super( "Add an EncTgsRepPart instance" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        EncTgsRepPartContainer encTgsRepPartContainer = ( EncTgsRepPartContainer ) container;
+
+        TLV tlv = encTgsRepPartContainer.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 EncKdcRepPart
+        Asn1Decoder encKdcRepPartDecoder = new Asn1Decoder();
+        
+        EncKdcRepPartContainer encKdcRepPartContainer = new EncKdcRepPartContainer();
+        encKdcRepPartContainer.setStream( container.getStream() );
+        
+        // Decode the EncKdcRepPart PDU
+        try
+        {
+            encKdcRepPartDecoder.decode( container.getStream(), encKdcRepPartContainer );
+        }
+        catch ( DecoderException de )
+        {
+            throw de;
+        }
+        
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+        // Update the parent
+        container.updateParent();
+        
+        EncKdcRepPart encKdcRepPart = encKdcRepPartContainer.getEncKdcRepPart();
+
+        encTgsRepPartContainer.getEncTgsRepPart().setEncKdcRepPart( encKdcRepPart );
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "EncKdcRepPart : {}", encKdcRepPart );
+        }
+        
+        container.setGrammarEndAllowed( true );
+    }
+}

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncAsRepPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncAsRepPart.java?rev=1039225&r1=1039224&r2=1039225&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncAsRepPart.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncAsRepPart.java
Thu Nov 25 23:37:53 2010
@@ -77,7 +77,7 @@ public class EncAsRepPart extends Kerber
      * <pre>
      * EncAsRepPart :
      * 
-     * 0x79 L1 AS-REP message
+     * 0x79 L1 EncAsRepPart message
      *  |
      *  +-->  0x30 L2 EncKdcRepPart sequence
      * </pre>

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncTgsRepPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncTgsRepPart.java?rev=1039225&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncTgsRepPart.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncTgsRepPart.java
Thu Nov 25 23:37:53 2010
@@ -0,0 +1,115 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.messages;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.KerberosMessageType;
+import org.apache.directory.shared.kerberos.components.EncKdcRepPart;
+
+
+/**
+ * EncTGSRepPart message. 
+ *  It will store the object described by the ASN.1 grammar :
+ * <pre>
+ * EncTGSRepPart   ::= [APPLICATION 26] EncKDCRepPart
+ * </pre>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncTgsRepPart extends KerberosMessage
+{
+    /** The EncKdcRepPart */
+    private EncKdcRepPart encKdcRepPart;
+    
+    // Storage for computed lengths
+    private transient int encKdcRepPartLength;
+
+    /**
+     * Creates a new instance of EncTgsRepPart.
+     */
+    public EncTgsRepPart() 
+    {
+        super( KerberosMessageType.ENC_TGS_REP_PART );
+    }
+
+
+    /**
+     * @return the encKdcRepPart
+     */
+    public EncKdcRepPart getEncKdcRepPart()
+    {
+        return encKdcRepPart;
+    }
+
+
+    /**
+     * @param encKdcRepPart the encKdcRepPart to set
+     */
+    public void setEncKdcRepPart( EncKdcRepPart encKdcRepPart )
+    {
+        this.encKdcRepPart = encKdcRepPart;
+    }
+
+    
+    /**
+     * Compute the EncTgsRepPart length
+     * <pre>
+     * EncTgsRepPart :
+     * 
+     * 0x7A L1 EncTgsRepPart message
+     *  |
+     *  +-->  0x30 L2 EncKdcRepPart sequence
+     * </pre>
+     */
+    public int computeLength()
+    {
+        encKdcRepPartLength = encKdcRepPart.computeLength();
+        return 1 + TLV.getNbBytes( encKdcRepPartLength ) + encKdcRepPartLength;
+    }
+    
+    
+    /**
+     * Encode the EncTgsRepPart component
+     * 
+     * @param buffer The buffer containing the encoded result
+     * @return The encoded component
+     * @throws EncoderException If the encoding failed
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            buffer = ByteBuffer.allocate( computeLength() );
+        }
+        
+        // The EncAsRepPart Tag
+        buffer.put( (byte)KerberosConstants.ENC_TGS_REP_PART_TAG );
+        buffer.put( TLV.getBytes( encKdcRepPartLength ) );
+        
+        // The EncKdcRepPart --------------------------------------------------------
+        encKdcRepPart.encode( buffer );
+        
+        return buffer;
+    }
+}

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncAsRepPartDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncAsRepPartDecoderTest.java?rev=1039225&r1=1039224&r2=1039225&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncAsRepPartDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncAsRepPartDecoderTest.java
Thu Nov 25 23:37:53 2010
@@ -31,7 +31,6 @@ import org.apache.directory.shared.asn1.
 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.asRep.AsRepContainer;
 import org.apache.directory.shared.kerberos.codec.encAsRepPart.EncAsRepPartContainer;
 import org.apache.directory.shared.kerberos.messages.EncAsRepPart;
 import org.junit.Test;
@@ -160,7 +159,7 @@ public class EncAsRepPartDecoderTest
         stream.flip();
 
         // Allocate a EncAsRepPart Container
-        Asn1Container encAsRepPartContainer = new AsRepContainer();
+        Asn1Container encAsRepPartContainer = new EncAsRepPartContainer();
 
         // Decode the EncAsRepPart PDU
         kerberosDecoder.decode( stream, encAsRepPartContainer );

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncTgsRepPartDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncTgsRepPartDecoderTest.java?rev=1039225&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncTgsRepPartDecoderTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncTgsRepPartDecoderTest.java
Thu Nov 25 23:37:53 2010
@@ -0,0 +1,196 @@
+/*
+ *  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.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.encTgsRepPart.EncTgsRepPartContainer;
+import org.apache.directory.shared.kerberos.messages.EncTgsRepPart;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the decoder for a EncTgsRepPart
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class EncTgsRepPartDecoderTest
+{
+    /**
+     * Test the decoding of a EncTgsRepPart message
+     */
+    @Test
+    public void testDecodeFullEncTgsRepPart() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0xA2 );
+        
+        stream.put( new byte[]
+        {
+            0x7A, (byte)0x81, (byte)0x9F,
+              0x30, (byte)0x81, (byte)0x9C,
+                (byte)0xA0, 0x11,
+                  0x30, 0x0F, 
+                    (byte)0xA0, 0x03, 
+                      0x02, 0x01, 0x11, 
+                    (byte)0xA1, 0x08, 
+                      0x04, 0x06, 
+                        0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
+                (byte)0xA1, 0x36,
+                  0x30, 0x34, 
+                    0x30, 0x18, 
+                      (byte)0xA0, 0x03, 
+                        0x02, 0x01, 0x02, 
+                      (byte)0xA1, 0x11, 
+                        0x18, 0x0F, 
+                          0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31,
0x32, 0x35, 0x39, 0x5A,
+                    0x30, 0x18,
+                      (byte)0xA0, 0x03,
+                        0x02, 0x01, 0x02,
+                      (byte)0xA1, 0x11,
+                        0x18, 0x0F, 
+                          0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31,
0x32, 0x35, 0x39, 0x5A,
+                (byte)0xA2, 0x03,
+                  0x02, 0x01, 0x01,
+                (byte)0xA4, 0x07,
+                  0x03, 0x05, 0x00, 0x40, 0x00, 0x00, 0x00,
+                (byte)0xA5, 0x11,
+                  0x18, 0x0F, 
+                    0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32,
0x35, 0x39, 0x5A,
+                (byte)0xA7, 0x11, 
+                  0x18, 0x0F, 
+                    0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32,
0x35, 0x39, 0x5A,
+                (byte)0xA9, 0x06,
+                  0x1B, 0x04, 'a', 'b', 'c', 'd',
+                (byte)0xAA, 0x13,
+                  0x30, 0x11, 
+                    (byte)0xA0, 0x03, 
+                      0x02, 0x01, 0x01, 
+                    (byte)0xA1, 0x0A, 
+                      0x30, 0x08,
+                        0x1B, 0x06, 
+                          0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
+        });
+
+        stream.flip();
+
+        // Allocate a EncAsRepPart Container
+        EncTgsRepPartContainer encTgsRepPartContainer = new EncTgsRepPartContainer();
+        encTgsRepPartContainer.setStream( stream );
+        
+        // Decode the EncTgsRepPart PDU
+        try
+        {
+            kerberosDecoder.decode( stream, encTgsRepPartContainer );
+        }
+        catch ( DecoderException de )
+        {
+            fail( de.getMessage() );
+        }
+
+        EncTgsRepPart encTgsRepPart = encTgsRepPartContainer.getEncTgsRepPart();
+        
+        // Check the encoding
+        int length = encTgsRepPart.computeLength();
+
+        // Check the length
+        assertEquals( 0xA2, length );
+        
+        // Check the encoding
+        ByteBuffer encodedPdu = ByteBuffer.allocate( length );
+        
+        try
+        {
+            encodedPdu = encTgsRepPart.encode( encodedPdu );
+            
+            // Check the length
+            assertEquals( 0xA2, encodedPdu.limit() );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
+    
+    
+    /**
+     * Test the decoding of a EncAsRepPart with nothing in it
+     */
+    @Test( expected = DecoderException.class)
+    public void testEncTgsRepPartEmpty() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+        
+        stream.put( new byte[]
+            { 0x7A, 0x00 } );
+
+        stream.flip();
+
+        // Allocate a EncTgsRepPart Container
+        Asn1Container encTgsRepPartContainer = new EncTgsRepPartContainer();
+
+        // Decode the EncTgsRepPart PDU
+        kerberosDecoder.decode( stream, encTgsRepPartContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test the decoding of a EncTgsRepPart with empty EncKdcRepPart tag
+     */
+    @Test( expected = DecoderException.class)
+    public void testEncTgsRepPartEmptyEncKdcRepPart() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x04 );
+        
+        stream.put( new byte[]
+            { 
+                0x7A, 0x02,
+                  0x30, 0x00
+            } );
+
+        stream.flip();
+
+        // Allocate a EncTgsRepPart Container
+        Asn1Container encTgsRepPartContainer = new EncTgsRepPartContainer();
+        encTgsRepPartContainer.setStream( stream );
+
+        // Decode the EncTgsRepPart PDU
+        kerberosDecoder.decode( stream, encTgsRepPartContainer );
+        fail();
+    }
+}



Mime
View raw message