directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r226668 - in /directory/sandbox/trunk/asn1-new-codec/src: java/org/apache/asn1/ldap/codec/grammars/ java/org/apache/asn1/ldap/pojo/ test/org/apache/asn1/ldap/codec/
Date Sun, 31 Jul 2005 17:47:39 GMT
Author: elecharny
Date: Sun Jul 31 10:47:30 2005
New Revision: 226668

URL: http://svn.apache.org/viewcvs?rev=226668&view=rev
Log:
Added the encoding of a BindRequest message

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindRequestGrammar.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SaslCredentials.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SimpleAuthentication.java
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/BindRequestTest.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindRequestGrammar.java?rev=226668&r1=226667&r2=226668&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindRequestGrammar.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindRequestGrammar.java
Sun Jul 31 10:47:30 2005
@@ -24,6 +24,7 @@
 import org.apache.asn1.ber.grammar.IGrammar;
 import org.apache.asn1.ber.tlv.TLV;
 import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.LdapMessageContainer;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
@@ -91,13 +92,13 @@
         // We have to allocate a BindRequest
         // LdapMessage ::= ... BindRequest ...
         // BindRequest ::= [APPLICATION 0] SEQUENCE { ... (Length)
-        super.transitions[LdapStatesEnum.BIND_REQUEST_TAG][0x60]    = new GrammarTransition(
+        super.transitions[LdapStatesEnum.BIND_REQUEST_TAG][LdapConstants.BIND_REQUEST_TAG]
   = new GrammarTransition(
                 LdapStatesEnum.BIND_REQUEST_TAG, LdapStatesEnum.BIND_REQUEST_VALUE, null
);
 
         // LdapMessage ::= ... BindRequest ...
         // BindRequest ::= [APPLICATION 0] SEQUENCE { ... (Value)
         // Nothing to do, the Value is empty, this is a constructed TLV. We now can swith
to the BindRequest Grammar
-        super.transitions[LdapStatesEnum.BIND_REQUEST_VALUE][0x60] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.BIND_REQUEST_VALUE][LdapConstants.BIND_REQUEST_TAG]
= new GrammarTransition(
                 LdapStatesEnum.BIND_REQUEST_VALUE, LdapStatesEnum.BIND_REQUEST_VERSION_TAG,

                 new GrammarAction( "Init BindRequest" )
                 {
@@ -116,12 +117,12 @@
 
         // BindRequest ::= ... version INTEGER (1 .. 127 ), ... (Tag)
         // Nothing to do.
-        super.transitions[LdapStatesEnum.BIND_REQUEST_VERSION_TAG][0x02] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.BIND_REQUEST_VERSION_TAG][LdapConstants.INTEGER_TAG]
= new GrammarTransition(
                 LdapStatesEnum.BIND_REQUEST_VERSION_TAG, LdapStatesEnum.BIND_REQUEST_VERSION_VALUE,
null );
 
         // BindRequest ::= ... version INTEGER (1 .. 127 ), ... (value)
         // Checks that the Version is in [1, 127]
-        super.transitions[LdapStatesEnum.BIND_REQUEST_VERSION_VALUE][0x02] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.BIND_REQUEST_VERSION_VALUE][LdapConstants.INTEGER_TAG]
= new GrammarTransition(
                 LdapStatesEnum.BIND_REQUEST_VERSION_VALUE, LdapStatesEnum.BIND_REQUEST_NAME_TAG,
                 new GrammarAction( "Store version" )
                 {
@@ -149,12 +150,12 @@
 
         // BindRequest ::= ... name LDAPDN, ... (Tag)
         // Nothing to do. The tag is supposed to be 0x04
-        super.transitions[LdapStatesEnum.BIND_REQUEST_NAME_TAG][0x04] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.BIND_REQUEST_NAME_TAG][LdapConstants.OCTET_STRING_TAG]
= new GrammarTransition(
                 LdapStatesEnum.BIND_REQUEST_NAME_TAG, LdapStatesEnum.BIND_REQUEST_NAME_VALUE,
null );
 
         // BindRequest ::= ... name LDAPDN, ... (Value)
         // We have to store the name
-        super.transitions[LdapStatesEnum.BIND_REQUEST_NAME_VALUE][0x04] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.BIND_REQUEST_NAME_VALUE][LdapConstants.OCTET_STRING_TAG]
= new GrammarTransition(
                 LdapStatesEnum.BIND_REQUEST_NAME_VALUE,
                 LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG,
                 new GrammarAction( "Store Bind Name value" )
@@ -191,7 +192,7 @@
         // If it's 0x80, it is a SimpleAuthentication.
         //--------------------------------------------------------------------------------------------
         // Nothing to do.
-        super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG][0x80] =
+        super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG][LdapConstants.BIND_REQUEST_SIMPLE_TAG]
=
             new GrammarTransition( LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG,
                 LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE, null );
 
@@ -199,7 +200,7 @@
         //        simple         [0] OCTET STRING, (Value)
         // We have to create an Authentication Object to store the credentials.
         // The nextState is GRAMMAR_END
-        super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE][( 0x80
& 0x00FF )] =
+        super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE][LdapConstants.BIND_REQUEST_SIMPLE_TAG]
=
             new GrammarTransition( LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE,
                 LdapStatesEnum.GRAMMAR_END,
                 new GrammarAction( "Store Bind Simple Authentication value" )
@@ -248,7 +249,7 @@
         // AuthenticationChoice ::= CHOICE {
         //        sasl         [3] saslCredentials, (Tag)
         // Nothing to do. In fact, 0x83 is the mechanism tag. 
-        super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG][( 0x83 &
0x00FF )] =
+        super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG][LdapConstants.BIND_REQUEST_SASL_TAG]
=
             new GrammarTransition( LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG,
                 LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM_VALUE, null );
 
@@ -259,7 +260,7 @@
         //        mechanism     LDAPSTRING,  (Value)
         //		  ...
         // We have to store the mechanism.
-        super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM_VALUE][( 0x83
& 0x00FF )] =
+        super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM_VALUE][LdapConstants.BIND_REQUEST_SASL_TAG]
=
             new GrammarTransition( LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM_VALUE,
                 LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG,
                 new GrammarAction( "Create Bind sasl Authentication Object" )
@@ -306,14 +307,14 @@
         //	- any other value is an error.
         //
         // It's a credential if it's 0x04
-        super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG][0x04]
=
+        super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG][LdapConstants.OCTET_STRING_TAG]
=
             new GrammarTransition( LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG,
                 LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_VALUE, null );
 
         // It's a control if it's 0x90
-        super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG][0x90]
=
-            new GrammarTransition( LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG,
-                LdapStatesEnum.GRAMMAR_END, null );
+        //super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG][0x90]
=
+        //    new GrammarTransition( LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG,
+        //        LdapStatesEnum.GRAMMAR_END, null );
         
         // SaslCredentials ::= SEQUENCE {
         //        ...
@@ -325,7 +326,7 @@
         // - or nothing at all (end of the BindRequest).
         // We just have to transit to the first case, which will accept or not the transition.
         // This is done by transiting to the GRAMMAR_END state
-        super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_VALUE][0x04]
=
+        super.transitions[LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_VALUE][LdapConstants.OCTET_STRING_TAG]
=
             new GrammarTransition( LdapStatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_VALUE,
                 LdapStatesEnum.GRAMMAR_END,
                 new GrammarAction( "Store Bind sasl Authentication credentials value" )

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java?rev=226668&r1=226667&r2=226668&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java
Sun Jul 31 10:47:30 2005
@@ -207,7 +207,7 @@
 
         try 
         {
-            // The SearchResultReference Tag
+            // The ModifyDNRequest Tag
             buffer.put( LdapConstants.MODIFY_DN_REQUEST_TAG );
             buffer.put( Length.getBytes( modifyDNRequestLength ) ) ;
 

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SaslCredentials.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SaslCredentials.java?rev=226668&r1=226667&r2=226668&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SaslCredentials.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SaslCredentials.java
Sun Jul 31 10:47:30 2005
@@ -16,8 +16,14 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
 import org.apache.asn1.primitives.OctetString;
 
@@ -111,6 +117,44 @@
         return saslLength;
     }
     
+    /**
+     * Encode the sasl authentication to a PDU.
+     * 
+     * SimpleAuthentication :
+     * 
+     * 0x83 LL mechanism
+     * [0x04 LL credentials]
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            // The simpleAuthentication Tag
+            buffer.put( (byte)LdapConstants.BIND_REQUEST_SASL_TAG );
+            buffer.put( Length.getBytes( mechanism.getLength() ) ) ;
+            buffer.put( mechanism.getData() ) ;
+            
+            if ( credentials != null )
+            {
+                Value.encode( buffer, credentials );
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return buffer;
+    }
+
     /**
      * Get a String representation of a SaslCredential
      *

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SimpleAuthentication.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SimpleAuthentication.java?rev=226668&r1=226667&r2=226668&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SimpleAuthentication.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SimpleAuthentication.java
Sun Jul 31 10:47:30 2005
@@ -16,8 +16,13 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.primitives.OctetString;
 
 
@@ -71,6 +76,38 @@
         return 1 + Length.getNbBytes( simple.getLength() ) + simple.getLength();
     }
     
+    /**
+     * Encode the simple authentication to a PDU.
+     * 
+     * SimpleAuthentication :
+     * 
+     * 0x80 LL simple
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            // The simpleAuthentication Tag
+            buffer.put( (byte)LdapConstants.BIND_REQUEST_SIMPLE_TAG );
+            buffer.put( Length.getBytes( simple.getLength() ) ) ;
+            buffer.put( simple.getValue() ) ;
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return buffer;
+    }
+
     /**
      * Return the simple authentication as a string
      *

Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/BindRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/BindRequestTest.java?rev=226668&r1=226667&r2=226668&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/BindRequestTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/BindRequestTest.java
Sun Jul 31 10:47:30 2005
@@ -19,12 +19,14 @@
 import java.nio.ByteBuffer;
 
 import org.apache.asn1.DecoderException;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.Asn1Decoder;
 import org.apache.asn1.ber.containers.IAsn1Container;
 import org.apache.asn1.ldap.pojo.BindRequest;
 import org.apache.asn1.ldap.pojo.LdapMessage;
 import org.apache.asn1.ldap.pojo.SaslCredentials;
 import org.apache.asn1.ldap.pojo.SimpleAuthentication;
+import org.apache.asn1.util.StringUtils;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 
@@ -68,6 +70,7 @@
 				'p', 'a', 's', 's', 'w', 'o', 'r', 'd'
             } );
 
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a LdapMessage Container
@@ -96,6 +99,21 @@
 
         // Check the length
         Assert.assertEquals(0x35, message.computeLength());
+        
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
     }
 
     /**
@@ -167,6 +185,7 @@
 				'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4'
             } );
 
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a LdapMessage Container
@@ -195,6 +214,21 @@
 
         // Check the length
         Assert.assertEquals(0x38, message.computeLength());
+        
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
     }
 
     /**
@@ -230,6 +264,7 @@
 				'a', 'b', 'c', 'd', 'e', 'f'
             } );
 
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a LdapMessage Container
@@ -259,5 +294,20 @@
 
         // Check the length
         Assert.assertEquals(0x40, message.computeLength());
+        
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
     }
 }



Mime
View raw message