directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r440980 - in /directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind: BindRequestAsn1Ber.java SaslCredentialsAsn1Ber.java SimpleAuthenticationAsn1Ber.java
Date Thu, 07 Sep 2006 05:27:40 GMT
Author: elecharny
Date: Wed Sep  6 22:27:40 2006
New Revision: 440980

URL: http://svn.apache.org/viewvc?view=rev&rev=440980
Log:
Added the encode implementation for those classes (it does not compile
atm, due to lacking methods in Value)

Modified:
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestAsn1Ber.java
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SaslCredentialsAsn1Ber.java
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SimpleAuthenticationAsn1Ber.java

Modified: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestAsn1Ber.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestAsn1Ber.java?view=diff&rev=440980&r1=440979&r2=440980
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestAsn1Ber.java
(original)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestAsn1Ber.java
Wed Sep  6 22:27:40 2006
@@ -19,9 +19,15 @@
  */
 package org.apache.directory.shared.ldap.codec.asn1ber.messages.bind;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
 import org.apache.directory.shared.asn1.ber.Decoder;
 import org.apache.directory.shared.asn1.ber.Encoder;
 import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.ldap.codec.asn1ber.messages.EncoderException;
+import org.apache.directory.shared.ldap.codec.asn1ber.messages.LdapBerTags;
 import org.apache.directory.shared.ldap.messages.Message;
 import org.apache.directory.shared.ldap.messages.bind.AuthenticationDecorator;
 import org.apache.directory.shared.ldap.messages.bind.BindRequestDecorator;
@@ -105,5 +111,52 @@
         }
 
         return length;
+    }
+    
+    /**
+     * Encode the BindRequest message to a PDU. 
+     * 
+     * 0x60 LL
+     *   0x02 LL version
+     *   0x04 LL name
+     *   authentication.encode()
+     *     0x80 LL simple
+     *    /
+     *    \
+     *     0x83 LL mechanism
+     *     [0x04 LL credential]
+     * 
+     * @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 BindRequest Tag
+            buffer.put( LdapBerTags.BIND_REQUEST_TAG.getValue() );
+            buffer.put( Length.getBytes( bindRequestLength ) );
+
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( "The PDU buffer size is too small !" );
+        }
+
+        // The version
+        Value.encode( buffer, getVersion() );
+
+        // The name
+        Value.encode( buffer, LdapDN.getBytes( getName() ) );
+
+        // The authentication
+        getAuthentication().encode( buffer );
+
+        return buffer;
     }
 }

Modified: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SaslCredentialsAsn1Ber.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SaslCredentialsAsn1Ber.java?view=diff&rev=440980&r1=440979&r2=440980
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SaslCredentialsAsn1Ber.java
(original)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SaslCredentialsAsn1Ber.java
Wed Sep  6 22:27:40 2006
@@ -19,9 +19,16 @@
  */
 package org.apache.directory.shared.ldap.codec.asn1ber.messages.bind;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
 import org.apache.directory.shared.asn1.ber.Decoder;
 import org.apache.directory.shared.asn1.ber.Encoder;
 import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.ber.tlv.ValueException;
+import org.apache.directory.shared.ldap.codec.asn1ber.messages.EncoderException;
+import org.apache.directory.shared.ldap.codec.asn1ber.messages.LdapBerTags;
 import org.apache.directory.shared.ldap.messages.bind.Authentication;
 import org.apache.directory.shared.ldap.messages.bind.SaslCredentialsDecorator;
 import org.apache.directory.shared.ldap.utils.StringTools;
@@ -97,5 +104,49 @@
         }
 
         return saslLength;
+    }
+    
+    /**
+     * Encode the sasl authentication to a PDU. 
+     * SaslCredentials : 
+     * 0xA3 L1 0x04 L2 mechanism [0x04 L3 credentials]
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            log.error( "Cannot put a PDU in a null buffer !" );
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try
+        {
+            // The saslAuthentication Tag
+            buffer.put( LdapBerTags.BIND_REQUEST_SASL_TAG.getValue() );
+
+            buffer.put( Length.getBytes( mechanismLength + credentialsLength ) );
+
+            Value.encode( buffer, mechanismBytes );
+
+            if ( getCredentials() != null )
+            {
+                Value.encode( buffer, getCredentials() );
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            log.error( "The PDU buffer size is too small !" );
+            throw new EncoderException( "The PDU buffer size is too small !" );
+        }
+        catch ( ValueException ve )
+        {
+            log.error( "The value is invalid !" );
+            throw new EncoderException( "The value is invalid !" );
+        }
+
+        return buffer;
     }
 }

Modified: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SimpleAuthenticationAsn1Ber.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SimpleAuthenticationAsn1Ber.java?view=diff&rev=440980&r1=440979&r2=440980
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SimpleAuthenticationAsn1Ber.java
(original)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SimpleAuthenticationAsn1Ber.java
Wed Sep  6 22:27:40 2006
@@ -19,9 +19,14 @@
  */
 package org.apache.directory.shared.ldap.codec.asn1ber.messages.bind;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
 import org.apache.directory.shared.asn1.ber.Decoder;
 import org.apache.directory.shared.asn1.ber.Encoder;
 import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.ldap.codec.asn1ber.messages.EncoderException;
+import org.apache.directory.shared.ldap.codec.asn1ber.messages.LdapBerTags;
 import org.apache.directory.shared.ldap.messages.bind.Authentication;
 import org.apache.directory.shared.ldap.messages.bind.SimpleAuthenticationDecorator;
 import org.slf4j.Logger;
@@ -71,5 +76,41 @@
         }
 
         return length;
+    }
+
+    /**
+     * 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 )
+        {
+            log.error( "Cannot put a PDU in a null buffer !" );
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try
+        {
+            // The simpleAuthentication Tag
+            buffer.put( LdapBerTags.BIND_REQUEST_SIMPLE_TAG.getValue() );
+            buffer.put( Length.getBytes( getSimple().length ) );
+
+            if ( getSimple().length != 0 )
+            {
+                buffer.put( getSimple() );
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            log.error( "The PDU buffer size is too small !" );
+            throw new EncoderException( "The PDU buffer size is too small !" );
+        }
+
+        return buffer;
     }
 }



Mime
View raw message