Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 7157 invoked from network); 7 Sep 2006 05:28:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 7 Sep 2006 05:28:03 -0000 Received: (qmail 41354 invoked by uid 500); 7 Sep 2006 05:28:02 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 41317 invoked by uid 500); 7 Sep 2006 05:28:02 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 41306 invoked by uid 99); 7 Sep 2006 05:28:02 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Sep 2006 22:28:02 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Sep 2006 22:28:01 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 01F521A981A; Wed, 6 Sep 2006 22:27:41 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20060907052741.01F521A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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; } }