directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1038606 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/ main/java/org/apache/directory/shared/kerberos/components/ test/java/org/apache/directory/shared/ker...
Date Wed, 24 Nov 2010 14:04:57 GMT
Author: elecharny
Date: Wed Nov 24 14:04:57 2010
New Revision: 1038606

URL: http://svn.apache.org/viewvc?rev=1038606&view=rev
Log:
Added the AuthorizationData grammar

Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/StoreAdType.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/actions/StoreAdType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/StoreAdType.java?rev=1038606&r1=1038605&r2=1038606&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/StoreAdType.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/StoreAdType.java
Wed Nov 24 14:04:57 2010
@@ -21,18 +21,10 @@ package org.apache.directory.shared.kerb
 
 
 import org.apache.directory.shared.asn1.ber.Asn1Container;
-import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
-import org.apache.directory.shared.asn1.ber.tlv.TLV;
-import org.apache.directory.shared.asn1.ber.tlv.Value;
-import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.asn1.util.IntegerDecoder;
-import org.apache.directory.shared.asn1.util.IntegerDecoderException;
-import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadInteger;
 import org.apache.directory.shared.kerberos.codec.authorizationData.AuthorizationDataContainer;
+import org.apache.directory.shared.kerberos.codec.types.AuthorizationType;
 import org.apache.directory.shared.kerberos.components.AuthorizationData;
-import org.apache.directory.shared.ldap.util.StringTools;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -40,15 +32,8 @@ import org.slf4j.LoggerFactory;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class StoreAdType extends GrammarAction
+public class StoreAdType extends AbstractReadInteger
 {
-    /** The logger */
-    private static final Logger LOG = LoggerFactory.getLogger( StoreAdType.class );
-
-    /** Speedup for logs */
-    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
-
-
     /**
      * Instantiates a new AuthorizationDataAdType action.
      */
@@ -61,47 +46,15 @@ public class StoreAdType extends Grammar
     /**
      * {@inheritDoc}
      */
-    public void action( Asn1Container container ) throws DecoderException
+    @Override
+    protected void setIntegerValue( int value, Asn1Container container )
     {
         AuthorizationDataContainer authDataContainer = ( AuthorizationDataContainer ) container;
-
-        TLV tlv = authDataContainer.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 ) );
-        }
-        
-        AuthorizationData authData = authDataContainer.getAuthorizationData();
-
-        // Creates a new AD
-        authData.createNewAD();
         
-        // The AuthorizationData data is an integer
-        Value value = tlv.getValue();
+        AuthorizationType authType = AuthorizationType.getTypeByValue( value );
         
-        try
-        {
-            int adType = IntegerDecoder.parse( value );
-
-            authData.setCurrentAdType( adType );
-
-            if ( IS_DEBUG )
-            {
-                LOG.debug( "adType : " + adType );
-            }
-        }
-        catch ( IntegerDecoderException ide )
-        {
-            LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData() ),
ide
-                .getLocalizedMessage() ) );
-
-            // This will generate a PROTOCOL_ERROR
-            throw new DecoderException( ide.getMessage() );
-        }
+        AuthorizationData authorizationData = authDataContainer.getAuthorizationData();
+        authorizationData.createNewAD();
+        authorizationData.setCurrentAdType( authType );
     }
 }

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=1038606&r1=1038605&r2=1038606&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 24 14:04:57 2010
@@ -33,6 +33,7 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.codec.types.AuthorizationType;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -55,7 +56,7 @@ public class AuthorizationData extends A
     public class AD
     {
         /** the type of authorization data */
-        private int adType;
+        private AuthorizationType adType;
 
         /** the authorization data */
         private byte[] adData;
@@ -63,7 +64,7 @@ public class AuthorizationData extends A
         /**
          * @return the adType
          */
-        public int getAdType()
+        public AuthorizationType getAdType()
         {
             return adType;
         }
@@ -131,7 +132,7 @@ public class AuthorizationData extends A
         
         for ( AD ad : authorizationData )
         {
-            int adTypeLen = Value.getNbBytes( ad.adType );
+            int adTypeLen = Value.getNbBytes( ad.adType.getValue() );
             adTypeTagLen[i] = 1 + TLV.getNbBytes( adTypeLen ) + adTypeLen;
             adDataTagLen[i] = 1 + TLV.getNbBytes( ad.adData.length ) + ad.adData.length;
             
@@ -176,7 +177,7 @@ public class AuthorizationData extends A
                 // the adType
                 buffer.put( ( byte ) KerberosConstants.AUTHORIZATION_DATA_ADTYPE_TAG );
                 buffer.put( TLV.getBytes( adTypeTagLen[i] ) );
-                Value.encode( buffer, ad.adType );
+                Value.encode( buffer, ad.adType.getValue() );
     
                 // the adData
                 buffer.put( ( byte ) KerberosConstants.AUTHORIZATION_DATA_ADDATA_TAG );
@@ -204,7 +205,7 @@ public class AuthorizationData extends A
     /**
      * @return the currentAD type
      */
-    public int getCurrentAdType()
+    public AuthorizationType getCurrentAdType()
     {
         return currentAD.adType;
     }
@@ -213,7 +214,7 @@ public class AuthorizationData extends A
     /**
      * Set the current AD type
      */
-    public void setCurrentAdType( int adType )
+    public void setCurrentAdType( AuthorizationType adType )
     {
         currentAD.adType = adType;
     }

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=1038606&r1=1038605&r2=1038606&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 24 14:04:57 2010
@@ -32,6 +32,7 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.kerberos.codec.authorizationData.AuthorizationDataContainer;
+import org.apache.directory.shared.kerberos.codec.types.AuthorizationType;
 import org.apache.directory.shared.kerberos.components.AuthorizationData;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
@@ -91,7 +92,7 @@ public class AuthorizationDataDecoderTes
         
         for ( AuthorizationData.AD ad : authData.getAuthorizationData() )
         {
-            assertEquals( 2, ad.getAdType() );
+            assertEquals( AuthorizationType.AD_INTENDED_FOR_SERVER, ad.getAdType() );
             assertTrue( Arrays.equals( StringTools.getBytesUtf8( expected[i++] ), ad.getAdData()
) );
             
         }



Mime
View raw message