Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 3604 invoked from network); 9 Aug 2010 10:19:04 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 9 Aug 2010 10:19:04 -0000 Received: (qmail 19624 invoked by uid 500); 9 Aug 2010 10:19:04 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 19565 invoked by uid 500); 9 Aug 2010 10:19: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 19554 invoked by uid 99); 9 Aug 2010 10:19:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Aug 2010 10:19:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Aug 2010 10:18:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 93AA123889E5; Mon, 9 Aug 2010 10:17:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r983573 [1/2] - in /directory/shared/branches/shared-codec-merge/ldap/src: main/java/org/apache/directory/shared/ldap/codec/ test/java/org/apache/directory/shared/ldap/codec/ test/java/org/apache/directory/shared/ldap/codec/bind/ Date: Mon, 09 Aug 2010 10:17:42 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100809101742.93AA123889E5@eris.apache.org> Author: elecharny Date: Mon Aug 9 10:17:41 2010 New Revision: 983573 URL: http://svn.apache.org/viewvc?rev=983573&view=rev Log: Migrated the BindRequest message Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java?rev=983573&r1=983572&r2=983573&view=diff ============================================================================== --- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java (original) +++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java Mon Aug 9 10:17:41 2010 @@ -45,6 +45,7 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.codec.unbind.UnBindRequestCodec; import org.apache.directory.shared.ldap.message.internal.InternalAbandonRequest; import org.apache.directory.shared.ldap.message.internal.InternalAddRequest; +import org.apache.directory.shared.ldap.message.internal.InternalBindRequest; import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest; import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest; import org.apache.directory.shared.ldap.message.internal.InternalMessage; @@ -199,6 +200,15 @@ public class LdapMessageContainer extend /** + * @return Returns the BindRequest stored in the container + */ + public InternalBindRequest getInternalBindRequest() + { + return ( InternalBindRequest ) internalMessage; + } + + + /** * @return Returns the BindResponse stored in the container */ public BindResponseCodec getBindResponse() Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java?rev=983573&r1=983572&r2=983573&view=diff ============================================================================== --- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java (original) +++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java Mon Aug 9 10:17:41 2010 @@ -71,10 +71,7 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.codec.actions.StoreTypeMatchingRuleAction; import org.apache.directory.shared.ldap.codec.actions.ValueAction; import org.apache.directory.shared.ldap.codec.add.AddResponseCodec; -import org.apache.directory.shared.ldap.codec.bind.BindRequestCodec; import org.apache.directory.shared.ldap.codec.bind.BindResponseCodec; -import org.apache.directory.shared.ldap.codec.bind.SaslCredentials; -import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication; import org.apache.directory.shared.ldap.codec.compare.CompareResponseCodec; import org.apache.directory.shared.ldap.codec.controls.ControlEnum; import org.apache.directory.shared.ldap.codec.controls.ControlImpl; @@ -98,6 +95,7 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.message.AbandonRequestImpl; import org.apache.directory.shared.ldap.message.AddRequestImpl; import org.apache.directory.shared.ldap.message.AddResponseImpl; +import org.apache.directory.shared.ldap.message.BindRequestImpl; import org.apache.directory.shared.ldap.message.BindResponseImpl; import org.apache.directory.shared.ldap.message.CompareRequestImpl; import org.apache.directory.shared.ldap.message.CompareResponseImpl; @@ -111,6 +109,7 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.message.control.Control; import org.apache.directory.shared.ldap.message.internal.InternalAbandonRequest; import org.apache.directory.shared.ldap.message.internal.InternalAddRequest; +import org.apache.directory.shared.ldap.message.internal.InternalBindRequest; import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest; import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest; import org.apache.directory.shared.ldap.message.internal.InternalMessage; @@ -487,9 +486,8 @@ public class LdapMessageGrammar extends LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; // Create the BindRequest LdapMessage instance and store it in the container - BindRequestCodec bindRequest = new BindRequestCodec(); - bindRequest.setMessageId( ldapMessageContainer.getMessageId() ); - ldapMessageContainer.setLdapMessage( bindRequest ); + InternalBindRequest bindRequest = new BindRequestImpl( ldapMessageContainer.getMessageId() ); + ldapMessageContainer.setInternalMessage( bindRequest ); // We will check that the request is not null TLV tlv = ldapMessageContainer.getCurrentTLV(); @@ -519,9 +517,8 @@ public class LdapMessageGrammar extends { public void action( IAsn1Container container ) throws DecoderException { - LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; - BindRequestCodec bindRequestMessage = ldapMessageContainer.getBindRequest(); + InternalBindRequest bindRequestMessage = ldapMessageContainer.getInternalBindRequest(); // The current TLV should be a integer between 1 and 127 // We get it and store it in Version @@ -538,7 +535,7 @@ public class LdapMessageGrammar extends log.debug( "Ldap version ", Integer.valueOf( version ) ); } - bindRequestMessage.setVersion( version ); + bindRequestMessage.setVersion3( version == 3 ); } catch ( IntegerDecoderException ide ) { @@ -567,7 +564,7 @@ public class LdapMessageGrammar extends public void action( IAsn1Container container ) throws DecoderException { LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; - BindRequestCodec bindRequestMessage = ldapMessageContainer.getBindRequest(); + InternalBindRequest bindRequestMessage = ldapMessageContainer.getInternalBindRequest(); // Get the Value and store it in the BindRequest TLV tlv = ldapMessageContainer.getCurrentTLV(); @@ -627,26 +624,20 @@ public class LdapMessageGrammar extends { LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; - BindRequestCodec bindRequestMessage = ldapMessageContainer.getBindRequest(); + InternalBindRequest bindRequestMessage = ldapMessageContainer.getInternalBindRequest(); TLV tlv = ldapMessageContainer.getCurrentTLV(); // Allocate the Authentication Object - SimpleAuthentication authentication = null; - - authentication = new SimpleAuthentication(); - - authentication.setParent( bindRequestMessage ); - - bindRequestMessage.setAuthentication( authentication ); + bindRequestMessage.setSimple( true ); // We have to handle the special case of a 0 length simple if ( tlv.getLength() == 0 ) { - authentication.setSimple( StringTools.EMPTY_BYTES ); + bindRequestMessage.setCredentials( StringTools.EMPTY_BYTES ); } else { - authentication.setSimple( tlv.getValue().getData() ); + bindRequestMessage.setCredentials( tlv.getValue().getData() ); } // We can have an END transition @@ -654,7 +645,8 @@ public class LdapMessageGrammar extends if ( IS_DEBUG ) { - log.debug( "The simple authentication is : {}", authentication.getSimple() ); + log.debug( "The simple authentication is : {}", StringTools.dumpBytes( bindRequestMessage + .getCredentials() ) ); } } } ); @@ -690,7 +682,7 @@ public class LdapMessageGrammar extends public void action( IAsn1Container container ) throws DecoderException { LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; - BindRequestCodec bindRequestMessage = ldapMessageContainer.getBindRequest(); + InternalBindRequest bindRequestMessage = ldapMessageContainer.getInternalBindRequest(); TLV tlv = ldapMessageContainer.getCurrentTLV(); // We will check that the sasl is not null @@ -705,12 +697,7 @@ public class LdapMessageGrammar extends bindRequestMessage.getName(), null ); } - // Create the SaslCredentials Object - SaslCredentials authentication = new SaslCredentials(); - - authentication.setParent( bindRequestMessage ); - - bindRequestMessage.setAuthentication( authentication ); + bindRequestMessage.setSimple( false ); if ( IS_DEBUG ) { @@ -734,21 +721,18 @@ public class LdapMessageGrammar extends public void action( IAsn1Container container ) throws DecoderException { LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; - BindRequestCodec bindRequestMessage = ldapMessageContainer.getBindRequest(); + InternalBindRequest bindRequestMessage = ldapMessageContainer.getInternalBindRequest(); TLV tlv = ldapMessageContainer.getCurrentTLV(); - // Get the SaslCredentials Object - SaslCredentials authentication = bindRequestMessage.getSaslAuthentication(); - // We have to handle the special case of a 0 length // mechanism if ( tlv.getLength() == 0 ) { - authentication.setMechanism( "" ); + bindRequestMessage.setSaslMechanism( "" ); } else { - authentication.setMechanism( StringTools.utf8ToString( tlv.getValue().getData() ) ); + bindRequestMessage.setSaslMechanism( StringTools.utf8ToString( tlv.getValue().getData() ) ); } // We can have an END transition @@ -756,7 +740,7 @@ public class LdapMessageGrammar extends if ( IS_DEBUG ) { - log.debug( "The mechanism is : {}", authentication.getMechanism() ); + log.debug( "The mechanism is : {}", bindRequestMessage.getSaslMechanism() ); } } } ); @@ -777,29 +761,29 @@ public class LdapMessageGrammar extends { LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; - BindRequestCodec bindRequestMessage = ldapMessageContainer.getBindRequest(); + InternalBindRequest bindRequestMessage = ldapMessageContainer.getInternalBindRequest(); // Get the Value and store it in the BindRequest TLV tlv = ldapMessageContainer.getCurrentTLV(); - SaslCredentials credentials = bindRequestMessage.getSaslAuthentication(); - // We have to handle the special case of a 0 length // credentials if ( tlv.getLength() == 0 ) { - credentials.setCredentials( StringTools.EMPTY_BYTES ); + bindRequestMessage.setCredentials( StringTools.EMPTY_BYTES ); } else { - credentials.setCredentials( tlv.getValue().getData() ); + bindRequestMessage.setCredentials( tlv.getValue().getData() ); } // We can have an END transition ldapMessageContainer.grammarEndAllowed( true ); + if ( IS_DEBUG ) { - log.debug( "The credentials are : {}", credentials.getCredentials() ); + log.debug( "The credentials are : {}", StringTools.dumpBytes( bindRequestMessage + .getCredentials() ) ); } } } ); Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java?rev=983573&r1=983572&r2=983573&view=diff ============================================================================== --- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java (original) +++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java Mon Aug 9 10:17:41 2010 @@ -24,17 +24,14 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.apache.directory.shared.asn1.Asn1Object; import org.apache.directory.shared.asn1.codec.DecoderException; import org.apache.directory.shared.asn1.primitives.OID; import org.apache.directory.shared.i18n.I18n; -import org.apache.directory.shared.ldap.codec.abandon.AbandonRequestCodec; import org.apache.directory.shared.ldap.codec.add.AddResponseCodec; import org.apache.directory.shared.ldap.codec.bind.BindRequestCodec; import org.apache.directory.shared.ldap.codec.bind.BindResponseCodec; import org.apache.directory.shared.ldap.codec.bind.SaslCredentials; import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication; -import org.apache.directory.shared.ldap.codec.compare.CompareRequestCodec; import org.apache.directory.shared.ldap.codec.compare.CompareResponseCodec; import org.apache.directory.shared.ldap.codec.del.DelResponseCodec; import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec; @@ -76,12 +73,10 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.filter.PresenceNode; import org.apache.directory.shared.ldap.filter.SimpleNode; import org.apache.directory.shared.ldap.filter.SubstringNode; -import org.apache.directory.shared.ldap.message.AbandonRequestImpl; import org.apache.directory.shared.ldap.message.AddResponseImpl; import org.apache.directory.shared.ldap.message.AliasDerefMode; import org.apache.directory.shared.ldap.message.BindRequestImpl; import org.apache.directory.shared.ldap.message.BindResponseImpl; -import org.apache.directory.shared.ldap.message.CompareRequestImpl; import org.apache.directory.shared.ldap.message.CompareResponseImpl; import org.apache.directory.shared.ldap.message.DeleteResponseImpl; import org.apache.directory.shared.ldap.message.ExtendedRequestImpl; @@ -97,7 +92,6 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.message.SearchResponseDoneImpl; import org.apache.directory.shared.ldap.message.SearchResponseEntryImpl; import org.apache.directory.shared.ldap.message.SearchResponseReferenceImpl; -import org.apache.directory.shared.ldap.message.UnbindRequestImpl; import org.apache.directory.shared.ldap.message.control.Control; import org.apache.directory.shared.ldap.message.extended.GracefulShutdownRequest; import org.apache.directory.shared.ldap.message.internal.InternalLdapResult; @@ -126,64 +120,6 @@ public class LdapTransformer /** - * Transform an AbandonRequest message from a codec Message to an - * InternalMessage - * - * @param codecMessage The message to transform - * @param messageId The message Id - * @return An internal AbandonRequest message - */ - private static InternalMessage transformAbandonRequest( AbandonRequestCodec abandonRequest, int messageId ) - { - AbandonRequestImpl internalMessage = new AbandonRequestImpl( messageId ); - - // Codec : int abandonnedMessageId -> Internal : int abandonId - internalMessage.setAbandoned( abandonRequest.getAbandonedMessageId() ); - - return internalMessage; - } - - - /** - * Transform a BindRequest message from a CodecMessage to a InternalMessage - * - * @param bindRequest The message to transform - * @param messageId The message Id - * @return A Internal BindRequestImpl - */ - private static InternalMessage transformBindRequest( BindRequestCodec bindRequest, int messageId ) - { - BindRequestImpl internalMessage = new BindRequestImpl( messageId ); - - // Codec : int version -> Internal : boolean isVersion3 - internalMessage.setVersion3( bindRequest.isLdapV3() ); - - // Codec : DN name -> Internal : DN name - internalMessage.setName( bindRequest.getName() ); - - // Codec : Asn1Object authentication instanceOf SimpleAuthentication -> - // Internal : boolean isSimple - // Codec : SimpleAuthentication OctetString simple -> Internal : byte [] - // credentials - Asn1Object authentication = bindRequest.getAuthentication(); - - if ( authentication instanceof SimpleAuthentication ) - { - internalMessage.setSimple( true ); - internalMessage.setCredentials( ( ( SimpleAuthentication ) authentication ).getSimple() ); - } - else - { - internalMessage.setSimple( false ); - internalMessage.setCredentials( ( ( SaslCredentials ) authentication ).getCredentials() ); - internalMessage.setSaslMechanism( ( ( SaslCredentials ) authentication ).getMechanism() ); - } - - return internalMessage; - } - - - /** * Transform a BindResponse message from a CodecMessage to a * InternalMessage. This is used by clients which are receiving a * BindResponse PDU and must decode it to return the Internal @@ -244,38 +180,6 @@ public class LdapTransformer /** - * Transform a CompareRequest message from a CodecMessage to a - * InternalMessage - * - * @param compareRequest The message to transform - * @param messageId The message Id - * @return A Internal CompareRequestImpl - */ - private static InternalMessage transformCompareRequest( CompareRequestCodec compareRequest, int messageId ) - { - CompareRequestImpl internalMessage = new CompareRequestImpl( messageId ); - - // Codec : DN entry -> Internal : private DN - internalMessage.setName( compareRequest.getEntry() ); - - // Codec : LdapString attributeDesc -> Internal : String attrId - internalMessage.setAttributeId( compareRequest.getAttributeDesc() ); - - // Codec : OctetString assertionValue -> Internal : byte[] attrVal - if ( compareRequest.getAssertionValue() instanceof String ) - { - internalMessage.setAssertionValue( ( String ) compareRequest.getAssertionValue() ); - } - else - { - internalMessage.setAssertionValue( ( byte[] ) compareRequest.getAssertionValue() ); - } - - return internalMessage; - } - - - /** * Transform an ExtendedRequest message from a CodecMessage to a * InternalMessage * @@ -724,19 +628,6 @@ public class LdapTransformer /** - * Transform an UnBindRequest message from a CodecMessage to a - * InternalMessage - * - * @param messageId The message Id - * @return A Internal UnBindRequestImpl - */ - private static InternalMessage transformUnBindRequest( int messageId ) - { - return new UnbindRequestImpl( messageId ); - } - - - /** * Transform the Codec message to a internal message. * * @param obj the object to transform @@ -759,10 +650,6 @@ public class LdapTransformer switch ( messageType ) { - case BIND_REQUEST: - internalMessage = transformBindRequest( ( BindRequestCodec ) codecMessage, messageId ); - break; - case SEARCH_REQUEST: internalMessage = transformSearchRequest( ( SearchRequestCodec ) codecMessage, messageId ); break; Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java?rev=983573&r1=983572&r2=983573&view=diff ============================================================================== --- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java (original) +++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java Mon Aug 9 10:17:41 2010 @@ -21,6 +21,7 @@ package org.apache.directory.shared.ldap import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.nio.ByteBuffer; @@ -31,8 +32,7 @@ import org.apache.directory.shared.asn1. import org.apache.directory.shared.asn1.ber.IAsn1Container; import org.apache.directory.shared.asn1.ber.tlv.TLVStateEnum; import org.apache.directory.shared.asn1.codec.DecoderException; -import org.apache.directory.shared.ldap.codec.bind.BindRequestCodec; -import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication; +import org.apache.directory.shared.ldap.message.internal.InternalBindRequest; import org.apache.directory.shared.ldap.util.StringTools; import org.junit.Test; import org.junit.runner.RunWith; @@ -61,15 +61,20 @@ public class LdapDecoderTest ByteBuffer stream = ByteBuffer.allocate( 0x35 ); stream.put( new byte[] - { 0x30, 0x33, // LDAPMessage ::=SEQUENCE { - 0x02, 0x01, 0x01, // messageID MessageID - 0x60, 0x2E, // CHOICE { ..., bindRequest BindRequest, ... + { 0x30, + 0x33, // LDAPMessage ::=SEQUENCE { + 0x02, 0x01, + 0x01, // messageID MessageID + 0x60, + 0x2E, // CHOICE { ..., bindRequest BindRequest, ... // BindRequest ::= APPLICATION[0] SEQUENCE { - 0x02, 0x01, 0x03, // version INTEGER (1..127), - 0x04, 0x1F, // name LDAPDN, + 0x02, 0x01, + 0x03, // version INTEGER (1..127), + 0x04, + 0x1F, // name LDAPDN, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', ( byte ) 0x80, 0x08, // authentication - // AuthenticationChoice + // AuthenticationChoice // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING, // ... 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' } ); @@ -91,14 +96,13 @@ public class LdapDecoderTest } // Check the decoded PDU - BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest(); + InternalBindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getInternalBindRequest(); assertEquals( 1, bindRequest.getMessageId() ); - assertEquals( 3, bindRequest.getVersion() ); + assertTrue( bindRequest.isVersion3() ); assertEquals( "uid=akarasulu,dc=example,dc=com", bindRequest.getName().toString() ); - assertEquals( true, ( bindRequest.getAuthentication() instanceof SimpleAuthentication ) ); - assertEquals( "password", StringTools.utf8ToString( ( ( SimpleAuthentication ) bindRequest.getAuthentication() ) - .getSimple() ) ); + assertTrue( bindRequest.isSimple() ); + assertEquals( "password", StringTools.utf8ToString( bindRequest.getCredentials() ) ); } @@ -140,12 +144,12 @@ public class LdapDecoderTest assertEquals( TLVStateEnum.VALUE_STATE_PENDING, ldapMessageContainer.getState() ); // Check the decoded PDU - BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest(); + InternalBindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getInternalBindRequest(); assertEquals( 1, bindRequest.getMessageId() ); - assertEquals( 3, bindRequest.getVersion() ); + assertTrue( bindRequest.isVersion3() ); assertEquals( null, bindRequest.getName() ); - assertEquals( false, ( bindRequest.getAuthentication() instanceof SimpleAuthentication ) ); + assertTrue( bindRequest.isSimple() ); } @@ -191,7 +195,7 @@ public class LdapDecoderTest stream.put( new byte[] { 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', ( byte ) 0x80, 0x08, // authentication - // AuthenticationChoice + // AuthenticationChoice // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING, // ... 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' } ); @@ -212,14 +216,13 @@ public class LdapDecoderTest assertEquals( ldapMessageContainer.getState(), TLVStateEnum.PDU_DECODED ); // Check the decoded PDU - BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest(); + InternalBindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getInternalBindRequest(); assertEquals( 1, bindRequest.getMessageId() ); - assertEquals( 3, bindRequest.getVersion() ); + assertTrue( bindRequest.isVersion3() ); assertEquals( "uid=akarasulu,dc=example,dc=com", bindRequest.getName().toString() ); - assertEquals( true, ( bindRequest.getAuthentication() instanceof SimpleAuthentication ) ); - assertEquals( "password", StringTools.utf8ToString( ( ( SimpleAuthentication ) bindRequest.getAuthentication() ) - .getSimple() ) ); + assertTrue( bindRequest.isSimple() ); + assertEquals( "password", StringTools.utf8ToString( bindRequest.getCredentials() ) ); } @@ -236,16 +239,21 @@ public class LdapDecoderTest ByteBuffer stream = ByteBuffer.allocate( 0x35 ); stream.put( new byte[] { - // Length should be 0x33... - 0x30, 0x32, // LDAPMessage ::=SEQUENCE { - 0x02, 0x01, 0x01, // messageID MessageID - 0x60, 0x2E, // CHOICE { ..., bindRequest BindRequest, ... + // Length should be 0x33... + 0x30, + 0x32, // LDAPMessage ::=SEQUENCE { + 0x02, 0x01, + 0x01, // messageID MessageID + 0x60, + 0x2E, // CHOICE { ..., bindRequest BindRequest, ... // BindRequest ::= APPLICATION[0] SEQUENCE { - 0x02, 0x01, 0x03, // version INTEGER (1..127), - 0x04, 0x1F, // name LDAPDN, + 0x02, 0x01, + 0x03, // version INTEGER (1..127), + 0x04, + 0x1F, // name LDAPDN, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', ( byte ) 0x80, 0x08, // authentication - // AuthenticationChoice + // AuthenticationChoice // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING, // ... 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' } ); @@ -282,20 +290,23 @@ public class LdapDecoderTest ByteBuffer stream = ByteBuffer.allocate( 0x35 ); stream.put( new byte[] - { - 0x30, 0x33, // LDAPMessage ::=SEQUENCE { - // Length should be 0x01... - 0x02, 0x02, 0x01, // messageID MessageID - 0x60, 0x2E, // CHOICE { ..., bindRequest BindRequest, ... - // BindRequest ::= APPLICATION[0] SEQUENCE { - 0x02, 0x01, 0x03, // version INTEGER (1..127), - 0x04, 0x1F, // name LDAPDN, - 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', - 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', - ( byte ) 0x80, 0x08, // authentication AuthenticationChoice - // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING, - // ... - 'p', 'a', 's', 's', 'w', 'o', 'r' } ); + { 0x30, + 0x33, // LDAPMessage ::=SEQUENCE { + // Length should be 0x01... + 0x02, 0x02, + 0x01, // messageID MessageID + 0x60, + 0x2E, // CHOICE { ..., bindRequest BindRequest, ... + // BindRequest ::= APPLICATION[0] SEQUENCE { + 0x02, 0x01, + 0x03, // version INTEGER (1..127), + 0x04, + 0x1F, // name LDAPDN, + 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', + 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', ( byte ) 0x80, 0x08, // authentication AuthenticationChoice + // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING, + // ... + 'p', 'a', 's', 's', 'w', 'o', 'r' } ); stream.flip(); @@ -329,16 +340,21 @@ public class LdapDecoderTest ByteBuffer stream = ByteBuffer.allocate( 0x35 ); stream.put( new byte[] - { 0x30, 0x33, // LDAPMessage ::=SEQUENCE { + { 0x30, + 0x33, // LDAPMessage ::=SEQUENCE { // Length should be 0x01... - 0x02, 0x01, 0x01, // messageID MessageID - 0x2D, 0x2D, // CHOICE { ..., bindRequest BindRequest, ... + 0x02, 0x01, + 0x01, // messageID MessageID + 0x2D, + 0x2D, // CHOICE { ..., bindRequest BindRequest, ... // BindRequest ::= APPLICATION[0] SEQUENCE { - 0x02, 0x01, 0x03, // version INTEGER (1..127), - 0x04, 0x1F, // name LDAPDN, + 0x02, 0x01, + 0x03, // version INTEGER (1..127), + 0x04, + 0x1F, // name LDAPDN, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', ( byte ) 0x80, 0x08, // authentication - // AuthenticationChoice + // AuthenticationChoice // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING, // ... 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' } ); @@ -362,6 +378,7 @@ public class LdapDecoderTest fail( "Should never reach this point." ); } + /** * Test the decoding of a splitted Length. * @@ -376,8 +393,7 @@ public class LdapDecoderTest ByteBuffer stream = ByteBuffer.allocate( 3 ); stream.put( new byte[] - { - 0x30, (byte)0x82, 0x01,// LDAPMessage ::=SEQUENCE { + { 0x30, ( byte ) 0x82, 0x01,// LDAPMessage ::=SEQUENCE { } ); stream.flip(); @@ -401,8 +417,7 @@ public class LdapDecoderTest // Second block of data stream = ByteBuffer.allocate( 1 ); stream.put( new byte[] - { - (byte)0x80 // End of the length + { ( byte ) 0x80 // End of the length } ); stream.flip(); Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java?rev=983573&r1=983572&r2=983573&view=diff ============================================================================== --- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java (original) +++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java Mon Aug 9 10:17:41 2010 @@ -21,10 +21,11 @@ package org.apache.directory.shared.ldap import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.nio.ByteBuffer; -import java.util.List; +import java.util.Map; import org.apache.directory.junit.tools.Concurrent; import org.apache.directory.junit.tools.ConcurrentJunitRunner; @@ -35,6 +36,7 @@ import org.apache.directory.shared.asn1. import org.apache.directory.shared.ldap.codec.LdapMessageContainer; import org.apache.directory.shared.ldap.codec.controls.ControlImpl; import org.apache.directory.shared.ldap.message.control.Control; +import org.apache.directory.shared.ldap.message.internal.InternalBindRequest; import org.apache.directory.shared.ldap.name.DN; import org.apache.directory.shared.ldap.util.StringTools; import org.junit.Test; @@ -59,25 +61,30 @@ public class BindRequestPerfTest ByteBuffer stream = ByteBuffer.allocate( 0x52 ); stream.put( new byte[] - { - 0x30, 0x50, // LDAPMessage ::=SEQUENCE { - 0x02, 0x01, 0x01, // messageID MessageID - 0x60, 0x2E, // CHOICE { ..., bindRequest BindRequest, ... - // BindRequest ::= APPLICATION[0] SEQUENCE { - 0x02, 0x01, 0x03, // version INTEGER (1..127), - 0x04, 0x1F, // name LDAPDN, - 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', - 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', - ( byte ) 0x80, 0x08, // authentication AuthenticationChoice - // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING, - // ... - 'p', 'a', 's', 's', 'w', 'o', 'r', 'd', - ( byte ) 0xA0, 0x1B, // A control - 0x30, 0x19, - 0x04, 0x17, - 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, - 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 - } ); + { + 0x30, + 0x50, // LDAPMessage ::=SEQUENCE { + 0x02, + 0x01, + 0x01, // messageID MessageID + 0x60, + 0x2E, // CHOICE { ..., bindRequest BindRequest, ... + // BindRequest ::= APPLICATION[0] SEQUENCE { + 0x02, + 0x01, + 0x03, // version INTEGER (1..127), + 0x04, + 0x1F, // name LDAPDN, + 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', + 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', + ( byte ) 0x80, + 0x08, // authentication AuthenticationChoice + // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING, + // ... + 'p', 'a', 's', 's', 'w', 'o', 'r', 'd', ( byte ) 0xA0, + 0x1B, // A control + 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, + 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } ); String decodedPdu = StringTools.dumpBytes( stream.array() ); stream.flip(); @@ -90,17 +97,17 @@ public class BindRequestPerfTest { int nbLoops = 1; //long t0 = System.currentTimeMillis(); - + for ( int i = 0; i < nbLoops; i++ ) { ldapDecoder.decode( stream, ldapMessageContainer ); - ( ( LdapMessageContainer ) ldapMessageContainer).clean(); + ( ( LdapMessageContainer ) ldapMessageContainer ).clean(); stream.flip(); } - + //long t1 = System.currentTimeMillis(); //System.out.println( "testDecodeBindRequestSimpleNoControlsPerf, " + nbLoops + " loops, Delta = " + ( t1 - t0 ) ); - + ldapDecoder.decode( stream, ldapMessageContainer ); } catch ( DecoderException de ) @@ -110,31 +117,40 @@ public class BindRequestPerfTest } // Check the decoded BindRequest - BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest(); + InternalBindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getInternalBindRequest(); assertEquals( 1, bindRequest.getMessageId() ); - assertEquals( 3, bindRequest.getVersion() ); + assertTrue( bindRequest.isVersion3() ); assertEquals( "uid=akarasulu,dc=example,dc=com", bindRequest.getName().toString() ); - assertEquals( true, ( bindRequest.getAuthentication() instanceof SimpleAuthentication ) ); - assertEquals( "password", StringTools.utf8ToString( ( ( SimpleAuthentication ) bindRequest.getAuthentication() ) - .getSimple() ) ); + assertTrue( bindRequest.isSimple() ); + assertEquals( "password", StringTools.utf8ToString( bindRequest.getCredentials() ) ); // Check the Control - List controls = bindRequest.getControls(); + Map controls = bindRequest.getControls(); assertEquals( 1, controls.size() ); - Control control = bindRequest.getControls( 0 ); + Control control = controls.get( "2.16.840.1.113730.3.4.2" ); assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() ); assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) ); // Check the length - assertEquals( 0x52, bindRequest.computeLength() ); + BindRequestCodec bindRequestCodec = new BindRequestCodec(); + bindRequestCodec.setMessageId( bindRequest.getMessageId() ); + bindRequestCodec.setName( bindRequest.getName() ); + bindRequestCodec.setVersion( bindRequest.getVersion3() ? 3 : 2 ); + bindRequestCodec.addControl( control ); + + SimpleAuthentication simple = new SimpleAuthentication(); + simple.setSimple( bindRequest.getCredentials() ); + bindRequestCodec.setAuthentication( simple ); + + assertEquals( 0x52, bindRequestCodec.computeLength() ); // Check the encoding try { - ByteBuffer bb = bindRequest.encode(); + ByteBuffer bb = bindRequestCodec.encode(); String encodedPdu = StringTools.dumpBytes( bb.array() ); @@ -147,6 +163,7 @@ public class BindRequestPerfTest } } + /** * Test the decoding of a BindRequest with Simple authentication and no * controls @@ -157,23 +174,23 @@ public class BindRequestPerfTest DN name = new DN( "uid=akarasulu,dc=example,dc=com" ); int nbLoops = 1; long t0 = System.currentTimeMillis(); - - for ( int i = 0; i< nbLoops; i++) + + for ( int i = 0; i < nbLoops; i++ ) { // Check the decoded BindRequest BindRequestCodec bindRequest = new BindRequestCodec(); bindRequest.setMessageId( 1 ); - + bindRequest.setName( name ); - + Control control = new ControlImpl( "2.16.840.1.113730.3.4.2" ); LdapAuthentication authentication = new SimpleAuthentication(); - ((SimpleAuthentication)authentication).setSimple( StringTools.getBytesUtf8( "password" ) ); + ( ( SimpleAuthentication ) authentication ).setSimple( StringTools.getBytesUtf8( "password" ) ); bindRequest.addControl( control ); bindRequest.setAuthentication( authentication ); - + // Check the encoding try {