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 2005/04/26 00:33:21 UTC

svn commit: r164676 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java

Author: elecharny
Date: Mon Apr 25 15:33:20 2005
New Revision: 164676

URL: http://svn.apache.org/viewcvs?rev=164676&view=rev
Log:
Added the first part of the SPNEGO Grammar, even if is not finished. (so I can't check it out from office;)

Added:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java?rev=164676&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java (added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java Mon Apr 25 15:33:20 2005
@@ -0,0 +1,155 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1.spnego.codec.grammars;
+
+import org.apache.asn1.DecoderException;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ber.grammar.AbstractGrammar;
+import org.apache.asn1.ber.grammar.GrammarAction;
+import org.apache.asn1.ber.grammar.GrammarTransition;
+import org.apache.asn1.ber.grammar.IGrammar;
+import org.apache.asn1.ldap.codec.grammars.LdapStatesEnum;
+import org.apache.asn1.spnego.codec.SpnegoContainer;
+import org.apache.asn1.spnego.codec.SpnegoPoolEnum;
+import org.apache.asn1.spnego.pojo.SpnegoNegTokenInitPOJO;
+import org.apache.asn1.spnego.pojo.SpnegoPOJO;
+import org.apache.asn1.util.pools.PoolException;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * This class implements the LdapMessage. 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 class SpnegoGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = Logger.getLogger( SpnegoGrammar.class );
+
+    /** Logging speed up  */
+    private static final boolean DEBUG = log.isDebugEnabled();
+
+    /** The instance of grammar. LdapMessageGrammar is a singleton */
+    private static IGrammar instance = new SpnegoGrammar();
+
+    /**
+     * Get the instance of this grammar
+     *
+     * @return An instance on the LdapMessage Grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+    
+    //~ Constructors -------------------------------------------------------------------------------
+    /**
+     * Creates a new LdapMessageGrammar object.
+     */
+    private SpnegoGrammar()
+    {
+
+        name = SpnegoGrammar.class.getName();
+
+        statesEnum = SpnegoStatesEnum.getInstance();
+
+        // We have 
+        super.transitions = new GrammarTransition[SpnegoStatesEnum.LAST_SPNEGO_STATE][256];
+
+        //============================================================================================
+        // SPNEGO 
+        //============================================================================================
+        // SPNEGO --> CHOICE {
+        //      negTokenInit  [0]  NegTokenInit, (Tag)
+        // We have a negTokenInit, and the tag must be 0xA0
+        super.transitions[SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_TAG][0xA0] = new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_TAG,
+                SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_LENGTH, new GrammarAction( "Spnego neg token init tag" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                    	try {
+	                    	SpnegoContainer spnegoContainer = (SpnegoContainer)container;
+	
+	                        // First, create a empty Spnego POJO
+	                    	SpnegoPOJO spnegoPOJO = ( SpnegoNegTokenInitPOJO) spnegoContainer.getPoolManager().allocate(SpnegoPoolEnum.SPNEGO_NEG_TOKEN_INIT_POJO_POOL);
+	
+	                        // Then stores it into the container
+	                    	spnegoContainer.setSpnego(spnegoPOJO);
+	                        
+	                        return;
+	                    }
+	                    catch ( PoolException pe )
+	                    {
+	                        throw new DecoderException(
+	                            "Cannot allocate a spnego Pojo : " + pe.getMessage() );
+	                    }
+                    }
+                } );
+
+        // SPNEGO --> CHOICE { ... 
+        //      negTokenInit  [0]  NegTokenInit, (Length)
+        // We have a negTokenInit, and the tag must be 0xA0
+        // Ok, get the negTokenInit length
+        super.transitions[SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_LENGTH][0xA0] = new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_LENGTH,
+                SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_VALUE, new GrammarAction( "Spnego neg token init Length" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                    	// We have to store the expected Length of the PDU
+                        SpnegoContainer spnegoContainer = (SpnegoContainer)container;
+                        SpnegoPOJO spnego = spnegoContainer.getSpnego();
+
+                        spnego.setExpectedLength(spnegoContainer.getCurrentTLV().getLength().getLength());
+                        spnego.setCurrentLength(0);
+
+                    	return;
+                    }
+                } );
+        
+        // SPNEGO --> CHOICE { ... 
+        //      negTokenInit  [0]  NegTokenInit, (Value)
+        // We will have a SEQUENCE. There is no value, so this is just a phantom transition.
+        super.transitions[SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_VALUE][0xA0] = new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_VALUE, SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_TAG, null);
+
+        // NegTokenInit ::= SEQUENCE { (Tag)
+        // Nothing to do, but setting the parent link.
+        super.transitions[SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_TAG][0x30] = new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_TAG, SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_LENGTH, null);
+
+        // NegTokenInit ::= SEQUENCE { (Length)
+        // We have to check the length
+        super.transitions[SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_LENGTH][0x30] = new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_LENGTH,
+                SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_VALUE, new GrammarAction( "Spnego neg token init sequence Length" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                    	// We have to store the expected Length of the PDU
+                        SpnegoContainer spnegoContainer = (SpnegoContainer)container;
+                        SpnegoPOJO spnego = spnegoContainer.getSpnego();
+                        checkLength(spnego, spnegoContainer.getCurrentTLV());
+                    	return;
+                    }
+                } );
+        
+    }
+}