You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/04/15 17:33:34 UTC

svn commit: r1092743 - in /directory: apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/ apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/ apacheds/trunk/server-integ/src/test/jav...

Author: elecharny
Date: Fri Apr 15 15:33:34 2011
New Revision: 1092743

URL: http://svn.apache.org/viewvc?rev=1092743&view=rev
Log:
o Added the bind( Dn ) and bind( String ) method in the LdapConnection interface
o Ignored the SASL PLAIN bind test, it's not working in the LdapNeworkConnection
o The testAnonymousBindReques is not anymore ignored, the NPE ha sbeen fixed
o Added a check in the LdapNetworkConnection.bind( username, password ) methods to forbid a call when the password is null but the username is not
o Fixed a NPE in the BindRequestDecorator class
o Updated the BindRequest Javadoc

Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SimpleBindIT.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/BindRequestDecorator.java
    directory/shared/trunk/ldap/codec/standalone/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/AddRequestImpl.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/BindRequest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/BindRequestImpl.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java?rev=1092743&r1=1092742&r2=1092743&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java Fri Apr 15 15:33:34 2011
@@ -1209,6 +1209,21 @@ public class LdapCoreSessionConnection i
     /**
      * {@inheritDoc}
      */
+    public BindResponse bind( Dn name ) throws LdapException, IOException
+    {
+        byte[] credBytes = StringConstants.EMPTY_BYTES;
+
+        BindRequest bindReq = new BindRequestImpl();
+        bindReq.setName( name );
+        bindReq.setCredentials( credBytes );
+
+        return bind( bindReq );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
     public BindResponse bind( Dn name, String credentials ) throws LdapException, IOException
     {
         byte[] credBytes = ( credentials == null ? StringConstants.EMPTY_BYTES : Strings.getBytesUtf8(credentials) );
@@ -1224,6 +1239,15 @@ public class LdapCoreSessionConnection i
     /**
      * {@inheritDoc}
      */
+    public BindResponse bind( String name ) throws LdapException, IOException
+    {
+        return bind( new Dn( schemaManager, name ), null );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
     public BindResponse bind( String name, String credentials ) throws LdapException, IOException
     {
         return bind( new Dn( schemaManager, name ), credentials );

Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java?rev=1092743&r1=1092742&r2=1092743&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java (original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java Fri Apr 15 15:33:34 2011
@@ -39,6 +39,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.interceptor.BaseInterceptor;
 import org.apache.directory.server.core.interceptor.NextInterceptor;
 import org.apache.directory.server.core.interceptor.context.BindOperationContext;
+import org.apache.directory.shared.ldap.model.exception.LdapAuthenticationException;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.message.BindRequest;
 import org.apache.directory.shared.ldap.model.message.BindRequestImpl;
@@ -48,7 +49,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -64,9 +64,16 @@ import org.junit.runner.RunWith;
 @ApplyLdifs(
     {
         // Entry # 1
-        "dn: uid=superuser,ou=system", "objectClass: person", "objectClass: organizationalPerson",
-        "objectClass: inetOrgPerson", "objectClass: top", "cn: superuser", "sn: administrator",
-        "displayName: Directory Superuser", "uid: superuser", "userPassword: test" })
+        "dn: uid=superuser,ou=system", 
+        "objectClass: person", 
+        "objectClass: organizationalPerson",
+        "objectClass: inetOrgPerson", 
+        "objectClass: top", 
+        "cn: superuser", 
+        "sn: administrator",
+        "displayName: Directory Superuser", 
+        "uid: superuser", 
+        "userPassword: test" })
 public class SimpleBindRequestTest extends AbstractLdapTestUnit
 {
     private LdapAsyncConnection connection;
@@ -159,7 +166,6 @@ public class SimpleBindRequestTest exten
      * Test a successful anonymous bind request.
      */
     @Test
-    @Ignore // TODO : FIXME ! We get a NPE low in the code because the name is null
     public void testAnonymousBindRequest() throws Exception
     {
         BindRequest bindRequest = new BindRequestImpl();
@@ -255,7 +261,7 @@ public class SimpleBindRequestTest exten
     @Test
     public void testSimpleBindUnauthenticated() throws Exception
     {
-        BindResponse response = connection.bind( "uid=admin,ou=system", ( String ) null );
+        BindResponse response = connection.bind( "uid=admin,ou=system" );
         LdapResult ldapResult = response.getLdapResult();
         assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, ldapResult.getResultCode() );
         assertEquals( 1, response.getMessageId() );
@@ -265,6 +271,16 @@ public class SimpleBindRequestTest exten
 
 
     /**
+     * Test an bind with no password
+     */
+    @Test( expected=LdapAuthenticationException.class )
+    public void testSimpleBindNoPassword() throws Exception
+    {
+        connection.bind( "uid=admin,ou=system", ( String ) null );
+    }
+
+
+    /**
      * Test a valid bind
      */
     @Test

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java?rev=1092743&r1=1092742&r2=1092743&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java Fri Apr 15 15:33:34 2011
@@ -232,6 +232,7 @@ public class SaslBindIT extends Abstract
      * Tests to make sure PLAIN-binds works
      */
     @Test
+    @Ignore // The SASL Plain mechanism is ot supported
     public void testSaslBindPLAIN() throws Exception
     {
         Dn userDn = new Dn( "uid=hnelson,ou=users,dc=example,dc=com" );

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SimpleBindIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SimpleBindIT.java?rev=1092743&r1=1092742&r2=1092743&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SimpleBindIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SimpleBindIT.java Fri Apr 15 15:33:34 2011
@@ -71,8 +71,14 @@ import org.junit.runner.RunWith;
 @ApplyLdifs(
     {
         // Entry # 1
-        "dn: uid=hnelson,ou=users,ou=system", "objectClass: inetOrgPerson", "objectClass: organizationalPerson",
-        "objectClass: person", "objectClass: top", "userPassword: secret", "uid: hnelson", "cn: Horatio Nelson",
+        "dn: uid=hnelson,ou=users,ou=system", 
+        "objectClass: inetOrgPerson", 
+        "objectClass: organizationalPerson",
+        "objectClass: person", 
+        "objectClass: top", 
+        "userPassword: secret", 
+        "uid: hnelson",
+        "cn: Horatio Nelson",
         "sn: Nelson" })
 @CreateDS(allowAnonAccess = true, name = "SimpleBindIT-class")
 @CreateLdapServer(transports =

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java?rev=1092743&r1=1092742&r2=1092743&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java Fri Apr 15 15:33:34 2011
@@ -31,7 +31,24 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.model.entry.Value;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
-import org.apache.directory.shared.ldap.model.message.*;
+import org.apache.directory.shared.ldap.model.message.AbandonRequest;
+import org.apache.directory.shared.ldap.model.message.AddRequest;
+import org.apache.directory.shared.ldap.model.message.AddResponse;
+import org.apache.directory.shared.ldap.model.message.BindRequest;
+import org.apache.directory.shared.ldap.model.message.BindResponse;
+import org.apache.directory.shared.ldap.model.message.CompareRequest;
+import org.apache.directory.shared.ldap.model.message.CompareResponse;
+import org.apache.directory.shared.ldap.model.message.Control;
+import org.apache.directory.shared.ldap.model.message.DeleteRequest;
+import org.apache.directory.shared.ldap.model.message.DeleteResponse;
+import org.apache.directory.shared.ldap.model.message.ExtendedRequest;
+import org.apache.directory.shared.ldap.model.message.ExtendedResponse;
+import org.apache.directory.shared.ldap.model.message.ModifyDnRequest;
+import org.apache.directory.shared.ldap.model.message.ModifyDnResponse;
+import org.apache.directory.shared.ldap.model.message.ModifyRequest;
+import org.apache.directory.shared.ldap.model.message.ModifyResponse;
+import org.apache.directory.shared.ldap.model.message.SearchRequest;
+import org.apache.directory.shared.ldap.model.message.SearchScope;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.name.Rdn;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
@@ -135,6 +152,18 @@ public interface LdapConnection
 
 
     /**
+     * Unauthenticated authentication bind
+     *
+     * @param name The name we use to authenticate the user. It must be a
+     * valid Dn
+     * @return The BindResponse LdapResponse
+     * @throws LdapException if some error occurred
+     * @throws IOException if an I/O exception occurred
+     */
+    BindResponse bind( String name ) throws LdapException, IOException;
+
+
+    /**
      * Simple Bind on a server.
      *
      * @param name The name we use to authenticate the user. It must be a
@@ -148,6 +177,18 @@ public interface LdapConnection
 
 
     /**
+     * Unauthenticated authentication Bind on a server.
+     *
+     * @param name The name we use to authenticate the user. It must be a
+     * valid Dn
+     * @return The BindResponse LdapResponse
+     * @throws LdapException if some error occurred
+     * @throws IOException if an I/O exception occurred
+     */
+    BindResponse bind( Dn name ) throws LdapException, IOException;
+
+
+    /**
      * Simple Bind on a server.
      *
      * @param name The name we use to authenticate the user. It must be a

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1092743&r1=1092742&r2=1092743&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java Fri Apr 15 15:33:34 2011
@@ -74,6 +74,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.entry.Modification;
 import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.model.entry.Value;
+import org.apache.directory.shared.ldap.model.exception.LdapAuthenticationException;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.model.exception.LdapNoPermissionException;
@@ -915,10 +916,31 @@ public class LdapNetworkConnection exten
     /**
      * {@inheritDoc}
      */
+    public BindResponse bind( String name ) throws LdapException, IOException
+    {
+        LOG.debug( "Bind request : {}", name );
+
+        // Create the BindRequest
+        BindRequest bindRequest = createBindRequest( name, StringConstants.EMPTY_BYTES );
+
+        return bind( bindRequest );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
     public BindResponse bind( String name, String credentials ) throws LdapException, IOException
     {
         LOG.debug( "Bind request : {}", name );
 
+        // The password must not be empty or null
+        if ( Strings.isEmpty( credentials ) && Strings.isNotEmpty( name ) )
+        {
+            LOG.debug( "The password is missing" );
+            throw new LdapAuthenticationException( "The password is missing" );
+        }
+        
         // Create the BindRequest
         BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8( credentials ) );
 
@@ -927,12 +949,39 @@ public class LdapNetworkConnection exten
 
 
     /**
+     * Asynchronous unauthenticated authentication bind
+     *
+     * @param name The name we use to authenticate the user. It must be a
+     * valid Dn
+     * @return The BindResponse LdapResponse
+     * @throws LdapException if some error occurred
+     * @throws IOException if an I/O exception occurred
+     */
+    public BindFuture bindAsync( String name ) throws LdapException, IOException
+    {
+        LOG.debug( "Bind request : {}", name );
+
+        // Create the BindRequest
+        BindRequest bindRequest = createBindRequest( name, StringConstants.EMPTY_BYTES );
+
+        return bindAsync( bindRequest );
+    }
+
+
+    /**
      * {@inheritDoc}
      */
     public BindFuture bindAsync( String name, String credentials ) throws LdapException, IOException
     {
         LOG.debug( "Bind request : {}", name );
 
+        // The password must not be empty or null
+        if ( Strings.isEmpty( credentials ) && Strings.isNotEmpty( name ) )
+        {
+            LOG.debug( "The password is missing" );
+            throw new LdapAuthenticationException( "The password is missing" );
+        }
+
         // Create the BindRequest
         BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8( credentials ) );
 
@@ -943,10 +992,31 @@ public class LdapNetworkConnection exten
     /**
      * {@inheritDoc}
      */
+    public BindResponse bind( Dn name ) throws LdapException, IOException
+    {
+        LOG.debug( "Unauthenticated authentication Bind request : {}", name );
+
+        // Create the BindRequest
+        BindRequest bindRequest = createBindRequest( name, StringConstants.EMPTY_BYTES, null );
+
+        return bind( bindRequest );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
     public BindResponse bind( Dn name, String credentials ) throws LdapException, IOException
     {
         LOG.debug( "Bind request : {}", name );
 
+        // The password must not be empty or null
+        if ( Strings.isEmpty( credentials ) && ( !Dn.EMPTY_DN.equals( name ) ) )
+        {
+            LOG.debug( "The password is missing" );
+            throw new LdapAuthenticationException( "The password is missing" );
+        }
+
         // Create the BindRequest
         BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8( credentials ), null );
 
@@ -955,12 +1025,39 @@ public class LdapNetworkConnection exten
 
 
     /**
+     * Asynchronous unauthenticated authentication Bind on a server.
+     *
+     * @param name The name we use to authenticate the user. It must be a
+     * valid Dn
+     * @return The BindResponse LdapResponse
+     * @throws LdapException if some error occurred
+     * @throws IOException if an I/O exception occurred
+     */
+    public BindFuture bindAsync( Dn name ) throws LdapException, IOException
+    {
+        LOG.debug( "Bind request : {}", name );
+
+        // Create the BindRequest
+        BindRequest bindRequest = createBindRequest( name, StringConstants.EMPTY_BYTES );
+
+        return bindAsync( bindRequest );
+    }
+
+
+    /**
      * {@inheritDoc}
      */
     public BindFuture bindAsync( Dn name, String credentials ) throws LdapException, IOException
     {
         LOG.debug( "Bind request : {}", name );
 
+        // The password must not be empty or null
+        if ( Strings.isEmpty( credentials ) && (! Dn.EMPTY_DN.equals( name ) ) )
+        {
+            LOG.debug( "The password is missing" );
+            throw new LdapAuthenticationException( "The password is missing" );
+        }
+
         // Create the BindRequest
         BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8( credentials ) );
 

Modified: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/BindRequestDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/BindRequestDecorator.java?rev=1092743&r1=1092742&r2=1092743&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/BindRequestDecorator.java (original)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/BindRequestDecorator.java Fri Apr 15 15:33:34 2011
@@ -266,10 +266,17 @@ public class BindRequestDecorator extend
     public int computeLength()
     {
         int bindRequestLength = 1 + 1 + 1; // Initialized with version
-
+        
+        Dn name = getName();
+        
         // The name
-        bindRequestLength += 1 + TLV.getNbBytes( Dn.getNbBytes( getName() ) )
-            + Dn.getNbBytes( getName() );
+        if ( name == null )
+        { 
+            name = Dn.EMPTY_DN;
+        }
+
+        bindRequestLength += 1 + TLV.getNbBytes( Dn.getNbBytes( name ) )
+            + Dn.getNbBytes( name );
 
         byte[] credentials = getCredentials();
 
@@ -347,7 +354,15 @@ public class BindRequestDecorator extend
         Value.encode( buffer, 3 );
 
         // The name
-        Value.encode( buffer, Dn.getBytes( getName() ) );
+        Dn name = getName();
+        
+        // The name
+        if ( name == null )
+        { 
+            name = Dn.EMPTY_DN;
+        }
+
+        Value.encode( buffer, Dn.getBytes( name ) );
 
         byte[] credentials = getCredentials();
 

Modified: directory/shared/trunk/ldap/codec/standalone/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/standalone/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java?rev=1092743&r1=1092742&r2=1092743&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/standalone/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java (original)
+++ directory/shared/trunk/ldap/codec/standalone/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java Fri Apr 15 15:33:34 2011
@@ -33,8 +33,8 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.asn1.ber.tlv.TLVStateEnum;
 import org.apache.directory.shared.ldap.codec.api.LdapDecoder;
-import org.apache.directory.shared.ldap.codec.api.MessageDecorator;
 import org.apache.directory.shared.ldap.codec.api.LdapMessageContainer;
+import org.apache.directory.shared.ldap.codec.api.MessageDecorator;
 import org.apache.directory.shared.ldap.codec.decorators.BindRequestDecorator;
 import org.apache.directory.shared.ldap.codec.osgi.AbstractCodecServiceTest;
 import org.apache.directory.shared.ldap.model.message.BindRequest;

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/AddRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/AddRequestImpl.java?rev=1092743&r1=1092742&r2=1092743&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/AddRequestImpl.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/AddRequestImpl.java Fri Apr 15 15:33:34 2011
@@ -272,7 +272,7 @@ public class AddRequestImpl extends Abst
     {
         StringBuilder sb = new StringBuilder();
 
-        sb.append( "    Add Request[" ).append( getMessageId() ).append( "] :\n" );
+        sb.append( "    Add Request :\n" );
 
         if ( entry == null )
         {

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/BindRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/BindRequest.java?rev=1092743&r1=1092742&r2=1092743&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/BindRequest.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/BindRequest.java Fri Apr 15 15:33:34 2011
@@ -60,8 +60,7 @@ public interface BindRequest extends Sin
      * Sets the authentication mechanism to simple or to SASL based
      * authentication.
      * 
-     * @param isSimple
-     *            true if authentication is simple, false otherwise.
+     * @param isSimple true if authentication is simple, false otherwise.
      */
     void setSimple( boolean isSimple );
 
@@ -70,25 +69,25 @@ public interface BindRequest extends Sin
      * Gets the simple credentials associated with a simple authentication
      * attempt or null if this request uses SASL authentication mechanisms.
      * 
-     * @return null if the mechanism is SASL or the credentials if it is simple.
+     * @return null if the mechanism is SASL, or the credentials if it is simple.
      */
     byte[] getCredentials();
 
 
     /**
      * Sets the simple credentials associated with a simple authentication
-     * attempt ignored if this request uses SASL authentication mechanisms.
+     * attempt. Ignored if this request uses SASL authentication mechanisms.
      * 
-     * @param credentials the credentials if authentication is simple, null otherwise
+     * @param credentials the credentials if authentication is simple
      */
     void setCredentials( String credentials );
 
 
     /**
      * Sets the simple credentials associated with a simple authentication
-     * attempt ignored if this request uses SASL authentication mechanisms.
+     * attempt. Ignored if this request uses SASL authentication mechanisms.
      * 
-     * @param credentials the credentials if authentication is simple, null otherwise
+     * @param credentials the credentials if authentication is simple
      */
     void setCredentials( byte[] credentials );
 
@@ -112,9 +111,7 @@ public interface BindRequest extends Sin
      * performed at a lower layer, or when using SASL credentials with a
      * mechanism that includes the Dn in the credentials.
      * 
-     * @param name
-     *            the Dn of the authenticating user - leave null for annonymous
-     *            user.
+     * @param name the Dn of the authenticating user - leave null for annonymous user.
      */
     void setName( Dn name );
 
@@ -156,9 +153,8 @@ public interface BindRequest extends Sin
      * an type-safe enumeration type for a binary value. If an LDAPv4 comes out
      * then we shall convert the return type to a type safe enumeration.
      * 
-     * @param isVersion3
-     *            if true the client will be exhibiting version 3 bind behavoir,
-     *            if false is used version 2 behavoir will be exhibited.
+     * @param isVersion3 if true the client will be exhibiting version 3 bind behavior,
+     *  If false is used version 2 behavior will be exhibited.
      */
     void setVersion3( boolean isVersion3 );
 
@@ -167,7 +163,7 @@ public interface BindRequest extends Sin
      * Gets the SASL mechanism String associated with this BindRequest if the
      * bind operation is using SASL.
      * 
-     * @return the SASL mechanism or null if the bind op is simple
+     * @return the SASL mechanism or null if the bind operation is simple
      */
     String getSaslMechanism();
 
@@ -176,8 +172,7 @@ public interface BindRequest extends Sin
      * Sets the SASL mechanism String associated with this BindRequest if the
      * bind operation is using SASL.
      * 
-     * @param saslMechanism
-     *            the SASL mechanism
+     * @param saslMechanism the SASL mechanism
      */
     void setSaslMechanism( String saslMechanism );
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/BindRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/BindRequestImpl.java?rev=1092743&r1=1092742&r2=1092743&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/BindRequestImpl.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/BindRequestImpl.java Fri Apr 15 15:33:34 2011
@@ -35,8 +35,6 @@ import org.apache.directory.shared.util.
  */
 public class BindRequestImpl extends AbstractAbandonableRequest implements BindRequest
 {
-    static final long serialVersionUID = 7945504184130380071L;
-
     /**
      * Distinguished name identifying the name of the authenticating subject -
      * defaults to the empty string
@@ -80,10 +78,7 @@ public class BindRequestImpl extends Abs
     // -----------------------------------------------------------------------
 
     /**
-     * Checks to see if the authentication mechanism is simple and not SASL
-     * based.
-     * 
-     * @return true if the mechanism is simple false if it is SASL based.
+     * {@inheritDoc}
      */
     public boolean isSimple()
     {
@@ -92,10 +87,7 @@ public class BindRequestImpl extends Abs
 
 
     /**
-     * Checks to see if the authentication mechanism is simple and not SASL
-     * based.
-     * 
-     * @return true if the mechanism is simple false if it is SASL based.
+     * {@inheritDoc}
      */
     public boolean getSimple()
     {
@@ -104,11 +96,7 @@ public class BindRequestImpl extends Abs
 
 
     /**
-     * Sets the authentication mechanism to simple or to SASL based
-     * authentication.
-     * 
-     * @param simple
-     *            true if authentication is simple, false otherwise.
+     * {@inheritDoc}
      */
     public void setSimple( boolean simple )
     {
@@ -117,10 +105,7 @@ public class BindRequestImpl extends Abs
 
 
     /**
-     * Gets the simple credentials associated with a simple authentication
-     * attempt or null if this request uses SASL authentication mechanisms.
-     * 
-     * @return null if the mechanism is SASL or the credentials if it is simple.
+     * {@inheritDoc}
      */
     public byte[] getCredentials()
     {
@@ -170,9 +155,7 @@ public class BindRequestImpl extends Abs
 
 
     /**
-     * Gets the mechanism if this request uses SASL authentication mechanisms.
-     * 
-     * @return The mechanism if SASL.
+     * {@inheritDoc}
      */
     public String getSaslMechanism()
     {
@@ -181,25 +164,17 @@ public class BindRequestImpl extends Abs
 
 
     /**
-     * Sets the mechanism associated with a SASL authentication
-     * 
-     * @param saslMechanism
-     *            the SASL mechanism
+     * {@inheritDoc}
      */
     public void setSaslMechanism( String saslMechanism )
     {
+        this.isSimple = false;
         this.mechanism = saslMechanism;
     }
 
 
     /**
-     * Gets the distinguished name of the subject in this authentication
-     * request. This field may take on a null value (a zero length string) for
-     * the purposes of anonymous binds, when authentication has been performed
-     * at a lower layer, or when using SASL credentials with a mechanism that
-     * includes the Dn in the credentials.
-     * 
-     * @return the Dn of the authenticating user.
+     * {@inheritDoc}
      */
     public Dn getName()
     {
@@ -208,15 +183,7 @@ public class BindRequestImpl extends Abs
 
 
     /**
-     * Sets the distinguished name of the subject in this authentication
-     * request. This field may take on a null value (or a zero length string)
-     * for the purposes of anonymous binds, when authentication has been
-     * performed at a lower layer, or when using SASL credentials with a
-     * mechanism that includes the Dn in the credentials.
-     * 
-     * @param name
-     *            the Dn of the authenticating user - leave null for annonymous
-     *            user.
+     * {@inheritDoc}
      */
     public void setName( Dn name )
     {
@@ -225,15 +192,7 @@ public class BindRequestImpl extends Abs
 
 
     /**
-     * Checks to see if the Ldap v3 protocol is used. Normally this would
-     * extract a version number from the bind request sent by the client
-     * indicating the version of the protocol to be used in this protocol
-     * session. The integer is either a 2 or a 3 at the moment. We thought it
-     * was better to just check if the protocol used is 3 or not rather than use
-     * an type-safe enumeration type for a binary value. If an LDAPv4 comes out
-     * then we shall convert the return type to a type safe enumeration.
-     * 
-     * @return true if client using version 3 false if it is version 2.
+     * {@inheritDoc}
      */
     public boolean isVersion3()
     {
@@ -242,15 +201,7 @@ public class BindRequestImpl extends Abs
 
 
     /**
-     * Gets whether or not the Ldap v3 protocol is used. Normally this would
-     * extract a version number from the bind request sent by the client
-     * indicating the version of the protocol to be used in this protocol
-     * session. The integer is either a 2 or a 3 at the moment. We thought it
-     * was better to just check if the protocol used is 3 or not rather than use
-     * an type-safe enumeration type for a binary value. If an LDAPv4 comes out
-     * then we shall convert the return type to a type safe enumeration.
-     * 
-     * @return true if client using version 3 false if it is version 2.
+     * {@inheritDoc}
      */
     public boolean getVersion3()
     {
@@ -259,17 +210,7 @@ public class BindRequestImpl extends Abs
 
 
     /**
-     * Sets whether or not the LDAP v3 or v2 protocol is used. Normally this
-     * would extract a version number from the bind request sent by the client
-     * indicating the version of the protocol to be used in this protocol
-     * session. The integer is either a 2 or a 3 at the moment. We thought it
-     * was better to just check if the protocol used is 3 or not rather than use
-     * an type-safe enumeration type for a binary value. If an LDAPv4 comes out
-     * then we shall convert the return type to a type safe enumeration.
-     * 
-     * @param version3
-     *            if true the client will be exhibiting version 3 bind behavoir,
-     *            if false is used version 2 behavoir will be exhibited.
+     * {@inheritDoc}
      */
     public void setVersion3( boolean version3 )
     {
@@ -354,16 +295,16 @@ public class BindRequestImpl extends Abs
         Dn dn1 = req.getName();
         Dn dn2 = getName();
 
-        if ( dn1 == null )
+        if ( Dn.isNullOrEmpty( dn1) )
         {
-            if ( dn2 != null )
+            if ( !Dn.isNullOrEmpty( dn2 ) )
             {
                 return false;
             }
         }
         else
         {
-            if ( dn2 == null )
+            if ( Dn.isNullOrEmpty( dn2 ) )
             {
                 return false;
             }
@@ -371,7 +312,6 @@ public class BindRequestImpl extends Abs
             {
                 return false;
             }
-
         }
 
         return Arrays.equals( req.getCredentials(), getCredentials() );
@@ -409,7 +349,7 @@ public class BindRequestImpl extends Abs
         sb.append( "    BindRequest\n" );
         sb.append( "        Version : '" ).append( isVersion3 ? "3" : "2" ).append( "'\n" );
 
-        if ( Strings.isEmpty(name.getNormName()) && isSimple )
+        if ( ( (name == null ) || Strings.isEmpty(name.getNormName() ) ) && isSimple )
         {
             sb.append( "        Name : anonymous\n" );
         }