You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/11/20 03:04:51 UTC

svn commit: r1037104 - in /directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding: ./ actions/

Author: elecharny
Date: Sat Nov 20 02:04:50 2010
New Revision: 1037104

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

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/StoreContents.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/StoreTrType.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/TransitedEncodingInit.java

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingContainer.java?rev=1037104&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingContainer.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingContainer.java Sat Nov 20 02:04:50 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.transitedEncoding;
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.components.TransitedEncoding;
+
+
+/**
+ * The transitedEncoding container stores the TransitedEncoding decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TransitedEncodingContainer extends AbstractContainer
+{
+    /** An EncryptedData container */
+    private TransitedEncoding transitedEncoding;
+
+    /**
+     * Creates a new TransitedEncodingContainer object.
+     */
+    public TransitedEncodingContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = TransitedEncodingGrammar.getInstance();
+        setTransition( TransitedEncodingStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the TransitedEncoding.
+     */
+    public TransitedEncoding getTransitedEncoding()
+    {
+        return transitedEncoding;
+    }
+
+    
+    /**
+     * Set a TransitedEncoding Object into the container. It will be completed by the
+     * KerberosDecoder.
+     * 
+     * @param transitedEncoding The TransitedEncoding to set.
+     */
+    public void setTransitedEncoding( TransitedEncoding transitedEncoding )
+    {
+        this.transitedEncoding = transitedEncoding;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingGrammar.java?rev=1037104&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingGrammar.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingGrammar.java Sat Nov 20 02:04:50 2010
@@ -0,0 +1,125 @@
+/*
+ *  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.transitedEncoding;
+
+
+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.transitedEncoding.actions.StoreContents;
+import org.apache.directory.shared.kerberos.codec.transitedEncoding.actions.StoreTrType;
+import org.apache.directory.shared.kerberos.codec.transitedEncoding.actions.TransitedEncodingInit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the TransitedEncoding 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 TransitedEncodingGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( TransitedEncodingGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. TransitedEncodingGrammar is a singleton */
+    private static Grammar instance = new TransitedEncodingGrammar();
+
+
+    /**
+     * Creates a new TransitedEncodingGrammar object.
+     */
+    private TransitedEncodingGrammar()
+    {
+        setName( TransitedEncodingGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[TransitedEncodingStatesEnum.LAST_TRANSITED_ENCODING_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // TransitedEncoding 
+        // ============================================================================================
+        // --------------------------------------------------------------------------------------------
+        // Transition from TransitedEncoding init to TransitedEncoding SEQ
+        // --------------------------------------------------------------------------------------------
+        // TransitedEncoding   ::= SEQUENCE {
+        super.transitions[TransitedEncodingStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
+            TransitedEncodingStatesEnum.START_STATE, TransitedEncodingStatesEnum.TRANSITED_ENCODING_SEQ_STATE, UniversalTag.SEQUENCE.getValue(),
+            new TransitedEncodingInit() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from TransitedEncoding SEQ to tr-type tag
+        // --------------------------------------------------------------------------------------------
+        // TransitedEncoding   ::= SEQUENCE {
+        //         tr-type         [0]
+        super.transitions[TransitedEncodingStatesEnum.TRANSITED_ENCODING_SEQ_STATE.ordinal()][KerberosConstants.TRANSITED_ENCODING_TR_TYPE_TAG] = new GrammarTransition(
+            TransitedEncodingStatesEnum.TRANSITED_ENCODING_SEQ_STATE, TransitedEncodingStatesEnum.TRANSITED_ENCODING_TR_TYPE_TAG_STATE, KerberosConstants.TRANSITED_ENCODING_TR_TYPE_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from tr-type tag to tr-type value
+        // --------------------------------------------------------------------------------------------
+        // TransitedEncoding   ::= SEQUENCE {
+        //         tr-type         [0] Int32 -- must be registered --,
+        super.transitions[TransitedEncodingStatesEnum.TRANSITED_ENCODING_TR_TYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition(
+            TransitedEncodingStatesEnum.TRANSITED_ENCODING_TR_TYPE_TAG_STATE, TransitedEncodingStatesEnum.TRANSITED_ENCODING_TR_TYPE_STATE, UniversalTag.INTEGER.getValue(),
+            new StoreTrType() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from tr-type value to contents tag
+        // --------------------------------------------------------------------------------------------
+        // TransitedEncoding   ::= SEQUENCE {
+        //         ...
+        //         contents        [1] 
+        super.transitions[TransitedEncodingStatesEnum.TRANSITED_ENCODING_TR_TYPE_STATE.ordinal()][KerberosConstants.TRANSITED_ENCODING_CONTENTS_TAG] = new GrammarTransition(
+            TransitedEncodingStatesEnum.TRANSITED_ENCODING_TR_TYPE_STATE, TransitedEncodingStatesEnum.TRANSITED_ENCODING_CONTENTS_TAG_STATE, KerberosConstants.TRANSITED_ENCODING_CONTENTS_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from contents tag to contents value
+        // --------------------------------------------------------------------------------------------
+        // TransitedEncoding   ::= SEQUENCE {
+        //         ...
+        //         contents        [1] OCTET STRING
+        super.transitions[TransitedEncodingStatesEnum.TRANSITED_ENCODING_CONTENTS_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition(
+            TransitedEncodingStatesEnum.TRANSITED_ENCODING_CONTENTS_TAG_STATE, TransitedEncodingStatesEnum.TRANSITED_ENCODING_CONTENTS_STATE, UniversalTag.OCTET_STRING.getValue(),
+            new StoreContents() );
+    }
+
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the TransitedEncoding Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingStatesEnum.java?rev=1037104&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingStatesEnum.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/TransitedEncodingStatesEnum.java Sat Nov 20 02:04:50 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.transitedEncoding;
+
+
+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 TransitedEncoding grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum TransitedEncodingStatesEnum implements States
+{
+    // Start
+    START_STATE,                                // 0
+    
+    // ----- TransitedEncoding message --------------------------------------
+    TRANSITED_ENCODING_SEQ_STATE,               // 1
+    
+    TRANSITED_ENCODING_TR_TYPE_TAG_STATE,       // 2
+    TRANSITED_ENCODING_TR_TYPE_STATE,           // 3
+    
+    TRANSITED_ENCODING_CONTENTS_TAG_STATE,      // 4
+    TRANSITED_ENCODING_CONTENTS_STATE,          // 5
+    
+    // End
+    LAST_TRANSITED_ENCODING_STATE;              // 6
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "TRANSITED_ENCODING_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar grammar )
+    {
+        if ( grammar instanceof KerberosMessageGrammar )
+        {
+            return "TRANSITED_ENCODING_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_TRANSITED_ENCODING_STATE.ordinal() ) ? "TRANSITED_ENCODING_END_STATE" : name() );
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_TRANSITED_ENCODING_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public TransitedEncodingStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/StoreContents.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/StoreContents.java?rev=1037104&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/StoreContents.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/StoreContents.java Sat Nov 20 02:04:50 2010
@@ -0,0 +1,90 @@
+/*
+ *  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.transitedEncoding.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.transitedEncoding.TransitedEncodingContainer;
+import org.apache.directory.shared.kerberos.components.TransitedEncoding;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to read the TransitedEncoding etext
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreContents extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( StoreContents.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new StoreContents action.
+     */
+    public StoreContents()
+    {
+        super( "TransitedEncoding etext" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public final void action( Asn1Container container ) throws DecoderException
+    {
+        TransitedEncodingContainer transitedEncodingContainer = ( TransitedEncodingContainer ) container;
+        
+        TLV tlv = transitedEncodingContainer.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 value is the realm
+        Value value = tlv.getValue();
+
+        TransitedEncoding transitedEncoding = transitedEncodingContainer.getTransitedEncoding();
+        transitedEncoding.setContents( value.getData() );
+        
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "Contents: " + StringTools.dumpBytes( value.getData() ) );
+        }
+        
+        container.setGrammarEndAllowed( true );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/StoreTrType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/StoreTrType.java?rev=1037104&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/StoreTrType.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/StoreTrType.java Sat Nov 20 02:04:50 2010
@@ -0,0 +1,57 @@
+/*
+ *  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.transitedEncoding.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.transitedEncoding.TransitedEncodingContainer;
+import org.apache.directory.shared.kerberos.codec.types.TransitedEncodingType;
+
+
+/**
+ * The action used to store the tr-type
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreTrType extends AbstractReadInteger
+{
+
+    /**
+     * Instantiates a new StoreTrType action.
+     */
+    public StoreTrType()
+    {
+        super( "TransitedEncoding tr-type" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setIntegerValue( int value, Asn1Container container )
+    {
+        TransitedEncodingContainer transitedEncodingContainer = ( TransitedEncodingContainer ) container;
+        TransitedEncodingType type = TransitedEncodingType.getTypeByOrdinal( value );
+        transitedEncodingContainer.getTransitedEncoding().setTrType( type );
+    }
+
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/TransitedEncodingInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/TransitedEncodingInit.java?rev=1037104&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/TransitedEncodingInit.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/transitedEncoding/actions/TransitedEncodingInit.java Sat Nov 20 02:04:50 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.transitedEncoding.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.transitedEncoding.TransitedEncodingContainer;
+import org.apache.directory.shared.kerberos.components.TransitedEncoding;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the TransitedEncoding object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TransitedEncodingInit extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( TransitedEncodingInit.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new TransitedEncodingInit action.
+     */
+    public TransitedEncodingInit()
+    {
+        super( "Creates a TransitedEncoding instance" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        TransitedEncodingContainer transitedEncodingContainer = ( TransitedEncodingContainer ) container;
+
+        TLV tlv = transitedEncodingContainer.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 ) );
+        }
+        
+        TransitedEncoding transitedEncoding = new TransitedEncoding();
+        transitedEncodingContainer.setTransitedEncoding( transitedEncoding );
+        
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "TransitedEncoding created" );
+        }
+    }
+}