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/16 14:29:21 UTC

svn commit: r1035632 - in /directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq: ./ AsReqContainer.java AsReqGrammar.java AsReqStatesEnum.java actions/ actions/StoreKdcReq.java

Author: elecharny
Date: Tue Nov 16 13:29:21 2010
New Revision: 1035632

URL: http://svn.apache.org/viewvc?rev=1035632&view=rev
Log:
Added the AS-REQ message decoder

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/actions/StoreKdcReq.java

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqContainer.java?rev=1035632&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqContainer.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqContainer.java Tue Nov 16 13:29:21 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.asReq;
+
+import org.apache.directory.shared.kerberos.codec.kdcReq.KdcReqContainer;
+import org.apache.directory.shared.kerberos.messages.AsReq;
+
+
+/**
+ * The AS-REQ container stores the KdcReq decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AsReqContainer extends KdcReqContainer
+{
+    /** An AS-REQ container */
+    private AsReq asReq;
+
+    /**
+     * Creates a new AsReqContainer object.
+     */
+    public AsReqContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = AsReqGrammar.getInstance();
+        setTransition( AsReqStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the AsReq.
+     */
+    public AsReq getAsReq()
+    {
+        return asReq;
+    }
+
+    
+    /**
+     * Set an AsReq Object into the container. It will be completed by the
+     * KerberosDecoder.
+     * 
+     * @param asReq The AsReq to set.
+     */
+    public void setAsReq( AsReq asReq )
+    {
+        this.asReq = asReq;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqGrammar.java?rev=1035632&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqGrammar.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqGrammar.java Tue Nov 16 13:29:21 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.asReq;
+
+
+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.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.codec.asReq.actions.StoreKdcReq;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the AS-REQ 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 AsReqGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( AsReqGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. AsReqGrammar is a singleton */
+    private static Grammar instance = new AsReqGrammar();
+
+
+    /**
+     * Creates a new AsReqGrammar object.
+     */
+    private AsReqGrammar()
+    {
+        setName( AsReqGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[AsReqStatesEnum.LAST_AS_REQ_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // AS-REQ 
+        // ============================================================================================
+        // --------------------------------------------------------------------------------------------
+        // Transition from AS-REQ init to KDC-REQ
+        // --------------------------------------------------------------------------------------------
+        // AS-REQ          ::= [APPLICATION 10] KDC-REQ
+        super.transitions[AsReqStatesEnum.START_STATE.ordinal()][KerberosConstants.AS_REQ_TAG] = new GrammarTransition(
+            AsReqStatesEnum.START_STATE, AsReqStatesEnum.AS_REQ_STATE, KerberosConstants.AS_REQ_TAG,
+            new StoreKdcReq() );
+    }
+
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the AS-REQ Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqStatesEnum.java?rev=1035632&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqStatesEnum.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/AsReqStatesEnum.java Tue Nov 16 13:29:21 2010
@@ -0,0 +1,105 @@
+/*
+ *  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.asReq;
+
+
+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 AS-REQ grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum AsReqStatesEnum implements States
+{
+    // Start
+    START_STATE,                            // 0
+    
+    // ----- HostAddresses message --------------------------------------
+    AS_REQ_STATE,                           // 1
+    
+    // End
+    LAST_AS_REQ_STATE;                      // 2
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "AS_REQ_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar grammar )
+    {
+        if ( grammar instanceof KerberosMessageGrammar )
+        {
+            return "AS_REQ_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_AS_REQ_STATE.ordinal() ) ? "AS_REQ_END_STATE" : name() );
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_AS_REQ_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public AsReqStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/actions/StoreKdcReq.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/actions/StoreKdcReq.java?rev=1035632&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/actions/StoreKdcReq.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/asReq/actions/StoreKdcReq.java Tue Nov 16 13:29:21 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.asReq.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.KerberosMessageGrammar;
+import org.apache.directory.shared.kerberos.codec.asReq.AsReqContainer;
+import org.apache.directory.shared.kerberos.codec.kdcReq.KdcReqContainer;
+import org.apache.directory.shared.kerberos.messages.AsReq;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to add a KDC-REQ object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreKdcReq extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new KDC-REQ action.
+     */
+    public StoreKdcReq()
+    {
+        super( "Add an KDC-REQ instance" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        AsReqContainer asReqContainer = ( AsReqContainer ) container;
+
+        TLV tlv = asReqContainer.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 KDC-REQ
+        Asn1Decoder kdcReqDecoder = new Asn1Decoder();
+        
+        KdcReqContainer kdcReqContainer = new KdcReqContainer();
+        kdcReqContainer.setStream( container.getStream() );
+        
+        // Store the created AS-REQ object into the KDC-REQ container
+        AsReq asReq = new AsReq();
+        kdcReqContainer.setKdcReq( asReq );
+        
+        // Decode the KDC_REQ PDU
+        try
+        {
+            kdcReqDecoder.decode( container.getStream(), kdcReqContainer );
+        }
+        catch ( DecoderException de )
+        {
+            throw de;
+        }
+        
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+        // Update the parent
+        container.updateParent();
+        
+        asReqContainer.setAsReq( asReq );
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "AS-REQ : {}", asReq );
+        }
+        
+        container.setGrammarEndAllowed( true );
+    }
+}