directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1041412 - in /directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/components/ test/java/org/apache/directory/shared/kerberos/codec/
Date Thu, 02 Dec 2010 15:35:53 GMT
Author: elecharny
Date: Thu Dec  2 15:35:52 2010
New Revision: 1041412

URL: http://svn.apache.org/viewvc?rev=1041412&view=rev
Log:
Extracted the AuthorizationData.AD class from AuthorizationData, and renamed it AuthorizationDataEntry

Added:
    directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationDataEntry.java
Modified:
    directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java
    directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdIfRelevantDecoderTest.java
    directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdKdcIssuedDecoderTest.java
    directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdMandatoryForKdcDecoderTest.java
    directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AuthorizationDataDecoderTest.java

Modified: directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java?rev=1041412&r1=1041411&r2=1041412&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java
(original)
+++ directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java
Thu Dec  2 15:35:52 2010
@@ -24,7 +24,6 @@ package org.apache.directory.shared.kerb
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 import org.apache.directory.server.i18n.I18n;
@@ -53,89 +52,11 @@ 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 AuthorizationType adType;
-
-        /** the authorization data */
-        private byte[] adData;
-
-        /**
-         * @return the adType
-         */
-        public AuthorizationType getAdType()
-        {
-            return adType;
-        }
-
-        /**
-         * @return the adData
-         */
-        public byte[] getAdData()
-        {
-            return adData;
-        }
-        
-
-        /**
-         * {@inheritDoc}
-         */
-        @Override
-        public int hashCode()
-        {
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + getOuterType().hashCode();
-            result = prime * result + Arrays.hashCode( adData );
-            result = prime * result + ( ( adType == null ) ? 0 : adType.hashCode() );
-            return result;
-        }
-
-        /**
-         * {@inheritDoc}
-         */
-        @Override
-        public boolean equals( Object obj )
-        {
-            if ( this == obj )
-            {
-                return true;
-            }
-            
-            if ( obj == null )
-            {
-                return false;
-            }
-            
-            AD other = ( AD ) obj;
-            
-            if ( !Arrays.equals( adData, other.adData ) )
-            {
-                return false;
-            }
-            
-            if ( adType != other.adType )
-            {
-                return false;
-            }
-
-            return true;
-        }
-
-        private AuthorizationData getOuterType()
-        {
-            return AuthorizationData.this;
-        }
-        
-    }
-    
     /** The list of AuthorizationData elements */
-    private List<AD> authorizationData = new ArrayList<AD>();
+    private List<AuthorizationDataEntry> authorizationData = new ArrayList<AuthorizationDataEntry>();
     
     /** The current AD being processed */
-    private AD currentAD;
+    private AuthorizationDataEntry currentAD;
 
     /** The logger */
     private static final Logger LOG = LoggerFactory.getLogger( EncryptedData.class );
@@ -182,11 +103,11 @@ public class AuthorizationData extends A
         adTypeTagLen = new int[authorizationData.size()];
         adDataTagLen = new int[authorizationData.size()];
         
-        for ( AD ad : authorizationData )
+        for ( AuthorizationDataEntry ad : authorizationData )
         {
-            int adTypeLen = Value.getNbBytes( ad.adType.getValue() );
+            int adTypeLen = Value.getNbBytes( ad.getAdType().getValue() );
             adTypeTagLen[i] = 1 + TLV.getNbBytes( adTypeLen ) + adTypeLen;
-            adDataTagLen[i] = 1 + TLV.getNbBytes( ad.adData.length ) + ad.adData.length;
+            adDataTagLen[i] = 1 + TLV.getNbBytes( ad.getAdDataRef().length ) + ad.getAdDataRef().length;
             
             authorizationDataSeqLen[i] = 1 + TLV.getNbBytes( adTypeTagLen[i] ) + adTypeTagLen[i]
+ 
                                          1 + TLV.getNbBytes( adDataTagLen[i] ) + adDataTagLen[i];
@@ -221,7 +142,8 @@ public class AuthorizationData extends A
             buffer.put( TLV.getBytes( authorizationDataSeqSeqLen ) );
             
             int i = 0;
-            for ( AD ad : authorizationData )
+            
+            for ( AuthorizationDataEntry ad : authorizationData )
             {
                 buffer.put( UniversalTag.SEQUENCE.getValue() );
                 buffer.put( TLV.getBytes( authorizationDataSeqLen[i] ) );
@@ -229,12 +151,12 @@ 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.getValue() );
+                Value.encode( buffer, ad.getAdType().getValue() );
     
                 // the adData
                 buffer.put( ( byte ) KerberosConstants.AUTHORIZATION_DATA_ADDATA_TAG );
                 buffer.put( TLV.getBytes( adDataTagLen[i] ) );
-                Value.encode( buffer, ad.adData );
+                Value.encode( buffer, ad.getAdDataRef() );
                 
                 i++;
             }
@@ -261,7 +183,7 @@ public class AuthorizationData extends A
      */
     public AuthorizationType getCurrentAdType()
     {
-        return currentAD.adType;
+        return currentAD.getAdType();
     }
 
 
@@ -270,7 +192,7 @@ public class AuthorizationData extends A
      */
     public void setCurrentAdType( AuthorizationType adType )
     {
-        currentAD.adType = adType;
+        currentAD.setAdType( adType );
     }
 
 
@@ -279,7 +201,7 @@ public class AuthorizationData extends A
      */
     public byte[] getCurrentAdData()
     {
-        return currentAD.adData;
+        return currentAD.getAdData();
     }
 
 
@@ -288,14 +210,14 @@ public class AuthorizationData extends A
      */
     public void setCurrentAdData( byte[] adData )
     {
-        currentAD.adData = adData;
+        currentAD.setAdData( adData );
     }
 
 
     /**
      * @return the currentAD
      */
-    public AD getCurrentAD()
+    public AuthorizationDataEntry getCurrentAD()
     {
         return currentAD;
     }
@@ -306,7 +228,7 @@ public class AuthorizationData extends A
      */
     public void createNewAD()
     {
-        currentAD = new AD();
+        currentAD = new AuthorizationDataEntry();
         authorizationData.add( currentAD );
     }
 
@@ -314,7 +236,7 @@ public class AuthorizationData extends A
     /**
      * @return the authorizationData
      */
-    public List<AD> getAuthorizationData()
+    public List<AuthorizationDataEntry> getAuthorizationData()
     {
         return authorizationData;
     }
@@ -393,12 +315,9 @@ public class AuthorizationData extends A
 
         sb.append( tabs ).append( "AuthorizationData : \n" );
         
-        for ( AD ad : authorizationData )
+        for ( AuthorizationDataEntry ad : authorizationData )
         {
-            sb.append( tabs ).append( "    {\n" );
-            sb.append( tabs ).append( "        adtype: " ).append( ad.adType ).append( '\n'
);
-            sb.append( tabs ).append( "        adData: " ).append( StringTools.dumpBytes(
ad.adData ) ).append( '\n');
-            sb.append( tabs ).append( "    }\n" );
+            sb.append( tabs ).append( ad );
         }
 
         return sb.toString();

Added: directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationDataEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationDataEntry.java?rev=1041412&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationDataEntry.java
(added)
+++ directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationDataEntry.java
Thu Dec  2 15:35:52 2010
@@ -0,0 +1,190 @@
+/*
+ *  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.components;
+
+import java.util.Arrays;
+
+import org.apache.directory.shared.kerberos.codec.types.AuthorizationType;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+/**
+ * The class storing the individual AuthorizationDatas
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AuthorizationDataEntry
+{
+    /** the type of authorization data */
+    private AuthorizationType adType;
+
+    /** the authorization data */
+    private byte[] adData;
+    
+    /**
+     * Creates a new instance of AD entry
+     */
+    public AuthorizationDataEntry()
+    {
+        
+    }
+    
+    
+    /**
+     * Creates a new Instance of AD entry
+     * 
+     * @param adType The AuthorizationData type
+     * @param adData The AuthorizationData data
+     */
+    public AuthorizationDataEntry( AuthorizationType adType, byte[] adData )
+    {
+        this.adType = adType;
+        
+        if ( adData != null )
+        {
+            this.adData = new byte[adData.length];
+            System.arraycopy( adData, 0, this.adData, 0, adData.length );
+        }
+    }
+
+    
+    /**
+     * @return the adType
+     */
+    public AuthorizationType getAdType()
+    {
+        return adType;
+    }
+
+
+    /**
+     * @param adType the adType to set
+     */
+    public void setAdType( AuthorizationType adType )
+    {
+        this.adType = adType;
+    }
+
+
+    /**
+     * @return a copy of adData
+     */
+    public byte[] getAdData()
+    {
+        if ( StringTools.isEmpty( adData ) )
+        {
+            return StringTools.EMPTY_BYTES;
+        }
+        else
+        {
+            byte[] copy = new byte[adData.length];
+            
+            System.arraycopy( adData, 0, copy, 0, adData.length );
+            
+            return copy;
+        }
+    }
+    
+
+    /**
+     * @return the reference on adData
+     */
+    public byte[] getAdDataRef()
+    {
+        return adData;
+    }
+    
+
+    /**
+     * @param adData the adData to set
+     */
+    public void setAdData( byte[] adData )
+    {
+        if ( StringTools.isEmpty( adData ) )
+        {
+            this.adData = StringTools.EMPTY_BYTES;
+        }
+        else
+        {
+            this.adData = new byte[adData.length];
+            
+            System.arraycopy( adData, 0, this.adData, 0, adData.length );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 17;
+        result = prime * result + Arrays.hashCode( adData );
+        result = prime * result + ( ( adType == null ) ? 0 : adType.hashCode() );
+        return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( this == obj )
+        {
+            return true;
+        }
+        
+        if ( obj == null )
+        {
+            return false;
+        }
+        
+        AuthorizationDataEntry other = ( AuthorizationDataEntry ) obj;
+        
+        if ( !Arrays.equals( adData, other.adData ) )
+        {
+            return false;
+        }
+        
+        if ( adType != other.adType )
+        {
+            return false;
+        }
+
+        return true;
+    }
+    
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( "AuthorizationDataEntry : {\n" );
+        sb.append( "    adType : " ).append( adType ).append( "\n" );
+        sb.append( "    adData : " ).append( StringTools.dumpBytes( adData ) ).append( "\n"
);
+        sb.append( "}" );
+        return sb.toString();
+    }
+}
+

Modified: directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdIfRelevantDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdIfRelevantDecoderTest.java?rev=1041412&r1=1041411&r2=1041412&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdIfRelevantDecoderTest.java
(original)
+++ directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdIfRelevantDecoderTest.java
Thu Dec  2 15:35:52 2010
@@ -34,7 +34,7 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.kerberos.codec.adIfRelevant.AdIfRelevantContainer;
 import org.apache.directory.shared.kerberos.codec.types.AuthorizationType;
 import org.apache.directory.shared.kerberos.components.AdIfRelevant;
-import org.apache.directory.shared.kerberos.components.AuthorizationData;
+import org.apache.directory.shared.kerberos.components.AuthorizationDataEntry;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
 
@@ -91,7 +91,7 @@ public class AdIfRelevantDecoderTest
         String[] expected = new String[]{ "abcdef", "ghijkl" };
         int i = 0;
         
-        for ( AuthorizationData.AD ad : adIfRelevant.getAuthorizationData() )
+        for ( AuthorizationDataEntry ad : adIfRelevant.getAuthorizationData() )
         {
             assertEquals( AuthorizationType.AD_INTENDED_FOR_SERVER, ad.getAdType() );
             assertTrue( Arrays.equals( StringTools.getBytesUtf8( expected[i++] ), ad.getAdData()
) );

Modified: directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdKdcIssuedDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdKdcIssuedDecoderTest.java?rev=1041412&r1=1041411&r2=1041412&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdKdcIssuedDecoderTest.java
(original)
+++ directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdKdcIssuedDecoderTest.java
Thu Dec  2 15:35:52 2010
@@ -40,6 +40,7 @@ import org.apache.directory.shared.kerbe
 import org.apache.directory.shared.kerberos.codec.types.PrincipalNameType;
 import org.apache.directory.shared.kerberos.components.AdKdcIssued;
 import org.apache.directory.shared.kerberos.components.AuthorizationData;
+import org.apache.directory.shared.kerberos.components.AuthorizationDataEntry;
 import org.apache.directory.shared.kerberos.components.Checksum;
 import org.apache.directory.shared.kerberos.components.PrincipalName;
 import org.apache.directory.shared.kerberos.crypto.checksum.ChecksumType;
@@ -139,7 +140,7 @@ public class AdKdcIssuedDecoderTest
         String[] expected = new String[]{ "abcdef", "ghijkl" };
         int i = 0;
         
-        for ( AuthorizationData.AD ad : authData.getAuthorizationData() )
+        for ( AuthorizationDataEntry ad : authData.getAuthorizationData() )
         {
             assertEquals( AuthorizationType.AD_INTENDED_FOR_SERVER, ad.getAdType() );
             assertTrue( Arrays.equals( StringTools.getBytesUtf8( expected[i++] ), ad.getAdData()
) );
@@ -242,7 +243,7 @@ public class AdKdcIssuedDecoderTest
         String[] expected = new String[]{ "abcdef", "ghijkl" };
         int i = 0;
         
-        for ( AuthorizationData.AD ad : authData.getAuthorizationData() )
+        for ( AuthorizationDataEntry ad : authData.getAuthorizationData() )
         {
             assertEquals( AuthorizationType.AD_INTENDED_FOR_SERVER, ad.getAdType() );
             assertTrue( Arrays.equals( StringTools.getBytesUtf8( expected[i++] ), ad.getAdData()
) );

Modified: directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdMandatoryForKdcDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdMandatoryForKdcDecoderTest.java?rev=1041412&r1=1041411&r2=1041412&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdMandatoryForKdcDecoderTest.java
(original)
+++ directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdMandatoryForKdcDecoderTest.java
Thu Dec  2 15:35:52 2010
@@ -34,7 +34,7 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.kerberos.codec.adMandatoryForKdc.AdMandatoryForKdcContainer;
 import org.apache.directory.shared.kerberos.codec.types.AuthorizationType;
 import org.apache.directory.shared.kerberos.components.AdMandatoryForKdc;
-import org.apache.directory.shared.kerberos.components.AuthorizationData;
+import org.apache.directory.shared.kerberos.components.AuthorizationDataEntry;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
 
@@ -91,7 +91,7 @@ public class AdMandatoryForKdcDecoderTes
         String[] expected = new String[]{ "abcdef", "ghijkl" };
         int i = 0;
         
-        for ( AuthorizationData.AD ad : adMandatoryForKdc.getAuthorizationData() )
+        for ( AuthorizationDataEntry ad : adMandatoryForKdc.getAuthorizationData() )
         {
             assertEquals( AuthorizationType.AD_INTENDED_FOR_SERVER, ad.getAdType() );
             assertTrue( Arrays.equals( StringTools.getBytesUtf8( expected[i++] ), ad.getAdData()
) );

Modified: directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AuthorizationDataDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AuthorizationDataDecoderTest.java?rev=1041412&r1=1041411&r2=1041412&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AuthorizationDataDecoderTest.java
(original)
+++ directory/apacheds/branches/apacheds-kerberos-codec-2.0/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AuthorizationDataDecoderTest.java
Thu Dec  2 15:35:52 2010
@@ -34,6 +34,7 @@ import org.apache.directory.shared.asn1.
 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.kerberos.components.AuthorizationDataEntry;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
 
@@ -90,7 +91,7 @@ public class AuthorizationDataDecoderTes
         String[] expected = new String[]{ "abcdef", "ghi" };
         int i = 0;
         
-        for ( AuthorizationData.AD ad : authData.getAuthorizationData() )
+        for ( AuthorizationDataEntry ad : authData.getAuthorizationData() )
         {
             assertEquals( AuthorizationType.AD_INTENDED_FOR_SERVER, ad.getAdType() );
             assertTrue( Arrays.equals( StringTools.getBytesUtf8( expected[i++] ), ad.getAdData()
) );



Mime
View raw message