directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r587531 - in /directory/apacheds/branches/bigbang/kerberos-shared/src: main/java/org/apache/directory/server/kerberos/shared/io/decoder/ main/java/org/apache/directory/server/kerberos/shared/io/encoder/ main/java/org/apache/directory/server...
Date Tue, 23 Oct 2007 14:59:13 GMT
Author: elecharny
Date: Tue Oct 23 07:59:10 2007
New Revision: 587531

URL: http://svn.apache.org/viewvc?rev=587531&view=rev
Log:
Modified the AuthorizationData class, and the AuthorizationType enum.

Added tests for HostAddresses and AuthorizationData

Added:
    directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/types/AuthorizationType.java
    directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataTest.java
    directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressesTest.java
Removed:
    directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationType.java
Modified:
    directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/AuthorizationDataDecoder.java
    directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/AuthorizationDataEncoder.java
    directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationData.java
    directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataEntry.java

Modified: directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/AuthorizationDataDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/AuthorizationDataDecoder.java?rev=587531&r1=587530&r2=587531&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/AuthorizationDataDecoder.java
(original)
+++ directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/AuthorizationDataDecoder.java
Tue Oct 23 07:59:10 2007
@@ -26,7 +26,7 @@
 import org.apache.directory.server.kerberos.shared.messages.Encodable;
 import org.apache.directory.server.kerberos.shared.messages.value.AuthorizationData;
 import org.apache.directory.server.kerberos.shared.messages.value.AuthorizationDataEntry;
-import org.apache.directory.server.kerberos.shared.messages.value.AuthorizationType;
+import org.apache.directory.server.kerberos.shared.messages.value.types.AuthorizationType;
 import org.apache.directory.shared.asn1.der.ASN1InputStream;
 import org.apache.directory.shared.asn1.der.DEREncodable;
 import org.apache.directory.shared.asn1.der.DERInteger;
@@ -67,7 +67,7 @@
     {
         AuthorizationData authData = new AuthorizationData();
 
-        for ( Enumeration e = sequence.getObjects(); e.hasMoreElements(); )
+        for ( Enumeration<DEREncodable> e = sequence.getObjects(); e.hasMoreElements();
)
         {
             DERSequence object = ( DERSequence ) e.nextElement();
             AuthorizationDataEntry entry = decodeAuthorizationEntry( object );
@@ -83,7 +83,7 @@
         AuthorizationType type = AuthorizationType.NULL;
         byte[] data = null;
 
-        for ( Enumeration e = sequence.getObjects(); e.hasMoreElements(); )
+        for ( Enumeration<DEREncodable> e = sequence.getObjects(); e.hasMoreElements();
)
         {
             DERTaggedObject object = ( DERTaggedObject ) e.nextElement();
             int tag = object.getTagNo();
@@ -95,6 +95,7 @@
                     DERInteger tag0 = ( DERInteger ) derObject;
                     type = AuthorizationType.getTypeByOrdinal( tag0.intValue() );
                     break;
+                    
                 case 1:
                     DEROctetString tag1 = ( DEROctetString ) derObject;
                     data = tag1.getOctets();

Modified: directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/AuthorizationDataEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/AuthorizationDataEncoder.java?rev=587531&r1=587530&r2=587531&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/AuthorizationDataEncoder.java
(original)
+++ directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/AuthorizationDataEncoder.java
Tue Oct 23 07:59:10 2007
@@ -20,8 +20,6 @@
 package org.apache.directory.server.kerberos.shared.io.encoder;
 
 
-import java.util.Iterator;
-
 import org.apache.directory.server.kerberos.shared.messages.value.AuthorizationData;
 import org.apache.directory.server.kerberos.shared.messages.value.AuthorizationDataEntry;
 import org.apache.directory.shared.asn1.der.DERInteger;
@@ -44,16 +42,13 @@
      */
     protected static DERSequence encode( AuthorizationData data )
     {
-        Iterator it = data.iterator();
         DERSequence outerSequence = new DERSequence();
 
-        while ( it.hasNext() )
+        for ( AuthorizationDataEntry entry: data.getEntries() )
         {
-            AuthorizationDataEntry entry = ( AuthorizationDataEntry ) it.next();
             DERSequence sequence = new DERSequence();
-            sequence
-                .add( new DERTaggedObject( 0, DERInteger.valueOf( entry.getAuthorizationDataType().getOrdinal()
) ) );
-            sequence.add( new DERTaggedObject( 1, new DEROctetString( entry.getAuthorizationData()
) ) );
+            sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( entry.getAdType().getOrdinal()
) ) );
+            sequence.add( new DERTaggedObject( 1, new DEROctetString( entry.getAdData() )
) );
             outerSequence.add( sequence );
         }
 

Modified: directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationData.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationData.java?rev=587531&r1=587530&r2=587531&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationData.java
(original)
+++ directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationData.java
Tue Oct 23 07:59:10 2007
@@ -20,21 +20,47 @@
 package org.apache.directory.server.kerberos.shared.messages.value;
 
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.directory.server.kerberos.shared.messages.Encodable;
+import org.apache.directory.shared.asn1.AbstractAsn1Object;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
+ * An authorization data container.
+ * 
+ * The ASN.1 grammar is :
+ * 
+ * -- NOTE: AuthorizationData is always used as an OPTIONAL field and
+ * -- should not be empty.
+ * AuthorizationData       ::= SEQUENCE OF AuthorizationDataEntry
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class AuthorizationData implements Encodable
+public class AuthorizationData extends AbstractAsn1Object implements Encodable
 {
+    /** The logger */
+    private static final Logger log = LoggerFactory.getLogger( AuthorizationData.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+    /** The list of AuthrorizationData elements */
     private List<AuthorizationDataEntry> entries = new ArrayList<AuthorizationDataEntry>();
 
+    // Storage for computed lengths
+    private transient int authorizationDataLength;
+
 
     /**
      * Creates a new instance of AuthorizationData.
@@ -68,12 +94,148 @@
 
 
     /**
-     * Returns an {@link Iterator} over the entries in this {@link AuthorizationData}.
-     *
-     * @return An {@link Iterator} over the entries in this {@link AuthorizationData}.
+     * @return The AuthorizationdataEntry list
+     */
+    public List<AuthorizationDataEntry> getEntries()
+    {
+        return entries;
+    }
+
+
+    /**
+     * Compute the AuthorizationData length
+     * 
+     * AuthorizationData :
+     * 
+     * 0x30 L1 AuthorizationData
+     *  |
+     *  +--> 0x30 L2 AuthorizationDataEntry
+     *  |
+     *  +--> 0x30 L2 AuthorizationDataEntry
+     *  |
+     *  ...
+     *  |
+     *  +--> 0x30 L2 AuthorizationDataEntry
+     */
+    public int computeLength()
+    {
+        if ( ( entries == null ) || ( entries.size() == 0 ) )
+        {
+            authorizationDataLength = 1;
+
+            return authorizationDataLength + 1;
+        }
+        else
+        {
+            authorizationDataLength = 0;
+
+            for ( AuthorizationDataEntry entry : entries )
+            {
+                authorizationDataLength += entry.computeLength();
+            }
+
+            return 1 + TLV.getNbBytes( authorizationDataLength ) + authorizationDataLength;
+        }
+    }
+
+
+    /**
+     * Encode the AuthorizationData message to a PDU. 
+     * 
+     * AuthorizationData :
+     * 
+     * 0x30 LL
+     *   0x30 LL AuthorizationDataEntry 
+     *   0x30 LL AuthorizationDataEntry
+     *   ... 
+     *   0x30 LL AuthorizationDataEntry 
+     * 
+     * @param buffer The buffer where to put the PDU. It should have been allocated
+     * before, with the right size.
+     * @return The constructed PDU.
      */
-    public Iterator iterator()
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
     {
-        return entries.iterator();
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try
+        {
+            // The AuthorizationData SEQ Tag
+            buffer.put( UniversalTag.SEQUENCE_TAG );
+            buffer.put( TLV.getBytes( authorizationDataLength ) );
+
+            // Each entry, if any
+            if ( ( entries != null ) && ( entries.size() != 0 ) )
+            {
+                for ( AuthorizationDataEntry entry : entries )
+                {
+                    entry.encode( buffer );
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            log.error(
+                "Cannot encode the AuthorizationData object, the PDU size is {} when only
{} bytes has been allocated",
+                1 + TLV.getNbBytes( authorizationDataLength ) + authorizationDataLength,
buffer.capacity() );
+            throw new EncoderException( "The PDU buffer size is too small !" );
+        }
+
+        if ( IS_DEBUG )
+        {
+            log.debug( "AuthorizationData encoding : {}", StringTools.dumpBytes( buffer.array()
) );
+            log.debug( "AuthorizationData initial value : {}", toString() );
+        }
+
+        return buffer;
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return toString( "" );
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString( String tabs )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        if ( ( entries == null ) || ( entries.size() == 0 ) )
+        {
+            sb.append( tabs ).append( "AuthorizationData : {}\n" );
+        }
+        else
+        {
+            sb.append( tabs ).append( "AuthorizationData : {\n" );
+            boolean isFirst = true;
+
+            for ( AuthorizationDataEntry entry : entries )
+            {
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    sb.append( '\n' );
+                }
+
+                sb.append( entry.toString( tabs + "    " ) ).append( '\n' );
+            }
+
+            sb.append( tabs + "}" );
+        }
+
+        return sb.toString();
     }
 }

Modified: directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataEntry.java?rev=587531&r1=587530&r2=587531&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataEntry.java
(original)
+++ directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataEntry.java
Tue Oct 23 07:59:10 2007
@@ -20,26 +20,77 @@
 package org.apache.directory.server.kerberos.shared.messages.value;
 
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.kerberos.shared.messages.value.types.AuthorizationType;
+import org.apache.directory.shared.asn1.AbstractAsn1Object;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
 /**
+ * A single AuthorizationData
+ * 
+ * The ASN.1 grammar is :
+ * -- NOTE: AuthorizationData is always used as an OPTIONAL field and
+ * -- should not be empty.
+ * AuthorizationDataEntry       ::= SEQUENCE {
+ *        ad-type         [0] Int32,
+ *        ad-data         [1] OCTET STRING
+ * }
+ *  
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class AuthorizationDataEntry
+public class AuthorizationDataEntry extends AbstractAsn1Object
 {
-    private AuthorizationType authorizationDataType;
-    private byte[] authorizationData;
+    /** The logger */
+    private static final Logger log = LoggerFactory.getLogger( AuthorizationDataEntry.class
);
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+    /** The Authorization type. One of :
+     * DER encoding of AD-IF-RELEVANT        1
+     * DER encoding of AD-KDCIssued          4
+     * DER encoding of AD-AND-OR             5
+     * DER encoding of AD-MANDATORY-FOR-KDC  8 
+     **/
+    private AuthorizationType adType;
+
+    /** The data, encrypted */
+    private byte[] adData;
+
+    // Storage for computed lengths
+    private transient int adTypeLength;
+    private transient int adDataLength;
+    private transient int authorizationDataEntryLength;
 
 
     /**
      * Creates a new instance of AuthorizationDataEntry.
+     */
+    public AuthorizationDataEntry()
+    {
+    }
+
+    
+    /**
+     * Creates a new instance of AuthorizationDataEntry.
      *
-     * @param adType
-     * @param adData
+     * @param adType The authorizationType
+     * @param adData The authorization data
      */
     public AuthorizationDataEntry( AuthorizationType adType, byte[] adData )
     {
-        authorizationDataType = adType;
-        authorizationData = adData;
+        this.adType = adType;
+        this.adData = adData;
     }
 
 
@@ -48,19 +99,182 @@
      *
      * @return The raw bytes of the authorization data.
      */
-    public byte[] getAuthorizationData()
+    public byte[] getAdData()
     {
-        return authorizationData;
+        return adData;
     }
 
 
     /**
+     * Set the authorization data
+     * 
+     * @param adData The data
+     */
+    public void setAdData( byte[] adData ) 
+    {
+        this.adData = adData;
+    }
+
+    
+    /**
      * Returns the {@link AuthorizationType}.
      *
      * @return The {@link AuthorizationType}.
      */
-    public AuthorizationType getAuthorizationDataType()
+    public AuthorizationType getAdType()
+    {
+        return adType;
+    }
+
+
+    /**
+     * Set the authorization type
+     * @param adType The authorization type
+     */
+    public void setAdType( int adType ) 
+    {
+        this.adType = AuthorizationType.getTypeByOrdinal( adType );
+    }
+
+    
+    /**
+     * Set the authorization type
+     * @param adType The authorization type
+     */
+    public void setAdType( AuthorizationType adType ) 
     {
-        return authorizationDataType;
+        this.adType = adType;
+    }
+
+    
+    /**
+     * Compute the AuthorizationDataEntry length
+     * 
+     * AuthorizationDataEntry :
+     * 
+     * 0x30 L1 AuthorizationDataEntry
+     *  |
+     *  +--> 0xA0 L2 adType tag
+     *  |     |
+     *  |     +--> 0x02 L2-1 adType (int)
+     *  |
+     *  +--> 0xA1 L3 adData tag
+     *        |
+     *        +--> 0x04 L3-1 adData (OCTET STRING)
+     *        
+     *  where L1 = L2 + lenght(0xA0) + length(L2) +
+     *             L3 + lenght(0xA1) + length(L3) 
+     *  and
+     *  L2 = L2-1 + length(0x02) + length( L2-1) 
+     *  L3 = L3-1 + length(0x04) + length( L3-1) 
+     */
+    public int computeLength()
+    {
+        // Compute the adType. The Length will always be contained in 1 byte
+        adTypeLength = 1 + 1 + Value.getNbBytes( adType.getOrdinal() );
+        authorizationDataEntryLength = 1 + TLV.getNbBytes( adTypeLength ) + adTypeLength;
+
+        // Compute the keyValue
+        if ( adData == null )
+        {
+            adDataLength = 1 + 1;
+        }
+        else
+        {
+            adDataLength = 1 + TLV.getNbBytes( adData.length ) + adData.length;
+        }
+
+        authorizationDataEntryLength += 1 + TLV.getNbBytes( adDataLength ) + adDataLength;
+
+        // Compute the whole sequence length
+        int authorizationDataEntrySeqLength = 1 + Value.getNbBytes( authorizationDataEntryLength
)
+            + authorizationDataEntryLength;
+
+        return authorizationDataEntrySeqLength;
+
+    }
+
+
+    /**
+     * Encode the AuthorizationDataEntry message to a PDU. 
+     * 
+     * AuthorizationDataEntry :
+     * 
+     * 0x30 LL
+     *   0xA0 LL 
+     *     0x02 0x01 adType
+     *   0xA1 LL 
+     *     0x04 LL adData
+     * 
+     * @param buffer The buffer where to put the PDU. It should have been allocated
+     * before, with the right size.
+     * @return The constructed PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try
+        {
+            // The AuthorizationDataEntry SEQ Tag
+            buffer.put( UniversalTag.SEQUENCE_TAG );
+            buffer.put( TLV.getBytes( authorizationDataEntryLength ) );
+
+            // The adType, first the tag, then the value
+            buffer.put( ( byte ) 0xA0 );
+            buffer.put( TLV.getBytes( adTypeLength ) );
+            Value.encode( buffer, adType.getOrdinal() );
+
+            // The adData, first the tag, then the value
+            buffer.put( ( byte ) 0xA1 );
+            buffer.put( TLV.getBytes( adDataLength ) );
+            Value.encode( buffer, adData );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            log
+                .error(
+                    "Cannot encode the AuthorizationDataEntry object, the PDU size is {}
when only {} bytes has been allocated",
+                    1 + TLV.getNbBytes( authorizationDataEntryLength ) + authorizationDataEntryLength,
buffer
+                        .capacity() );
+            throw new EncoderException( "The PDU buffer size is too small !" );
+        }
+
+        if ( IS_DEBUG )
+        {
+            log.debug( "AuthorizationDataEntry encoding : {}", StringTools.dumpBytes( buffer.array()
) );
+            log.debug( "AuthorizationDataEntry initial value : {}", toString() );
+        }
+
+        return buffer;
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return toString( "    " );
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString( String tabs )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( tabs ).append( "AuthorizationDataEntry : {\n" );
+        sb.append( tabs ).append( "    ad-type: " ).append( adType ).append( '\n' );
+
+        sb.append( tabs ).append( "    ad-data: " ).append( StringTools.dumpBytes( adData
) )
+            .append( "\n" + tabs + "}" );
+
+        return sb.toString();
     }
 }

Added: directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/types/AuthorizationType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/types/AuthorizationType.java?rev=587531&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/types/AuthorizationType.java
(added)
+++ directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/types/AuthorizationType.java
Tue Oct 23 07:59:10 2007
@@ -0,0 +1,229 @@
+/*
+ *  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.server.kerberos.shared.messages.value.types;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 540371 $, $Date: 2007-05-22 02:00:43 +0200 (Tue, 22 May 2007) $
+ */
+public enum AuthorizationType
+{
+    /**
+     * Constant for the "null" authorization type.
+     */
+    NULL( 0 ),
+
+    /**
+     * Constant for the "if relevant" authorization type.
+     * 
+     * RFC 4120
+     */
+    AD_IF_RELEVANT( 1 ),
+
+    /**
+     * Constant for the "intended for server" authorization type.
+     * 
+     * RFC 4120
+     */
+    AD_INTENDED_FOR_SERVER( 2 ),
+
+    /**
+     * Constant for the  "intended for application class" authorization type.
+     * 
+     * RFC 4120
+     */
+    AD_INTENDED_FOR_APPLICATION_CLASS( 3 ),
+
+    /**
+     * Constant for the "kdc issued" authorization type.
+     * 
+     * RFC 4120
+     */
+    AD_KDC_ISSUED( 4 ),
+
+    /**
+     * Constant for the "or" authorization type.
+     * 
+     * RFC 4120
+     */
+    AD_OR( 5 ),
+
+    /**
+     * Constant for the "mandatory ticket extensions" authorization type.
+     * 
+     * RFC 4120
+     */
+    AD_MANDATORY_TICKET_EXTENSIONS( 6 ),
+
+    /**
+     * Constant for the "in ticket extensions" authorization type.
+     * 
+     * RFC 4120
+     */
+    AD_IN_TICKET_EXTENSIONS( 7 ),
+
+    /**
+     * Constant for the "mandatory-for-kdc" authorization type.
+     * 
+     * RFC 4120
+     */
+    AD_MANDATORY_FOR_KDC( 8 ),
+
+    /**
+     * Constant for the "OSF DCE" authorization type.
+     * 
+     * RFC 1510
+     */
+    OSF_DCE( 64 ),
+
+    /**
+     * Constant for the "sesame" authorization type.
+     * 
+     * RFC 1510
+     */
+    SESAME( 65 ),
+
+    /**
+     * Constant for the "OSF-DCE pki certid" authorization type.
+     * 
+     * RFC 1510
+     */
+    AD_OSF_DCE_PKI_CERTID( 66 ),
+
+    /**
+     * Constant for the "sesame" authorization type.
+     * 
+     * RFC 1510
+     */
+    AD_WIN2K_PAC( 128 ),
+
+    /**
+     * Constant for the "sesame" authorization type.
+     * 
+     * RFC 1510
+     */
+    AD_ETYPE_NEGOTIATION( 129 );
+
+
+    /**
+     * The value/code for the authorization type.
+     */
+    private final int ordinal;
+
+
+    /**
+     * Private constructor prevents construction outside of this class.
+     */
+    private AuthorizationType( int ordinal )
+    {
+        this.ordinal = ordinal;
+    }
+
+
+    /**
+     * Returns the authorization type when specified by its ordinal.
+     *
+     * @param type
+     * @return The authorization type.
+     */
+    public static AuthorizationType getTypeByOrdinal( int type )
+    {
+        switch ( type )
+        {
+            case 1 :    return AD_IF_RELEVANT;
+            case 2 :    return AD_INTENDED_FOR_SERVER;
+            case 3 :    return AD_INTENDED_FOR_APPLICATION_CLASS;
+            case 4 :    return AD_KDC_ISSUED;
+            case 5 :    return AD_OR;
+            case 6 :    return AD_MANDATORY_TICKET_EXTENSIONS;
+            case 7 :    return AD_IN_TICKET_EXTENSIONS;
+            case 8 :    return AD_MANDATORY_FOR_KDC;
+            case 64 :   return OSF_DCE;
+            case 65 :   return SESAME;
+            case 66 :   return AD_OSF_DCE_PKI_CERTID;
+            case 128 :  return AD_WIN2K_PAC;
+            case 129 :  return AD_ETYPE_NEGOTIATION;
+            default :   return NULL;
+        }
+    }
+
+
+    /**
+     * Returns the number associated with this authorization type.
+     *
+     * @return The authorization type ordinal.
+     */
+    public int getOrdinal()
+    {
+        return ordinal;
+    }
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        switch ( this )
+        {
+            case AD_IF_RELEVANT                     : 
+                return "if relevant" + "(" + ordinal + ")";
+            
+            case AD_INTENDED_FOR_SERVER : 
+                return "intended for server" + "(" + ordinal + ")";
+            
+            case AD_INTENDED_FOR_APPLICATION_CLASS : 
+                return "intended for application class" + "(" + ordinal + ")";
+            
+            case AD_KDC_ISSUED : 
+                return "kdc issued" + "(" + ordinal + ")";
+            
+            case AD_OR : 
+                return "or" + "(" + ordinal + ")";
+            
+            case AD_MANDATORY_TICKET_EXTENSIONS : 
+                return "mandatory ticket extensions" + "(" + ordinal + ")";
+            
+            case AD_IN_TICKET_EXTENSIONS : 
+                return "in ticket extensions" + "(" + ordinal + ")";
+            
+            case AD_MANDATORY_FOR_KDC : 
+                return "mandatory-for-kdc" + "(" + ordinal + ")";
+            
+            case OSF_DCE : 
+                return "OSF DCE" + "(" + ordinal + ")";
+            
+            case SESAME : 
+                return "sesame" + "(" + ordinal + ")";
+                
+            case AD_OSF_DCE_PKI_CERTID :
+                return "OSF DCE pki certid" + "(" + ordinal + ")";
+            
+            case AD_WIN2K_PAC :
+                return "win 2000 PAC" + "(" + ordinal + ")";
+            
+            case AD_ETYPE_NEGOTIATION :
+                return "etype negociation" + "(" + ordinal + ")";
+            
+            default : 
+                return "null" + "(" + ordinal + ")";
+        }
+    }
+}

Added: directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataTest.java?rev=587531&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataTest.java
(added)
+++ directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataTest.java
Tue Oct 23 07:59:10 2007
@@ -0,0 +1,102 @@
+/*
+ *  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.server.kerberos.shared.messages.value;
+
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.messages.value.types.AuthorizationType;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test the AuthorizationData encoding and decoding
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class AuthorizationDataTest extends TestCase
+{
+    public void testAuthorizationDataOneAD() throws Exception
+    {
+        AuthorizationData ad = new AuthorizationData();
+        ad.add( new AuthorizationDataEntry( AuthorizationType.AD_KDC_ISSUED, new byte[]
+            { 0x01, 0x02, 0x03, 0x04 } ) );
+
+        ByteBuffer encoded = ByteBuffer.allocate( ad.computeLength() );
+
+        ad.encode( encoded );
+
+        byte[] expectedResult = new byte[]
+            { 
+              0x30, 0x0F, 
+                0x30, 0x0d, 
+                  ( byte ) 0xA0, 0x03, 
+                    0x02, 0x01, 0x04, 
+                  ( byte ) 0xA1, 0x06, 
+                    0x04, 0x04, 0x01, 0x02, 0x03, 0x04 
+            };
+
+        assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+    }
+
+
+    public void testAuthorizationDataThreeAD() throws Exception
+    {
+        AuthorizationData ad = new AuthorizationData();
+        ad.add( new AuthorizationDataEntry( AuthorizationType.AD_KDC_ISSUED, new byte[]
+            { 0x01, 0x02, 0x03, 0x04 } ) );
+        ad.add( new AuthorizationDataEntry( AuthorizationType.AD_IF_RELEVANT, new byte[]
+            { 0x05, 0x06, 0x07, 0x08 } ) );
+        ad.add( new AuthorizationDataEntry( AuthorizationType.AD_MANDATORY_TICKET_EXTENSIONS,
new byte[]
+            { 0x09, 0x0A, 0x0B, 0x0C } ) );
+
+        ByteBuffer encoded = ByteBuffer.allocate( ad.computeLength() );
+
+        ad.encode( encoded );
+
+        byte[] expectedResult = new byte[]
+            { 
+              0x30, 0x2D, 
+                0x30, 0x0d, 
+                  ( byte ) 0xA0, 0x03, 
+                    0x02, 0x01, 0x04, 
+                  ( byte ) 0xA1, 0x06, 
+                    0x04, 0x04, 
+                      0x01, 0x02, 0x03, 0x04, 
+                0x30, 0x0d, 
+                  ( byte ) 0xA0, 0x03, 
+                    0x02, 0x01, 0x01, 
+                  ( byte ) 0xA1, 0x06, 
+                    0x04, 0x04,
+                      0x05, 0x06, 0x07, 0x08, 
+                0x30, 0x0d, 
+                  ( byte ) 0xA0, 0x03, 
+                    0x02, 0x01, 0x06, 
+                  ( byte ) 0xA1, 0x06, 
+                    0x04, 0x04, 
+                      0x09, 0x0A, 0x0B, 0x0C 
+            };
+
+        assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+    }
+}

Added: directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressesTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressesTest.java?rev=587531&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressesTest.java
(added)
+++ directory/apacheds/branches/bigbang/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressesTest.java
Tue Oct 23 07:59:10 2007
@@ -0,0 +1,120 @@
+/*
+ *  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.server.kerberos.shared.messages.value;
+
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.messages.value.types.HostAddrType;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test the HostAddresses encoding and decoding
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class HostAddressesTest extends TestCase
+{
+    public void testEncodingHostAddressesIPOneAddresses() throws Exception
+    {
+        HostAddress[] ha = new HostAddress[]
+            { new HostAddress( HostAddrType.ADDRTYPE_INET, new byte[]
+                { 0x01, 0x02, 0x03, 0x04 } ), };
+
+        HostAddresses has = new HostAddresses( ha );
+
+        ByteBuffer encoded = ByteBuffer.allocate( has.computeLength() );
+
+        has.encode( encoded );
+
+        byte[] expectedResult = new byte[]
+            { 
+              0x30, 0x0F, 
+                0x30, 0x0d, 
+                  (byte)0xA0, 0x03, 
+                    0x02, 0x01, 0x02, 
+                  (byte)0xA1, 0x06, 
+                    0x04, 0x04, 
+                      0x01, 0x02, 0x03, 0x04
+            };
+
+        assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+    }
+
+
+    public void testEncodingHostAddressesIP3Addresses() throws Exception
+    {
+        HostAddress[] ha = new HostAddress[]
+            { new HostAddress( HostAddrType.ADDRTYPE_INET, new byte[]
+                { 0x01, 0x02, 0x03, 0x04 } ), new HostAddress( HostAddrType.ADDRTYPE_INET,
new byte[]
+                { 0x05, 0x06, 0x07, 0x08 } ), new HostAddress( HostAddrType.ADDRTYPE_INET,
new byte[]
+                { 0x09, 0x0A, 0x0B, 0x0C } ) };
+
+        HostAddresses has = new HostAddresses( ha );
+
+        ByteBuffer encoded = ByteBuffer.allocate( has.computeLength() );
+
+        has.encode( encoded );
+
+        byte[] expectedResult = new byte[]
+            { 
+                0x30, 0x2D, 
+                  0x30, 0x0d, 
+                    (byte)0xA0, 0x03, 
+                      0x02, 0x01, 0x02, 
+                    (byte)0xA1, 0x06, 
+                      0x04, 0x04, 
+                        0x01, 0x02, 0x03, 0x04, 
+                  0x30, 0x0d, 
+                    (byte)0xA0, 0x03, 
+                      0x02, 0x01, 0x02, 
+                    (byte)0xA1, 0x06, 
+                      0x04, 0x04,
+                        0x05, 0x06, 0x07, 0x08, 
+                  0x30, 0x0d, 
+                    (byte)0xA0, 0x03, 
+                      0x02, 0x01, 0x02, 
+                    (byte)0xA1, 0x06, 
+                      0x04, 0x04, 
+                        0x09, 0x0A, 0x0B, 0x0C 
+            };
+
+        assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+    }
+
+
+    public void testEncodingHostAddressIPNullAddress() throws Exception
+    {
+        HostAddresses has = new HostAddresses( null );
+
+        ByteBuffer encoded = ByteBuffer.allocate( has.computeLength() );
+
+        has.encode( encoded );
+
+        byte[] expectedResult = new byte[]
+            { 0x30, 0x00 };
+
+        assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+    }
+}



Mime
View raw message