directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1039470 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/ main/java/org/apache/directory/shared/kerberos/codec/adAndOr/ main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/ ...
Date Fri, 26 Nov 2010 17:19:02 GMT
Author: elecharny
Date: Fri Nov 26 17:19:02 2010
New Revision: 1039470

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

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/AdAndOrInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/StoreConditionCount.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/StoreElements.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdAndOr.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdAndOrDecoderTest.java
Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/Checksum.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=1039470&r1=1039469&r2=1039470&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
Fri Nov 26 17:19:02 2010
@@ -139,8 +139,8 @@ public class KerberosConstants
     // Components
     //-------------------------------------------------------------------------
     /** AD-AND-OR */
-    public static final int AD_AND_IF_CONDITION_COUNT_TAG = 0xA0;
-    public static final int AD_AND_IF_ELEMENTS_TAG = 0xA1;
+    public static final int AD_AND_OR_CONDITION_COUNT_TAG = 0xA0;
+    public static final int AD_AND_OR_ELEMENTS_TAG = 0xA1;
     
     /** AuthorizationData tags */
     public static final int AUTHORIZATION_DATA_ADTYPE_TAG = 0xA0;

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrContainer.java?rev=1039470&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrContainer.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrContainer.java
Fri Nov 26 17:19:02 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.adAndOr;
+
+import org.apache.directory.shared.kerberos.codec.kdcReq.KdcReqContainer;
+import org.apache.directory.shared.kerberos.components.AdAndOr;
+
+
+/**
+ * The AdAndOr container stores the AD-AND-OR decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AdAndOrContainer extends KdcReqContainer
+{
+    /** An AD-AND-OR container */
+    private AdAndOr adAndOr = new AdAndOr();
+
+    /**
+     * Creates a new AdAndOrContainer object.
+     */
+    public AdAndOrContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = AdAndOrGrammar.getInstance();
+        setTransition( AdAndOrStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the AdAndOr.
+     */
+    public AdAndOr getAdAndOr()
+    {
+        return adAndOr;
+    }
+
+    
+    /**
+     * Set an AdAndOr Object into the container. It will be completed by the
+     * KerberosDecoder.
+     * 
+     * @param adAndOr The AdAndOr to set.
+     */
+    public void setAdAndOr( AdAndOr adAndOr )
+    {
+        this.adAndOr = adAndOr;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrGrammar.java?rev=1039470&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrGrammar.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrGrammar.java
Fri Nov 26 17:19:02 2010
@@ -0,0 +1,116 @@
+/*
+ *  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.adAndOr;
+
+
+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.adAndOr.actions.AdAndOrInit;
+import org.apache.directory.shared.kerberos.codec.adAndOr.actions.StoreConditionCount;
+import org.apache.directory.shared.kerberos.codec.adAndOr.actions.StoreElements;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the AdAndOr 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 AdAndOrGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( AdAndOrGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. AdAndOrGrammar is a singleton */
+    private static Grammar instance = new AdAndOrGrammar();
+
+
+    /**
+     * Creates a new AdAndOrGrammar object.
+     */
+    private AdAndOrGrammar()
+    {
+        setName( AdAndOrGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[AdAndOrStatesEnum.LAST_AD_AND_OR_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // AdAndOr 
+        // ============================================================================================
+        // --------------------------------------------------------------------------------------------
+        // Transition from AdAndOr init to AdAndOr SEQ
+        // --------------------------------------------------------------------------------------------
+        // AD-AND-OR               ::= SEQUENCE {
+        super.transitions[AdAndOrStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            AdAndOrStatesEnum.START_STATE, AdAndOrStatesEnum.AD_AND_OR_STATE, UniversalTag.SEQUENCE.getValue(),
+            new AdAndOrInit() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from AdAndOr SEQ to condition-count tag
+        // --------------------------------------------------------------------------------------------
+        // AD-AND-OR               ::= SEQUENCE {
+        //         condition-count [0]
+        super.transitions[AdAndOrStatesEnum.AD_AND_OR_STATE.ordinal()][KerberosConstants.AD_AND_OR_CONDITION_COUNT_TAG]
= new GrammarTransition(
+            AdAndOrStatesEnum.AD_AND_OR_STATE, AdAndOrStatesEnum.AD_AND_OR_CONDITION_COUNT_TAG_STATE,
KerberosConstants.AD_AND_OR_CONDITION_COUNT_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from condition-count tag to condition-count value
+        // --------------------------------------------------------------------------------------------
+        // AD-AND-OR               ::= SEQUENCE {
+        //         condition-count [0] Int32,
+        super.transitions[AdAndOrStatesEnum.AD_AND_OR_CONDITION_COUNT_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
+            AdAndOrStatesEnum.AD_AND_OR_CONDITION_COUNT_TAG_STATE, AdAndOrStatesEnum.AD_AND_OR_CONDITION_COUNT_STATE,
UniversalTag.INTEGER.getValue(),
+            new StoreConditionCount() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from condition-countvalue to elements
+        // --------------------------------------------------------------------------------------------
+        // AD-AND-OR               ::= SEQUENCE {
+        //         ...
+        //         elements        [1] AuthorizationData
+        // }
+        super.transitions[AdAndOrStatesEnum.AD_AND_OR_CONDITION_COUNT_STATE.ordinal()][KerberosConstants.AD_AND_OR_ELEMENTS_TAG]
= new GrammarTransition(
+            AdAndOrStatesEnum.AD_AND_OR_CONDITION_COUNT_STATE, AdAndOrStatesEnum.AD_AND_OR_ELEMENTS_TAG_STATE,
KerberosConstants.AD_AND_OR_ELEMENTS_TAG,
+            new StoreElements() );
+    }
+
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the AD-AND-OR Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrStatesEnum.java?rev=1039470&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrStatesEnum.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/AdAndOrStatesEnum.java
Fri Nov 26 17:19:02 2010
@@ -0,0 +1,110 @@
+/*
+ *  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.adAndOr;
+
+
+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 AD-AND-OR grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum AdAndOrStatesEnum implements States
+{
+    // Start
+    START_STATE,                          // 0
+    
+    // ----- AD-AND-OR message --------------------------------------
+    AD_AND_OR_STATE,                      // 1
+    
+    AD_AND_OR_CONDITION_COUNT_TAG_STATE,  // 2
+    AD_AND_OR_CONDITION_COUNT_STATE,      // 3
+    
+    AD_AND_OR_ELEMENTS_TAG_STATE,         // 4
+    
+    // End
+    LAST_AD_AND_OR_STATE;                 // 5
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "AD_AND_OR_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar grammar )
+    {
+        if ( grammar instanceof KerberosMessageGrammar )
+        {
+            return "AD_AND_OR_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_AD_AND_OR_STATE.ordinal() ) ? "AD_AND_OR_END_STATE" : name()
);
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_AD_AND_OR_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public AdAndOrStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/AdAndOrInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/AdAndOrInit.java?rev=1039470&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/AdAndOrInit.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/AdAndOrInit.java
Fri Nov 26 17:19:02 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.adAndOr.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.adAndOr.AdAndOrContainer;
+import org.apache.directory.shared.kerberos.components.AdAndOr;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the AD-AND-OR object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AdAndOrInit extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( AdAndOrInit.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new AdAndOrInit action.
+     */
+    public AdAndOrInit()
+    {
+        super( "Creates a AD-AND-OR instance" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        AdAndOrContainer adAndOrContainer = ( AdAndOrContainer ) container;
+
+        TLV tlv = adAndOrContainer.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 ) );
+        }
+        
+        AdAndOr adAndor = new AdAndOr();
+        adAndOrContainer.setAdAndOr( adAndor );
+        
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "AdAndOr created" );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/StoreConditionCount.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/StoreConditionCount.java?rev=1039470&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/StoreConditionCount.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/StoreConditionCount.java
Fri Nov 26 17:19:02 2010
@@ -0,0 +1,54 @@
+/*
+ *   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.adAndOr.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadInteger;
+import org.apache.directory.shared.kerberos.codec.adAndOr.AdAndOrContainer;
+
+
+/**
+ * Sets the AdAndOr's type.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreConditionCount extends AbstractReadInteger
+{
+    /**
+     * Creates a new instance of StoreConditionCount.
+     */
+    public StoreConditionCount()
+    {
+        super( "AdAndOr condition count" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setIntegerValue( int value, Asn1Container container )
+    {
+        AdAndOrContainer adAndOrContainer = ( AdAndOrContainer ) container;
+        adAndOrContainer.getAdAndOr().setConditionCount( value );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/StoreElements.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/StoreElements.java?rev=1039470&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/StoreElements.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adAndOr/actions/StoreElements.java
Fri Nov 26 17:19:02 2010
@@ -0,0 +1,111 @@
+/*
+ *  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.adAndOr.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+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.adAndOr.AdAndOrContainer;
+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 store the AdAndor 'elements' value
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreElements extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( StoreElements.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new StoreElements action.
+     */
+    public StoreElements()
+    {
+        super( "AdAndOr 'elements' value" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        AdAndOrContainer adAndOrContainer = ( AdAndOrContainer ) container;
+
+        TLV tlv = adAndOrContainer.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 ) );
+        }
+        
+        // Now, let's decode the AuthorizationData
+        Asn1Decoder authorizationDataDecoder = new Asn1Decoder();
+        
+        AuthorizationDataContainer authorizationDataContainer = new AuthorizationDataContainer();
+        authorizationDataContainer.setStream( container.getStream() );
+        
+        // Decode the AuthorizationData PDU
+        try
+        {
+            authorizationDataDecoder.decode( container.getStream(), authorizationDataContainer
);
+        }
+        catch ( DecoderException de )
+        {
+            throw de;
+        }
+        
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+        // Update the parent
+        container.updateParent();
+
+        // Store the AuthorizationData in the container
+        AuthorizationData elements = authorizationDataContainer.getAuthorizationData();
+        adAndOrContainer.getAdAndOr().setElements( elements );
+        
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "Elements added : {}", elements );
+        }
+        
+        container.setGrammarEndAllowed( true );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdAndOr.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdAndOr.java?rev=1039470&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdAndOr.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdAndOr.java
Fri Nov 26 17:19:02 2010
@@ -0,0 +1,214 @@
+/*
+ *  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;
+
+/**
+ * The AdAndOr structure is used to store a AD-AND-OR associated to a type.
+ * 
+ * The ASN.1 grammar is :
+ * <pre>
+ * AD-AND-OR               ::= SEQUENCE {
+ *         condition-count [0] Int32,
+ *         elements        [1] <AuthorizationData>
+ * }
+ * </pre>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AdAndOr extends AbstractAsn1Object
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( AdAndOr.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The condition-count */
+    private int conditionCount;
+    
+    /** The elements */
+    private AuthorizationData elements;
+
+    // Storage for computed lengths
+    private transient int conditionCountTagLength;
+    private transient int elementsTagLength;
+    private transient int adAndOrSeqLength;
+
+    /**
+     * Creates a new instance of AdAndOr
+     */
+    public AdAndOr()
+    {
+    }
+
+
+    /**
+     * @return the conditionCount
+     */
+    public int getConditionCount()
+    {
+        return conditionCount;
+    }
+
+    
+    /**
+     * @param conditionCount the conditionCount to set
+     */
+    public void setConditionCount( int conditionCount )
+    {
+        this.conditionCount = conditionCount;
+    }
+
+    
+    /**
+     * @return the elements
+     */
+    public AuthorizationData getElements()
+    {
+        return elements;
+    }
+
+    
+    /**
+     * @param elements the elements to set
+     */
+    public void setElements( AuthorizationData elements )
+    {
+        this.elements = elements;
+    }
+    
+    
+    /**
+     * Compute the AD-AND-OR length
+     * <pre>
+     * 0x30 L1 AD-AND-OR sequence
+     *  |
+     *  +--> 0xA1 L2 condition count tag
+     *  |     |
+     *  |     +--> 0x02 L2-1 condition count (int)
+     *  |
+     *  +--> 0xA2 L3 elements tag
+     *        |
+     *        +--> 0x30 L3-1 elements (AuthorizationData)
+     * </pre>
+     */
+    @Override
+    public int computeLength()
+    {
+        // Compute the condition count length
+        int conditionCountLength = Value.getNbBytes( conditionCount );
+        conditionCountTagLength = 1 + TLV.getNbBytes( conditionCountLength ) + conditionCountLength;
+        adAndOrSeqLength = 1 + TLV.getNbBytes( conditionCountTagLength ) + conditionCountTagLength;

+
+        // Compute the elements length
+        elementsTagLength = elements.computeLength();
+        adAndOrSeqLength += 1 + TLV.getNbBytes( elementsTagLength ) + elementsTagLength;

+
+        // Compute the whole sequence length
+        return 1 + TLV.getNbBytes( adAndOrSeqLength ) + adAndOrSeqLength;
+    }
+
+
+    /**
+     * Encode the AD-AND-OR 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 AD-AND-OR SEQ OF Tag
+            buffer.put( UniversalTag.SEQUENCE.getValue() );
+            buffer.put( TLV.getBytes( adAndOrSeqLength ) );
+            
+            // the condition-count
+            buffer.put( ( byte ) KerberosConstants.AD_AND_OR_CONDITION_COUNT_TAG );
+            buffer.put( (byte)conditionCountTagLength );
+            Value.encode( buffer, conditionCount );
+
+            // the elements
+            buffer.put( ( byte ) KerberosConstants.AD_AND_OR_ELEMENTS_TAG );
+            buffer.put( (byte)elementsTagLength );
+            
+            elements.encode( buffer );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            LOG.error( I18n.err( I18n.ERR_139, 1 + TLV.getNbBytes( adAndOrSeqLength )
+                + adAndOrSeqLength, buffer.capacity() ) );
+            throw new EncoderException( I18n.err( I18n.ERR_138 ) );
+        }
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "AD-AND-OR encoding : {}", StringTools.dumpBytes( buffer.array() )
);
+            LOG.debug( "AD-AND-OR 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( "AD-AND-OR : {\n" );
+        sb.append( tabs ).append( "    condition-count: " ).append( conditionCount ).append(
'\n' );
+        sb.append( tabs + "    elements:" ).append( elements ).append( '\n' );
+        sb.append( tabs + "}\n" );
+
+        return sb.toString();
+    }
+}

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/Checksum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/Checksum.java?rev=1039470&r1=1039469&r2=1039470&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/Checksum.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/Checksum.java
Fri Nov 26 17:19:02 2010
@@ -273,6 +273,7 @@ public class Checksum extends AbstractAs
         return buffer;
     }
 
+    
     /**
      * @see Object#toString()
      */

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdAndOrDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdAndOrDecoderTest.java?rev=1039470&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdAndOrDecoderTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdAndOrDecoderTest.java
Fri Nov 26 17:19:02 2010
@@ -0,0 +1,283 @@
+/*
+ *   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.fail;
+
+import java.nio.ByteBuffer;
+
+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.adAndOr.AdAndOrContainer;
+import org.apache.directory.shared.kerberos.components.AdAndOr;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+
+/**
+ * Test cases for AD-AND-OR codec.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AdAndOrDecoderTest
+{
+    @Test
+    public void testDecodeFullAdAndOr()
+    {
+        Asn1Decoder krbDecoder = new Asn1Decoder();
+        
+        ByteBuffer stream = ByteBuffer.allocate( 0x2D );
+
+        stream.put( new byte[]
+            { 
+                0x30, 0x2B,
+                  (byte)0xA0, 0x03,                 // condition count
+                    0x02, 0x01, 0x02,
+                  (byte)0xA1, 0x24,                 // elements
+                    0x30, 0x22,
+                      0x30, 0x0F,
+                        (byte)0xA0, 0x03,                 // ad-type
+                          0x02, 0x01, 0x02,
+                        (byte)0xA1, 0x08,                 // ad-data
+                          0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f',
+                      0x30, 0x0F,
+                        (byte)0xA0, 0x03,                 // ad-type
+                          0x02, 0x01, 0x02,
+                        (byte)0xA1, 0x08,                 // ad-data
+                          0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l'
+            } );
+        
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        AdAndOrContainer adAndOrContainer = new AdAndOrContainer();
+        adAndOrContainer.setStream( stream );
+        
+        try
+        {
+            krbDecoder.decode( stream, adAndOrContainer );
+        }
+        catch ( DecoderException de )
+        {
+            fail( de.getMessage() );
+        }
+
+        AdAndOr adAndOr = adAndOrContainer.getAdAndOr();
+        
+        assertEquals( 2, adAndOr.getConditionCount() );
+        
+        ByteBuffer bb = ByteBuffer.allocate( adAndOr.computeLength() );
+        
+        try
+        {
+            bb = adAndOr.encode( bb );
+    
+            // Check the length
+            assertEquals( 0x2D, bb.limit() );
+    
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+    
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
+
+    
+    @Test( expected = DecoderException.class )
+    public void testDecodeAdAndOrWithEmptySeq() throws DecoderException
+    {
+        Asn1Decoder krbDecoder = new Asn1Decoder();
+        
+        ByteBuffer stream = ByteBuffer.allocate( 2 );
+
+        stream.put( new byte[]
+            { 
+                0x30, 0x0
+            } );
+        
+        stream.flip();
+
+        AdAndOrContainer adAndOrContainer = new AdAndOrContainer();
+        adAndOrContainer.setStream( stream );
+
+        krbDecoder.decode( stream, adAndOrContainer );
+        fail();
+    }
+
+    
+    @Test( expected = DecoderException.class )
+    public void testDecodeAdAndOrEmptyConditionCount() throws DecoderException
+    {
+        Asn1Decoder krbDecoder = new Asn1Decoder();
+        
+        ByteBuffer stream = ByteBuffer.allocate( 4 );
+
+        stream.put( new byte[]
+            { 
+                0x30, 0x02,
+                  (byte)0xA0, 0x00
+            } );
+        
+        stream.flip();
+
+        AdAndOrContainer adAndOrContainer = new AdAndOrContainer();
+        adAndOrContainer.setStream( stream );
+
+        krbDecoder.decode( stream, adAndOrContainer );
+        fail();
+    }
+
+    
+    @Test( expected = DecoderException.class )
+    public void testDecodeAdAndOrNullConditionCount() throws DecoderException
+    {
+        Asn1Decoder krbDecoder = new Asn1Decoder();
+        
+        ByteBuffer stream = ByteBuffer.allocate( 6 );
+
+        stream.put( new byte[]
+            { 
+                0x30, 0x04,
+                  (byte)0xA0, 0x02,
+                    0x02, 0x00
+            } );
+        
+        stream.flip();
+
+        AdAndOrContainer adAndOrContainer = new AdAndOrContainer();
+        adAndOrContainer.setStream( stream );
+
+        krbDecoder.decode( stream, adAndOrContainer );
+        fail();
+    }
+
+    
+    @Test( expected = DecoderException.class )
+    public void testDecodeAdAndOrNoConditionCount() throws DecoderException
+    {
+        Asn1Decoder krbDecoder = new Asn1Decoder();
+        
+        ByteBuffer stream = ByteBuffer.allocate( 0x28 );
+
+        stream.put( new byte[]
+            { 
+                0x30, 0x26,
+                  (byte)0xA1, 0x24,                 // elements
+                    0x30, 0x22,
+                      0x30, 0x0F,
+                        (byte)0xA0, 0x03,                 // ad-type
+                          0x02, 0x01, 0x02,
+                        (byte)0xA1, 0x08,                 // ad-data
+                          0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f',
+                      0x30, 0x0F,
+                        (byte)0xA0, 0x03,                 // ad-type
+                          0x02, 0x01, 0x02,
+                        (byte)0xA1, 0x08,                 // ad-data
+                          0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l'
+            } );
+        
+        stream.flip();
+
+        AdAndOrContainer adAndOrContainer = new AdAndOrContainer();
+        adAndOrContainer.setStream( stream );
+
+        krbDecoder.decode( stream, adAndOrContainer );
+        fail();
+    }
+
+    
+    @Test( expected = DecoderException.class )
+    public void testDecodeAdAndOrNoElements() throws DecoderException
+    {
+        Asn1Decoder krbDecoder = new Asn1Decoder();
+        
+        ByteBuffer stream = ByteBuffer.allocate( 0x07 );
+
+        stream.put( new byte[]
+            { 
+                0x30, 0x05,
+                  (byte)0xA0, 0x03,                 // condition count
+                    0x02, 0x01, 0x02,
+            } );
+        
+        stream.flip();
+
+        AdAndOrContainer adAndOrContainer = new AdAndOrContainer();
+        adAndOrContainer.setStream( stream );
+
+        krbDecoder.decode( stream, adAndOrContainer );
+        fail();
+    }
+    
+    
+    @Test( expected = DecoderException.class )
+    public void testDecodeAdAndOrEmptyElements() throws DecoderException
+    {
+        Asn1Decoder krbDecoder = new Asn1Decoder();
+        
+        ByteBuffer stream = ByteBuffer.allocate( 0x09 );
+
+        stream.put( new byte[]
+            { 
+                0x30, 0x07,
+                  (byte)0xA0, 0x03,                 // condition count
+                    0x02, 0x01, 0x02,
+                  (byte)0xA1, 0x00                  // elements
+            } );
+        
+        stream.flip();
+
+        AdAndOrContainer adAndOrContainer = new AdAndOrContainer();
+
+        krbDecoder.decode( stream, adAndOrContainer );
+        fail();
+    }
+    
+    
+    @Test( expected = DecoderException.class )
+    public void testDecodeAdAndOrNullElements() throws DecoderException
+    {
+        Asn1Decoder krbDecoder = new Asn1Decoder();
+        
+        ByteBuffer stream = ByteBuffer.allocate( 0x0B );
+
+        stream.put( new byte[]
+            { 
+                0x30, 0x09,
+                  (byte)0xA0, 0x03,                 // condition count
+                    0x02, 0x01, 0x02,
+                  (byte)0xA1, 0x02,                 // elements
+                    0x30, 0x00
+            } );
+        
+        stream.flip();
+
+        AdAndOrContainer adAndOrContainer = new AdAndOrContainer();
+        adAndOrContainer.setStream( stream );
+
+        krbDecoder.decode( stream, adAndOrContainer );
+        fail();
+    }
+}



Mime
View raw message