directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1033437 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/ main/java/org/apache/directory/shared/kerberos/codec/authorizationData/ main/java/org/apache/directory/shared/kerberos/codec/authori...
Date Wed, 10 Nov 2010 12:44:47 GMT
Author: kayyagari
Date: Wed Nov 10 12:44:47 2010
New Revision: 1033437

URL: http://svn.apache.org/viewvc?rev=1033437&view=rev
Log:
o implementation of AuthorizationData component

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataContainer.java
    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/
    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/KerberosConstants.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java?rev=1033437&r1=1033436&r2=1033437&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
Wed Nov 10 12:44:47 2010
@@ -49,6 +49,10 @@ public class KerberosConstants
     public static final int HOST_ADDRESS_ADDR_TYPE_TAG = 0xA0;
     public static final int HOST_ADDRESS_ADDRESS_TAG = 0xA1;
     
+    /** AuthorizationData tags */
+    public static final int AUTHORIZATION_DATA_ADTYPE_TAG = 0xA0;
+    public static final int AUTHORIZATION_DATA_ADDATA_TAG = 0xA1;
+
     /** KRB-REQ-BODY's tags */
     public static final int KDC_REQ_BODY_KDC_OPTIONS_TAG = 0xA0;
     public static final int KDC_REQ_BODY_CNAME_TAG = 0xA1;

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataContainer.java?rev=1033437&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataContainer.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataContainer.java
Wed Nov 10 12:44:47 2010
@@ -0,0 +1,67 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.authorizationData;
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.components.AuthorizationData;
+
+
+/**
+ * The AuthorizationData container stores the AuthorizationData decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AuthorizationDataContainer extends AbstractContainer
+{
+    /** An AuthorizationData container */
+    private AuthorizationData authorizationData;
+
+    /**
+     * Creates a new AuthorizationDataContainer object.
+     */
+    public AuthorizationDataContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = AuthorizationDataGrammar.getInstance();
+        setTransition( AuthorizationDataStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the AuthorizationData.
+     */
+    public AuthorizationData getAuthorizationData()
+    {
+        return authorizationData;
+    }
+
+    
+    /**
+     * Set a AuthorizationData Object into the container. It will be completed by the
+     * KerberosDecoder.
+     * 
+     * @param authorizationData The AuthorizationData to set.
+     */
+    public void setAuthorizationData( AuthorizationData authorizationData )
+    {
+        this.authorizationData = authorizationData;
+    }
+}

Added: 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=1033437&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataGrammar.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataGrammar.java
Wed Nov 10 12:44:47 2010
@@ -0,0 +1,128 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.authorizationData;
+
+
+import org.apache.directory.shared.asn1.ber.grammar.AbstractGrammar;
+import org.apache.directory.shared.asn1.ber.grammar.Grammar;
+import org.apache.directory.shared.asn1.ber.grammar.GrammarTransition;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.codec.actions.CheckNotNullLength;
+import org.apache.directory.shared.kerberos.codec.authorizationData.actions.AuthorizationDataAdData;
+import org.apache.directory.shared.kerberos.codec.authorizationData.actions.AuthorizationDataAdType;
+import org.apache.directory.shared.kerberos.codec.authorizationData.actions.AuthorizationDataInit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the AuthorizationData structure. All the actions are declared
+ * in this class. As it is a singleton, these declaration are only done once. If
+ * an action is to be added or modified, this is where the work is to be done !
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class AuthorizationDataGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( AuthorizationDataGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. AuthorizationDataGrammar is a singleton */
+    private static Grammar instance = new AuthorizationDataGrammar();
+
+
+    /**
+     * Creates a new AuthorizationDataGrammar object.
+     */
+    private AuthorizationDataGrammar()
+    {
+        setName( AuthorizationDataGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[AuthorizationDataStatesEnum.LAST_AUTHORIZATION_DATA_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // AuthorizationData 
+        // ============================================================================================
+        // --------------------------------------------------------------------------------------------
+        // Transition from AuthorizationData init to AuthorizationData SEQ
+        // --------------------------------------------------------------------------------------------
+        // AuthorizationData   ::= SEQUENCE
+        super.transitions[AuthorizationDataStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            AuthorizationDataStatesEnum.START_STATE, AuthorizationDataStatesEnum.AUTHORIZATION_DATA_SEQ_STATE,
UniversalTag.SEQUENCE.getValue(),
+            new AuthorizationDataInit() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from AuthorizationData SEQ to adType tag
+        // --------------------------------------------------------------------------------------------
+        // AuthorizationData  ::= 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,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from adtype tag to adtype value
+        // --------------------------------------------------------------------------------------------
+        // AuthorizationData  ::= 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(),
+            new AuthorizationDataAdType() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from ad-type value to ad-data tag
+        // --------------------------------------------------------------------------------------------
+        // AuthorizationData   ::= SEQUENCE {
+        //         ...
+        //         ad-data     [1]
+        super.transitions[AuthorizationDataStatesEnum.AUTHORIZATION_DATA_ADTYPE_STATE.ordinal()][KerberosConstants.AUTHORIZATION_DATA_ADDATA_TAG]
= new GrammarTransition(
+            AuthorizationDataStatesEnum.AUTHORIZATION_DATA_ADTYPE_STATE, AuthorizationDataStatesEnum.AUTHORIZATION_DATA_ADDATA_TAG_STATE,
KerberosConstants.AUTHORIZATION_DATA_ADDATA_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from ad-data tag to ad-data value
+        // --------------------------------------------------------------------------------------------
+        // AuthorizationData   ::= 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() );
+    }
+
+
+    // ~ Methods
+    // ------------------------------------------------------------------------------------
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the AuthorizationData Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: 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=1033437&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataStatesEnum.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/AuthorizationDataStatesEnum.java
Wed Nov 10 12:44:47 2010
@@ -0,0 +1,113 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.authorizationData;
+
+
+import org.apache.directory.shared.asn1.ber.grammar.Grammar;
+import org.apache.directory.shared.asn1.ber.grammar.States;
+import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
+
+
+/**
+ * This class store the AuthorizationData grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum AuthorizationDataStatesEnum implements States
+{
+    // ~ Static fields/initializers
+    // -----------------------------------------------------------------
+
+    // Start
+    START_STATE,                            // 0
+    
+    AUTHORIZATION_DATA_SEQ_STATE,               // 1
+    
+    AUTHORIZATION_DATA_ADTYPE_TAG_STATE,         // 2
+    AUTHORIZATION_DATA_ADTYPE_STATE,             // 3
+    
+    AUTHORIZATION_DATA_ADDATA_TAG_STATE,          // 4
+    AUTHORIZATION_DATA_ADDATA_STATE,              // 5
+    
+    // End
+    LAST_AUTHORIZATION_DATA_STATE;              // 6
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "AUTHORIZATION_DATA_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar grammar )
+    {
+        if ( grammar instanceof KerberosMessageGrammar )
+        {
+            return "AUTHORIZATION_DATA_GRAMMAR";
+        }
+        else
+        {
+            return "UNKNOWN GRAMMAR";
+        }
+    }
+
+
+    /**
+     * Get the string representing the state
+     * 
+     * @param state The state number
+     * @return The String representing the state
+     */
+    public String getState( int state )
+    {
+        return ( ( state == LAST_AUTHORIZATION_DATA_STATE.ordinal() ) ? "LAST_AUTHORIZATION_DATA_STATE"
: name() );
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_AUTHORIZATION_DATA_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public AuthorizationDataStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: 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=1033437&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdData.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdData.java
Wed Nov 10 12:44:47 2010
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.authorizationData.actions;
+
+
+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.i18n.I18n;
+import org.apache.directory.shared.kerberos.codec.authorizationData.AuthorizationDataContainer;
+import org.apache.directory.shared.kerberos.components.AuthorizationData;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to store the AuthorizationData's ad-data
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AuthorizationDataAdData extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( AuthorizationDataAdData.class
);
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new AuthorizationDataAdData action.
+     */
+    public AuthorizationDataAdData()
+    {
+        super( "AuthorizationData ad-data" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        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 ) );
+        }
+        
+        Value value = tlv.getValue();
+        
+        // The encrypted data should not be null
+        if ( value.getData() == null ) 
+        {
+            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();
+        authData.setAdData( value.getData() );
+        
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "ad-data : {}", StringTools.dumpBytes( value.getData() ) );
+        }
+        
+        authDataContainer.setGrammarEndAllowed( true );
+    }
+}

Added: 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=1033437&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdType.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataAdType.java
Wed Nov 10 12:44:47 2010
@@ -0,0 +1,104 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.authorizationData.actions;
+
+
+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.authorizationData.AuthorizationDataContainer;
+import org.apache.directory.shared.kerberos.components.AuthorizationData;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to store the AuthorizationData adType
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AuthorizationDataAdType extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( AuthorizationDataAdType.class
);
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new AuthorizationDataAdType action.
+     */
+    public AuthorizationDataAdType()
+    {
+        super( "AuthorizationData adType" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        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 ) );
+        }
+        
+        // The encyptionType is an integer
+        Value value = tlv.getValue();
+        
+        AuthorizationData authData = authDataContainer.getAuthorizationData();
+        
+        try
+        {
+            int adType = IntegerDecoder.parse( value );
+
+            authData.setAdType( 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() );
+        }
+    }
+}

Added: 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=1033437&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataInit.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataInit.java
Wed Nov 10 12:44:47 2010
@@ -0,0 +1,83 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.authorizationData.actions;
+
+
+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.codec.DecoderException;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.kerberos.codec.authorizationData.AuthorizationDataContainer;
+import org.apache.directory.shared.kerberos.components.AuthorizationData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the AuthorizationData object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AuthorizationDataInit extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( AuthorizationDataInit.class
);
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new EncryptedDataInit action.
+     */
+    public AuthorizationDataInit()
+    {
+        super( "Creates a AuthorizationData instance" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        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 = new AuthorizationData();
+        authDataContainer.setAuthorizationData( authData );
+        
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "AuthorizationData created" );
+        }
+    }
+}

Added: 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=1033437&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java
Wed Nov 10 12:44:47 2010
@@ -0,0 +1,199 @@
+/*
+ *   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.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.i18n.I18n;
+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.kerberos.KerberosConstants;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A structure to hold the authorization data.
+ * 
+ * AuthorizationData      ::= SEQUENCE OF SEQUENCE {
+ *               ad-type  [0] Int32,
+ *               ad-data  [1] OCTET STRING
+ * }
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AuthorizationData extends AbstractAsn1Object
+{
+
+    /** the type of authorization data */
+    private int adType;
+
+    /** the authorization data */
+    private byte[] adData;
+
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( EncryptedData.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    private transient int adTypeTagLen;
+    private transient int adDataTagLen;
+    private transient int authorizationDataSeqLen;
+
+
+    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
+     *       |
+     *       +--> 0x04 L3-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;
+
+        return 1 + TLV.getNbBytes( authorizationDataSeqLen ) + authorizationDataSeqLen;
+    }
+
+
+    /**
+     * Encode the EncryptedData message to a PDU.
+     * 
+     * @param buffer The buffer where to put the PDU. It should have been allocated
+     * before, with the right size.
+     * @return The constructed PDU.
+     */
+    @Override
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_148 ) );
+        }
+
+        try
+        {
+            // The AuthorizationData SEQ 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 );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            LOG.error( I18n.err( I18n.ERR_139, 1 + TLV.getNbBytes( authorizationDataSeqLen
)
+                + authorizationDataSeqLen, buffer.capacity() ) );
+            throw new EncoderException( I18n.err( I18n.ERR_138 ) );
+        }
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "AuthorizationData encoding : {}", StringTools.dumpBytes( buffer.array()
) );
+            LOG.debug( "AuthorizationData initial value : {}", toString() );
+        }
+
+        return buffer;
+    }
+
+
+    public int getAdType()
+    {
+        return adType;
+    }
+
+
+    public void setAdType( int adType )
+    {
+        this.adType = adType;
+    }
+
+
+    public byte[] getAdData()
+    {
+        return adData;
+    }
+
+
+    public void setAdData( byte[] adData )
+    {
+        this.adData = adData;
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        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"
);
+
+        return sb.toString();
+    }
+}

Added: 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=1033437&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AuthorizationDataDecoderTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AuthorizationDataDecoderTest.java
Wed Nov 10 12:44:47 2010
@@ -0,0 +1,165 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.shared.kerberos.codec;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.codec.authorizationData.AuthorizationDataContainer;
+import org.apache.directory.shared.kerberos.components.AuthorizationData;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+
+/**
+ * Test cases for AuthorizationData decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AuthorizationDataDecoderTest
+{
+
+    @Test
+    public void testAuthorizationData()
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x11 );
+        
+        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'
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        AuthorizationDataContainer authDataContainer = new AuthorizationDataContainer();
+        
+        // Decode the AuthorizationData PDU
+        try
+        {
+            kerberosDecoder.decode( stream, authDataContainer );
+        }
+        catch ( DecoderException de )
+        {
+            fail( de.getMessage() );
+        }
+
+        AuthorizationData authData = authDataContainer.getAuthorizationData();
+        assertEquals( 2, authData.getAdType() );
+        assertTrue( Arrays.equals( StringTools.getBytesUtf8( "abcdef" ), authData.getAdData()
) );
+        
+        // Check the encoding
+        ByteBuffer bb = ByteBuffer.allocate( authData.computeLength() );
+        
+        try
+        {
+            bb = authData.encode( bb );
+    
+            // Check the length
+            assertEquals( 0x11, bb.limit() );
+    
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+    
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            
+            fail();
+        }
+    }
+    
+    
+    @Test( expected = DecoderException.class)
+    public void testAuthorizationDataWithoutType() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x07 );
+        
+        stream.put( new byte[]
+            { 0x30, 0x5,
+                (byte)0xA1, 0x03,                 // ad-data
+                  0x04, 0x01, 'a'
+            } );
+
+        stream.flip();
+
+        AuthorizationDataContainer authDataContainer = new AuthorizationDataContainer();
+        
+        kerberosDecoder.decode( stream, authDataContainer );
+        fail();
+    }
+    
+    
+    @Test( expected = DecoderException.class)
+    public void testAuthorizationDataWithoutData() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x07 );
+        
+        stream.put( new byte[]
+            { 0x30, 0x5,
+                (byte)0xA0, 0x03,                 // ad-data
+                  0x02, 0x01, 0x02
+            } );
+
+        stream.flip();
+
+        AuthorizationDataContainer authDataContainer = new AuthorizationDataContainer();
+        
+        kerberosDecoder.decode( stream, authDataContainer );
+        fail();
+    }
+
+    
+    @Test( expected = DecoderException.class)
+    public void testAuthorizationDataWithIncorrectPdu() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+        
+        stream.put( new byte[]
+            { 0x30, 0x0 } );
+
+        stream.flip();
+
+        AuthorizationDataContainer authDataContainer = new AuthorizationDataContainer();
+        
+        kerberosDecoder.decode( stream, authDataContainer );
+        fail();
+    }
+
+}



Mime
View raw message