directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1033612 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/authorizationData/ main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/ main/java/org/apache/directo...
Date Wed, 10 Nov 2010 17:47:07 GMT
Author: elecharny
Date: Wed Nov 10 17:47:06 2010
New Revision: 1033612

URL: http://svn.apache.org/viewvc?rev=1033612&view=rev
Log:
Transform the grammar to deal with SE of SEQ

Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdData.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdType.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AuthorizationDataDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataGrammar.java?rev=1033612&r1=1033611&r2=1033612&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataGrammar.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataGrammar.java
Wed Nov 10 17:47:06 2010
@@ -66,17 +66,25 @@ public final class AuthorizationDataGram
         // AuthorizationData 
         // ============================================================================================
         // --------------------------------------------------------------------------------------------
-        // Transition from AuthorizationData init to AuthorizationData SEQ
+        // Transition from AuthorizationData init to AuthorizationData SEQ OF
         // --------------------------------------------------------------------------------------------
-        // AuthorizationData   ::= SEQUENCE
+        // AuthorizationData   ::= SEQUENCE OF
         super.transitions[AuthorizationDataStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
-            AuthorizationDataStatesEnum.START_STATE, AuthorizationDataStatesEnum.AUTHORIZATION_DATA_SEQ_STATE,
UniversalTag.SEQUENCE.getValue(),
+            AuthorizationDataStatesEnum.START_STATE, AuthorizationDataStatesEnum.AUTHORIZATION_DATA_SEQ_SEQ_STATE,
UniversalTag.SEQUENCE.getValue(),
             new AuthorizationDataInit() );
         
         // --------------------------------------------------------------------------------------------
-        // Transition from AuthorizationData SEQ to adType tag
+        // Transition from AuthorizationData SEQ OF to SEQ
         // --------------------------------------------------------------------------------------------
-        // AuthorizationData  ::= SEQUENCE {
+        // AuthorizationData  ::= SEQUENCE OF SEQUENCE {
+        super.transitions[AuthorizationDataStatesEnum.AUTHORIZATION_DATA_SEQ_SEQ_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            AuthorizationDataStatesEnum.AUTHORIZATION_DATA_SEQ_SEQ_STATE, AuthorizationDataStatesEnum.AUTHORIZATION_DATA_SEQ_STATE,
UniversalTag.SEQUENCE.getValue(),
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from AuthorizationData SEQ OF to adType tag
+        // --------------------------------------------------------------------------------------------
+        // AuthorizationData  ::= SEQUENCE OF SEQUENCE {
         //         ad-type     [0]
         super.transitions[AuthorizationDataStatesEnum.AUTHORIZATION_DATA_SEQ_STATE.ordinal()][KerberosConstants.AUTHORIZATION_DATA_ADTYPE_TAG]
= new GrammarTransition(
             AuthorizationDataStatesEnum.AUTHORIZATION_DATA_SEQ_STATE, AuthorizationDataStatesEnum.AUTHORIZATION_DATA_ADTYPE_TAG_STATE,
KerberosConstants.AUTHORIZATION_DATA_ADTYPE_TAG,
@@ -85,7 +93,7 @@ public final class AuthorizationDataGram
         // --------------------------------------------------------------------------------------------
         // Transition from adtype tag to adtype value
         // --------------------------------------------------------------------------------------------
-        // AuthorizationData  ::= SEQUENCE {
+        // AuthorizationData  ::= SEQUENCE OF SEQUENCE {
         //         ad-type     [0] Int32,
         super.transitions[AuthorizationDataStatesEnum.AUTHORIZATION_DATA_ADTYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
             AuthorizationDataStatesEnum.AUTHORIZATION_DATA_ADTYPE_TAG_STATE, AuthorizationDataStatesEnum.AUTHORIZATION_DATA_ADTYPE_STATE,
UniversalTag.INTEGER.getValue(),
@@ -94,7 +102,7 @@ public final class AuthorizationDataGram
         // --------------------------------------------------------------------------------------------
         // Transition from ad-type value to ad-data tag
         // --------------------------------------------------------------------------------------------
-        // AuthorizationData   ::= SEQUENCE {
+        // AuthorizationData   ::= SEQUENCE OF SEQUENCE {
         //         ...
         //         ad-data     [1]
         super.transitions[AuthorizationDataStatesEnum.AUTHORIZATION_DATA_ADTYPE_STATE.ordinal()][KerberosConstants.AUTHORIZATION_DATA_ADDATA_TAG]
= new GrammarTransition(
@@ -104,12 +112,22 @@ public final class AuthorizationDataGram
         // --------------------------------------------------------------------------------------------
         // Transition from ad-data tag to ad-data value
         // --------------------------------------------------------------------------------------------
-        // AuthorizationData   ::= SEQUENCE {
+        // AuthorizationData   ::= SEQUENCE OF SEQUENCE {
         //         ...
         //         ad-data     [1] (OCTET STRING)
         super.transitions[AuthorizationDataStatesEnum.AUTHORIZATION_DATA_ADDATA_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()]
= new GrammarTransition(
             AuthorizationDataStatesEnum.AUTHORIZATION_DATA_ADDATA_TAG_STATE, AuthorizationDataStatesEnum.AUTHORIZATION_DATA_ADDATA_STATE,
UniversalTag.OCTET_STRING.getValue(),
             new AuthorizationDataAdData() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from ad-data value to SEQUENCE
+        // --------------------------------------------------------------------------------------------
+        // AuthorizationData   ::= SEQUENCE {
+        //         ...
+        //         ad-data     [1] (OCTET STRING)
+        super.transitions[AuthorizationDataStatesEnum.AUTHORIZATION_DATA_ADDATA_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            AuthorizationDataStatesEnum.AUTHORIZATION_DATA_ADDATA_STATE, AuthorizationDataStatesEnum.AUTHORIZATION_DATA_SEQ_STATE,
UniversalTag.SEQUENCE.getValue(),
+            new CheckNotNullLength() );
     }
 
 

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataStatesEnum.java?rev=1033612&r1=1033611&r2=1033612&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataStatesEnum.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataStatesEnum.java
Wed Nov 10 17:47:06 2010
@@ -33,22 +33,21 @@ import org.apache.directory.shared.kerbe
  */
 public enum AuthorizationDataStatesEnum implements States
 {
-    // ~ Static fields/initializers
-    // -----------------------------------------------------------------
-
     // Start
-    START_STATE,                            // 0
+    START_STATE,                                // 0
     
     AUTHORIZATION_DATA_SEQ_STATE,               // 1
     
-    AUTHORIZATION_DATA_ADTYPE_TAG_STATE,         // 2
-    AUTHORIZATION_DATA_ADTYPE_STATE,             // 3
+    AUTHORIZATION_DATA_SEQ_SEQ_STATE,           // 2
+    
+    AUTHORIZATION_DATA_ADTYPE_TAG_STATE,        // 3
+    AUTHORIZATION_DATA_ADTYPE_STATE,            // 4
     
-    AUTHORIZATION_DATA_ADDATA_TAG_STATE,          // 4
-    AUTHORIZATION_DATA_ADDATA_STATE,              // 5
+    AUTHORIZATION_DATA_ADDATA_TAG_STATE,        // 5
+    AUTHORIZATION_DATA_ADDATA_STATE,            // 6
     
     // End
-    LAST_AUTHORIZATION_DATA_STATE;              // 6
+    LAST_AUTHORIZATION_DATA_STATE;              // 7
 
     
     /**

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdData.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdData.java?rev=1033612&r1=1033611&r2=1033612&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdData.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdData.java
Wed Nov 10 17:47:06 2010
@@ -86,7 +86,7 @@ public class AuthorizationDataAdData ext
         }
         
         AuthorizationData authData = authDataContainer.getAuthorizationData();
-        authData.setAdData( value.getData() );
+        authData.setCurrentAdData( value.getData() );
         
         if ( IS_DEBUG )
         {

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdType.java?rev=1033612&r1=1033611&r2=1033612&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdType.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdType.java
Wed Nov 10 17:47:06 2010
@@ -76,16 +76,19 @@ public class AuthorizationDataAdType ext
             throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
         }
         
-        // The encyptionType is an integer
-        Value value = tlv.getValue();
-        
         AuthorizationData authData = authDataContainer.getAuthorizationData();
+
+        // Creates a new AD
+        authData.createNewAD();
+        
+        // The AuthorizationData data is an integer
+        Value value = tlv.getValue();
         
         try
         {
             int adType = IntegerDecoder.parse( value );
 
-            authData.setAdType( adType );
+            authData.setCurrentAdType( adType );
 
             if ( IS_DEBUG )
             {

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataInit.java?rev=1033612&r1=1033611&r2=1033612&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataInit.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataInit.java
Wed Nov 10 17:47:06 2010
@@ -46,7 +46,7 @@ public class AuthorizationDataInit exten
 
 
     /**
-     * Instantiates a new EncryptedDataInit action.
+     * Instantiates a new AuthorizationDataInit action.
      */
     public AuthorizationDataInit()
     {

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java?rev=1033612&r1=1033611&r2=1033612&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java
Wed Nov 10 17:47:06 2010
@@ -23,6 +23,8 @@ package org.apache.directory.shared.kerb
 
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.shared.asn1.AbstractAsn1Object;
@@ -48,12 +50,37 @@ import org.slf4j.LoggerFactory;
  */
 public class AuthorizationData extends AbstractAsn1Object
 {
+    // The inner class storing the individual ADs
+    public class AD
+    {
+        /** the type of authorization data */
+        private int adType;
+
+        /** the authorization data */
+        private byte[] adData;
 
-    /** the type of authorization data */
-    private int adType;
+        /**
+         * @return the adType
+         */
+        public int getAdType()
+        {
+            return adType;
+        }
 
-    /** the authorization data */
-    private byte[] adData;
+        /**
+         * @return the adData
+         */
+        public byte[] getAdData()
+        {
+            return adData;
+        }
+    }
+    
+    /** The list of AuthorizationData elements */
+    private List<AD> authorizationData = new ArrayList<AD>();
+    
+    /** The current AD being processed */
+    private AD currentAD;
 
     /** The logger */
     private static final Logger LOG = LoggerFactory.getLogger( EncryptedData.class );
@@ -61,49 +88,60 @@ public class AuthorizationData extends A
     /** Speedup for logs */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
 
-    private transient int adTypeTagLen;
-    private transient int adDataTagLen;
-    private transient int authorizationDataSeqLen;
+    // Storage for computed lengths
+    private transient int adTypeTagLen[];
+    private transient int adDataTagLen[];
+    private transient int authorizationDataSeqLen[];
+    private transient int authorizationDataSeqSeqLen;
 
 
+    /**
+     * Creates a new set of AuthorizationData
+     */
     public AuthorizationData()
     {
     }
 
 
-    public AuthorizationData( int adType, byte[] adData )
-    {
-        this.adType = adType;
-        this.adData = adData;
-    }
-
-
     /**
      * Compute the AuthorizationData length
      * 
      * 0x30 L1 AuthorizationData sequence
-     * |
-     * +--> 0xA1 L2 adType tag
-     * |     |
-     * |     +--> 0x02 L2-1 adType (int)
-     * |
-     * +--> 0xA2 L3 adData tag
+     *  |
+     *  +-- 0x30 L2 The AD sequence
      *       |
-     *       +--> 0x04 L3-1 adData (OCTET STRING)
+     *       +--> 0xA1 L3 adType tag
+     *       |     |
+     *       |     +--> 0x02 L3-1 adType (int)
+     *       |
+     *       +--> 0xA2 L4 adData tag
+     *             |
+     *             +--> 0x04 L<4-1 adData (OCTET STRING)
      * 
      */
     @Override
     public int computeLength()
     {
-        int adTypeLen = Value.getNbBytes( adType );
-        adTypeTagLen = 1 + TLV.getNbBytes( adTypeLen ) + adTypeLen;
-
-        adDataTagLen = 1 + TLV.getNbBytes( adData.length ) + adData.length;
-
-        authorizationDataSeqLen = 1 + TLV.getNbBytes( adTypeTagLen ) + adTypeTagLen;
-        authorizationDataSeqLen += 1 + TLV.getNbBytes( adDataTagLen ) + adDataTagLen;
+        int i = 0;
+        authorizationDataSeqLen = new int[authorizationData.size()];
+        adTypeTagLen = new int[authorizationData.size()];
+        adDataTagLen = new int[authorizationData.size()];
+        authorizationDataSeqLen = new int[authorizationData.size()];
+        
+        for ( AD ad : authorizationData )
+        {
+            int adTypeLen = Value.getNbBytes( ad.adType );
+            adTypeTagLen[i] = 1 + TLV.getNbBytes( adTypeLen ) + adTypeLen;
+            adDataTagLen[i] = 1 + TLV.getNbBytes( ad.adData.length ) + ad.adData.length;
+            
+            authorizationDataSeqLen[i] = 1 + TLV.getNbBytes( adTypeTagLen[i] ) + adTypeTagLen[i]
+ 
+                                         1 + TLV.getNbBytes( adDataTagLen[i] ) + adDataTagLen[i];
+            
+            authorizationDataSeqSeqLen += 1 + TLV.getNbBytes( authorizationDataSeqLen[i]
) + authorizationDataSeqLen[i];
+            i++;
+        }
 
-        return 1 + TLV.getNbBytes( authorizationDataSeqLen ) + authorizationDataSeqLen;
+        return 1 + TLV.getNbBytes(authorizationDataSeqSeqLen) + authorizationDataSeqSeqLen;
     }
 
 
@@ -124,27 +162,31 @@ public class AuthorizationData extends A
 
         try
         {
-            // The AuthorizationData SEQ Tag
+            // The AuthorizationData SEQ OF Tag
             buffer.put( UniversalTag.SEQUENCE.getValue() );
-            buffer.put( TLV.getBytes( authorizationDataSeqLen ) );
-
-            // the adType
-            buffer.put( ( byte ) KerberosConstants.AUTHORIZATION_DATA_ADTYPE_TAG );
-            buffer.put( TLV.getBytes( adTypeTagLen ) );
-
-            Value.encode( buffer, adType );
-
-            // the adData
-            // the adType
-            buffer.put( ( byte ) KerberosConstants.AUTHORIZATION_DATA_ADDATA_TAG );
-            buffer.put( TLV.getBytes( adDataTagLen ) );
-
-            Value.encode( buffer, adData );
+            buffer.put( TLV.getBytes( authorizationDataSeqSeqLen ) );
+            
+            int i = 0;
+            for ( AD ad : authorizationData )
+            {
+                buffer.put( UniversalTag.SEQUENCE.getValue() );
+                buffer.put( TLV.getBytes( authorizationDataSeqLen[i] ) );
+                
+                // the adType
+                buffer.put( ( byte ) KerberosConstants.AUTHORIZATION_DATA_ADTYPE_TAG );
+                buffer.put( TLV.getBytes( adTypeTagLen[i] ) );
+                Value.encode( buffer, ad.adType );
+    
+                // the adData
+                buffer.put( ( byte ) KerberosConstants.AUTHORIZATION_DATA_ADDATA_TAG );
+                buffer.put( TLV.getBytes( adDataTagLen[i] ) );
+                Value.encode( buffer, ad.adData );
+            }
         }
         catch ( BufferOverflowException boe )
         {
-            LOG.error( I18n.err( I18n.ERR_139, 1 + TLV.getNbBytes( authorizationDataSeqLen
)
-                + authorizationDataSeqLen, buffer.capacity() ) );
+            LOG.error( I18n.err( I18n.ERR_139, 1 + TLV.getNbBytes( authorizationDataSeqSeqLen
)
+                + authorizationDataSeqSeqLen, buffer.capacity() ) );
             throw new EncoderException( I18n.err( I18n.ERR_138 ) );
         }
 
@@ -158,27 +200,67 @@ public class AuthorizationData extends A
     }
 
 
-    public int getAdType()
+    /**
+     * @return the currentAD type
+     */
+    public int getCurrentAdType()
     {
-        return adType;
+        return currentAD.adType;
     }
 
 
-    public void setAdType( int adType )
+    /**
+     * Set the current AD type
+     */
+    public void setCurrentAdType( int adType )
     {
-        this.adType = adType;
+        currentAD.adType = adType;
     }
 
 
-    public byte[] getAdData()
+    /**
+     * @return the currentAD data
+     */
+    public byte[] getCurrentAdData()
     {
-        return adData;
+        return currentAD.adData;
     }
 
 
-    public void setAdData( byte[] adData )
+    /**
+     * Set the current AD data
+     */
+    public void setCurrentAdData( byte[] adData )
     {
-        this.adData = adData;
+        currentAD.adData = adData;
+    }
+
+
+    /**
+     * @return the currentAD
+     */
+    public AD getCurrentAD()
+    {
+        return currentAD;
+    }
+
+
+    /**
+     * Create a new currentAD
+     */
+    public void createNewAD()
+    {
+        currentAD = new AD();
+        authorizationData.add( currentAD );
+    }
+
+
+    /**
+     * @return the authorizationData
+     */
+    public List<AD> getAuthorizationData()
+    {
+        return authorizationData;
     }
 
 
@@ -189,10 +271,15 @@ public class AuthorizationData extends A
     {
         StringBuilder sb = new StringBuilder();
 
-        sb.append( "AuthorizationData : {\n" );
-        sb.append( "    adtype: " ).append( adType ).append( '\n' );
-
-        sb.append( "    adData: " ).append( StringTools.dumpBytes( adData ) ).append( "\n}\n"
);
+        sb.append( "AuthorizationData : \n" );
+        
+        for ( AD ad : authorizationData )
+        {
+            sb.append( "    {\n" );
+            sb.append( "        adtype: " ).append( ad.adType ).append( '\n' );
+            sb.append( "        adData: " ).append( StringTools.dumpBytes( ad.adData ) ).append(
'\n');
+            sb.append( "    }\n" );
+        }
 
         return sb.toString();
     }

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AuthorizationDataDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AuthorizationDataDecoderTest.java?rev=1033612&r1=1033611&r2=1033612&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AuthorizationDataDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AuthorizationDataDecoderTest.java
Wed Nov 10 17:47:06 2010
@@ -21,6 +21,7 @@
 package org.apache.directory.shared.kerberos.codec;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -48,14 +49,21 @@ public class AuthorizationDataDecoderTes
     {
         Asn1Decoder kerberosDecoder = new Asn1Decoder();
 
-        ByteBuffer stream = ByteBuffer.allocate( 0x11 );
+        ByteBuffer stream = ByteBuffer.allocate( 0x24 );
         
         stream.put( new byte[]
-            { 0x30, 0xF,
-                (byte)0xA0, 0x03,                 // ad-type
-                  0x02, 0x01, 0x02,
-                (byte)0xA1, 0x08,                 // ad-data
-                  0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f'
+            { 
+              0x30, 0x22,
+                0x30, 0x0F,
+                  (byte)0xA0, 0x03,                 // ad-type
+                    0x02, 0x01, 0x02,
+                  (byte)0xA1, 0x08,                 // ad-data
+                    0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f',
+                0x30, 0x0F,
+                  (byte)0xA0, 0x03,                 // ad-type
+                    0x02, 0x01, 0x02,
+                  (byte)0xA1, 0x08,                 // ad-data
+                    0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l'
             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -74,9 +82,20 @@ public class AuthorizationDataDecoderTes
         }
 
         AuthorizationData authData = authDataContainer.getAuthorizationData();
-        assertEquals( 2, authData.getAdType() );
-        assertTrue( Arrays.equals( StringTools.getBytesUtf8( "abcdef" ), authData.getAdData()
) );
         
+        assertNotNull( authData.getAuthorizationData().size() );
+        assertEquals( 2, authData.getAuthorizationData().size() );
+        
+        String[] expected = new String[]{ "abcdef", "ghijkl" };
+        int i = 0;
+        
+        for ( AuthorizationData.AD ad : authData.getAuthorizationData() )
+        {
+            assertEquals( 2, ad.getAdType() );
+            assertTrue( Arrays.equals( StringTools.getBytesUtf8( expected[i++] ), ad.getAdData()
) );
+            
+        }
+
         // Check the encoding
         ByteBuffer bb = ByteBuffer.allocate( authData.computeLength() );
         
@@ -85,7 +104,7 @@ public class AuthorizationDataDecoderTes
             bb = authData.encode( bb );
     
             // Check the length
-            assertEquals( 0x11, bb.limit() );
+            assertEquals( 0x24, bb.limit() );
     
             String encodedPdu = StringTools.dumpBytes( bb.array() );
     



Mime
View raw message