directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r165436 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java
Date Sat, 30 Apr 2005 23:16:31 GMT
Author: elecharny
Date: Sat Apr 30 16:16:30 2005
New Revision: 165436

URL: http://svn.apache.org/viewcvs?rev=165436&view=rev
Log:
Added a lot of actions to the Spnego grammar. A third of all actions has been implemented,
so far, and the last actions will be easier.

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

Modified: 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=165436&r1=165435&r2=165436&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java
Sat Apr 30 16:16:30 2005
@@ -22,10 +22,14 @@
 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.ber.tlv.TLV;
+import org.apache.asn1.primitives.OID;
+import org.apache.asn1.primitives.OctetString;
 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.PoolEnum;
 import org.apache.asn1.util.pools.PoolException;
 
 import org.apache.log4j.Logger;
@@ -64,7 +68,7 @@
 
         statesEnum = SpnegoStatesEnum.getInstance();
 
-        // We have
+        // Initialisation of the transition's table.
         super.transitions = new GrammarTransition[SpnegoStatesEnum.LAST_SPNEGO_STATE][256];
 
         //============================================================================================
@@ -72,7 +76,8 @@
         //============================================================================================
         // SPNEGO --> CHOICE {
         //      negTokenInit  [0]  NegTokenInit, (Tag)
-        // We have a negTokenInit, and the tag must be 0xA0
+        // We have a negTokenInit, and the tag must be 0xA0. We will create the Spnego POJO
+        // here, and store it in the container.
         super.transitions[SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_TAG][0xA0] =
             new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_TAG,
                 SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_LENGTH,
@@ -107,7 +112,7 @@
         // SPNEGO --> CHOICE { ...
         //      negTokenInit  [0]  NegTokenInit, (Length)
         // We have a negTokenInit, and the tag must be 0xA0
-        // Ok, get the negTokenInit length
+        // We get the negTokenInit length, and store it in the Spnego POJO 
         super.transitions[SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_LENGTH][0xA0] =
             new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_LENGTH,
                 SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_VALUE,
@@ -136,13 +141,21 @@
                 SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_TAG, null );
 
         // NegTokenInit ::= SEQUENCE { (Tag)
-        // Nothing to do, but setting the parent link.
+        //    mechTypes     [0]  MechTypeList  OPTIONAL,
+        //    reqFlags      [1]  ContextFlags  OPTIONAL,
+        //    mechToken     [2]  OCTET STRING  OPTIONAL,
+        //    mechListMIC   [3]  OCTET STRING  OPTIONAL }
+        // Nothing to do here, it's just a tag...
         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
+        //    mechTypes     [0]  MechTypeList  OPTIONAL,
+        //    reqFlags      [1]  ContextFlags  OPTIONAL,
+        //    mechToken     [2]  OCTET STRING  OPTIONAL,
+        //    mechListMIC   [3]  OCTET STRING  OPTIONAL }
+        // We have to check the length, and set the new expected 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,
@@ -150,11 +163,18 @@
                 {
                     public void action( IAsn1Container container ) throws DecoderException
                     {
-
-                        // We have to store the expected Length of the PDU
+                        // first, we check that the length is OK
                         SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
-                        SpnegoPOJO      spnego          = spnegoContainer.getSpnego();
-                        checkLength( spnego, spnegoContainer.getCurrentTLV() );
+                        SpnegoNegTokenInitPOJO spnego   = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
+                        TLV             tlv             = spnegoContainer.getCurrentTLV();
+                        checkLength( spnego, tlv );
+                        
+                        // Second, we store the new expected length into the global
+                        // expected length, as it won't be usefull any more (this is
+                        // an optimisation, we could have declared another class
+                        // member to do this.) We also reset the current length to 0.
+                        spnego.setExpectedLength( tlv.getLength().getLength() );
+                        spnego.setCurrentLength(0);
                         return;
                     }
                 } );
@@ -175,7 +195,7 @@
         // NegTokenInit ::= SEQUENCE {
         //    mechTypes     [0]  MechTypeList  OPTIONAL, (Tag)
         //    ...
-        // We have a 0xA0 tag, so this is a mechTypes.
+        // We have a 0xA0 tag, so this is a mechTypes. We have nothing to do.
         super.transitions[SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_FOLLOWING_TAG][0xA0]
=
             new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_FOLLOWING_TAG,
                 SpnegoStatesEnum.SPNEGO_MECH_TYPES_LENGTH, null );
@@ -184,18 +204,24 @@
         //    mechTypes     [0]  MechTypeList  OPTIONAL, (Length)
         //    ...
         // MechTypeList ::= SEQUENCE OF MechType 
-        // The value part. As it is a SEQUENCE, we have to allocate a list
-        // in the Spnego object
+        // The Length part. We just have to check the length and store the sequence
+        // expected length.
         super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPES_LENGTH][0xA0] =
             new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TYPES_LENGTH,
                 SpnegoStatesEnum.SPNEGO_MECH_TYPES_VALUE, 
-                new GrammarAction( "Mech Type list sequence Length" )
+                new GrammarAction( "Mech Type list Length" )
                 {
                     public void action( IAsn1Container container ) throws DecoderException
                     {
-                        /*SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
-                        SpnegoPOJO      spnego          = spnegoContainer.getSpnego();
-                        checkLength( spnego, spnegoContainer.getCurrentTLV() );*/
+                        SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+                        SpnegoNegTokenInitPOJO spnego   = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
+                        TLV				tlv 			= spnegoContainer.getCurrentTLV();
+                        
+                        // Checks the length.
+                        checkLength(spnego, tlv);
+                        
+                        // Stores the current length in the associated accumulator.
+                        spnego.setMechTypesExpectedLength(tlv.getLength().getLength());
                         return;
                     }
                 } );
@@ -203,44 +229,115 @@
         // NegTokenInit ::= SEQUENCE {
         //    mechTypes     [0]  MechTypeList  OPTIONAL, (Value)
         //    ...
-        // 
-        super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPES_VALUE][0xA0]       = new GrammarTransition(
+        // Nothing to do.
+        super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPES_VALUE][0xA0] = new GrammarTransition(
                 SpnegoStatesEnum.SPNEGO_MECH_TYPES_VALUE,
                 SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_TAG, null );
 
         // MechTypeList ::= SEQUENCE OF MechType (Tag) 
+        // Nothing to do
         super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_TAG][0x30] =
             new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_TAG,
                 SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_LENGTH, null );
 
-        // MechTypeList ::= SEQUENCE OF MechType (Length) 
+        // MechTypeList ::= SEQUENCE OF MechType (Length)
+        // We have to check the length.
         super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_LENGTH][0x30] =
             new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_LENGTH,
-                SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_VALUE, null );
+                SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_VALUE, new GrammarAction( "Mech Type
list sequence Length" )
+                {
+	                public void action( IAsn1Container container ) throws DecoderException
+	                {
+	                    SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+	                    SpnegoNegTokenInitPOJO spnego   = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
+	                    TLV				tlv 			= spnegoContainer.getCurrentTLV();
+	                    
+	                    // Checks the length.
+	                    int expectedLength = spnego.getMechTypesExpectedLength();
+	                    
+	                    int currentLength = tlv.getLength().getLength() + tlv.getSize();
+	                    
+	                    if (expectedLength < currentLength)
+	                    {
+	                        throw new DecoderException("The current length is longer than the
expected length");
+	                    }
+	                    
+	                    // Stores the expected length of the mech types.
+	                    spnego.setMechTypeListExpectedLength(tlv.getLength().getLength());
+	                    return;
+	                }
+                });
 
         // MechTypeList ::= SEQUENCE OF MechType (Value) 
-        // As it is a SEQUENCE, we have to allocate a list
-        // in the Spnego object
+        // Nothing to do.
         super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_VALUE][0x30] =
             new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_VALUE,
                 SpnegoStatesEnum.SPNEGO_MECH_TYPE_TAG, null );
 
-        // MechType ::= OBJECT IDENTIFIER (Tag) 
+        // MechType ::= OBJECT IDENTIFIER (Tag)
+        // Nothing to do.
         super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_TAG][0x06]    = new GrammarTransition(
                 SpnegoStatesEnum.SPNEGO_MECH_TYPE_TAG, SpnegoStatesEnum.SPNEGO_MECH_TYPE_LENGTH,
                 null );
 
-        // MechType ::= OBJECT IDENTIFIER (Length) 
+        // MechType ::= OBJECT IDENTIFIER (Length)
+        // We have to check the length.
         super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_LENGTH][0x06] = new GrammarTransition(
                 SpnegoStatesEnum.SPNEGO_MECH_TYPE_LENGTH, SpnegoStatesEnum.SPNEGO_MECH_TYPE_VALUE,
-                null );
+                new GrammarAction( "Mech Type Length" )
+                {
+	                public void action( IAsn1Container container ) throws DecoderException
+	                {
+	                    SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+	                    SpnegoNegTokenInitPOJO spnego   = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
+	                    TLV				tlv 			= spnegoContainer.getCurrentTLV();
+	                    
+	                    // Checks the length.
+	                    int expectedLength = spnego.getMechTypeListExpectedLength();
+	                    
+	                    int currentLength = tlv.getLength().getLength() + tlv.getSize();
+	                    
+	                    if (expectedLength < currentLength)
+	                    {
+	                        throw new DecoderException("The current length is longer than the
expected length");
+	                    }
+	                    
+	                    // Updates the current length.
+	                    spnego.setMechTypeListExpectedLength( expectedLength - currentLength
);
+	                    return;
+	                }
+                } );
 
         // MechType ::= OBJECT IDENTIFIER (Value) 
+        // Here we will add a new Mech Type to the MechTypeList
         super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_VALUE][0x06]  = new GrammarTransition(
                 SpnegoStatesEnum.SPNEGO_MECH_TYPE_VALUE,
-                SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG, null );
+                SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG, new GrammarAction( "Mech
Type Value" )
+                {
+	                public void action( IAsn1Container container ) throws DecoderException
+	                {
+	                    SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+	                    SpnegoNegTokenInitPOJO spnego   = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
+	                    TLV				tlv 			= spnegoContainer.getCurrentTLV();
+	                    
+	                    // Creates a new OID, and add it to the mech type list
+	                    try
+	                    {
+	                        OID oid = (OID)(spnegoContainer.getPoolManager().allocate(PoolEnum.OID_POOL));
+	                    
+	                        oid.setOID(tlv.getValue().getData());
+	                        spnego.addMechTypeList( oid );
+	                    }
+	                    catch (PoolException pe)
+	                    {
+	                        throw new DecoderException("Cannot allocate an OID");
+	                    }
+	                    return;
+	                }
+                } );
 
         // MechType ::= OBJECT IDENTIFIER (Tag) 
+        // Nothing to do, this is just a recursive call.
         super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG][0x06]    = new
GrammarTransition(
                 SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG, SpnegoStatesEnum.SPNEGO_MECH_TYPE_LENGTH,
                 null );
@@ -327,35 +424,50 @@
         //    ...
         //    mechToken     [2]  OCTET STRING  OPTIONAL,
         //    ...
+        // We have to check the length
         super.transitions[SpnegoStatesEnum.SPNEGO_REQ_FLAGS_FOLLOWING_TAG][0xA2] =
             new GrammarTransition( SpnegoStatesEnum.SPNEGO_REQ_FLAGS_FOLLOWING_TAG,
-                SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH, null );
+                SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH, new GrammarAction( "Mech Token
Length" )
+                {
+                public void action( IAsn1Container container ) throws DecoderException
+                {
+                    SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+                    SpnegoNegTokenInitPOJO spnego   = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
+                    TLV				tlv 			= spnegoContainer.getCurrentTLV();
+                    
+                    // Checks the length.
+                    checkLength(spnego, tlv);
+                    return;
+                }
+            }  );
 
         // NegTokenInit ::= SEQUENCE {
         //    ...
-        //    mechToken     [2]  OCTET STRING  OPTIONAL,
+        //    mechToken     [2]  OCTET STRING  OPTIONAL, (Tag)
         //    ...
+        // Nothing to do.
         super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG][0xA2] =
             new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG,
-                SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH, null );
+                SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH, null);
 
         // NegTokenInit ::= SEQUENCE {
         //    ...
-        //    mechToken     [2]  OCTET STRING  OPTIONAL,
+        //    mechToken     [2]  OCTET STRING  OPTIONAL, (Tag)
         //    ...
         super.transitions[SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_FOLLOWING_TAG][0xA2]
=
             new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_FOLLOWING_TAG,
                 SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH, null );
 
-        // NegTokenInit ::= SEQUENCE { (Value)
+        // NegTokenInit ::= SEQUENCE { 
         //    ...
-        //    mechToken     [2]  OCTET STRING  OPTIONAL,
+        //    mechToken     [2]  OCTET STRING  OPTIONAL, (Length)
         //    ...
         super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH][0xA2] =
             new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH,
                 SpnegoStatesEnum.SPNEGO_MECH_TOKEN_VALUE, null );
 
-        // mechToken     [2]  OCTET STRING  OPTIONAL, (Tag)
+        // mechToken     [2]  OCTET STRING  OPTIONAL, (Value)
+        // Nothing to do
         super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TOKEN_VALUE][0xA2]    = new GrammarTransition(
                 SpnegoStatesEnum.SPNEGO_MECH_TOKEN_VALUE, SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_TAG,
                 null );
@@ -366,14 +478,39 @@
                 null );
 
         // mechToken     [2]  OCTET STRING  OPTIONAL, (Length)
+        // Checks the length
         super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_LENGTH][0x04] =
new GrammarTransition(
                 SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_LENGTH, SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_VALUE,
                 null );
 
         // mechToken     [2]  OCTET STRING  OPTIONAL, (Value)
+        // We will allocate a new Octet String.
         super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_VALUE][0x04]  =
new GrammarTransition(
                 SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_VALUE,
-                SpnegoStatesEnum.SPNEGO_METH_TOKEN_FOLLOWING_TAG, null );
+                SpnegoStatesEnum.SPNEGO_METH_TOKEN_FOLLOWING_TAG, new GrammarAction( "Mech
Token Value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+                        SpnegoNegTokenInitPOJO spnego   = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
+                        TLV				tlv 			= spnegoContainer.getCurrentTLV();
+                        
+                        // Creates a new mechToken
+                        try
+                        {
+                            OctetString mechToken = (OctetString)(spnegoContainer.getPoolManager().allocate(PoolEnum.OCTET_STRING_POOL));
+                        
+                            mechToken.setData(tlv.getValue().getData());
+                            
+                            spnego.setMechToken(mechToken);
+                        }
+                        catch (PoolException pe)
+                        {
+                            throw new DecoderException("Cannot allocate an OID");
+                        }
+                        return;
+                    }
+                } );
 
         //------------------------------------------------------------------------------------------
         // NegTokenInit ::= SEQUENCE {



Mime
View raw message