directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1233925 [3/3] - in /directory/shared/trunk: dsml/engine/src/main/java/org/apache/directory/shared/dsmlv2/engine/ dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/ dsml/parser/src/test/java/org/apache/directory/shared/ds...
Date Fri, 20 Jan 2012 14:28:26 GMT
Modified: directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java?rev=1233925&r1=1233924&r2=1233925&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java
(original)
+++ directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java
Fri Jan 20 14:28:25 2012
@@ -206,7 +206,7 @@ public class BindRequestTest extends Abs
 
         assertEquals( 1, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );
-        assertEquals( "uid=akarasulu,dc=example,dc=com", bindRequest.getName().toString()
);
+        assertEquals( "uid=akarasulu,dc=example,dc=com", bindRequest.getName() );
         assertTrue( bindRequest.isSimple() );
         assertEquals( "password", Strings.utf8ToString(bindRequest.getCredentials()) );
 
@@ -369,7 +369,7 @@ public class BindRequestTest extends Abs
 
         assertEquals( 1, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );
-        assertEquals( "", bindRequest.getName().toString() );
+        assertEquals( "", bindRequest.getName() );
         assertTrue( bindRequest.isSimple() );
         assertEquals( "password", Strings.utf8ToString(bindRequest.getCredentials()) );
 
@@ -528,7 +528,7 @@ public class BindRequestTest extends Abs
 
         assertEquals( 1, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );
-        assertEquals( "uid=akarasulu,dc=example,dc=com", bindRequest.getName().toString()
);
+        assertEquals( "uid=akarasulu,dc=example,dc=com", bindRequest.getName() );
         assertFalse( bindRequest.isSimple() );
         assertEquals( "KERBEROS_V4", bindRequest.getSaslMechanism() );
         assertEquals( "abcdef", Strings.utf8ToString(bindRequest.getCredentials()) );
@@ -605,7 +605,7 @@ public class BindRequestTest extends Abs
 
         assertEquals( 1, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );
-        assertEquals( "", bindRequest.getName().toString() );
+        assertEquals( "", bindRequest.getName() );
         assertFalse( bindRequest.isSimple() );
         assertEquals( "KERBEROS_V4", bindRequest.getSaslMechanism() );
         assertEquals( "abcdef", Strings.utf8ToString(bindRequest.getCredentials()) );
@@ -885,7 +885,7 @@ public class BindRequestTest extends Abs
      * Test the decoding of a BindRequest with an empty simple
      */
     @Test
-    public void testDecodeBindRequestEmptysimple()
+    public void testDecodeBindRequestEmptySimple()
     {
         Asn1Decoder ldapDecoder = new Asn1Decoder();
 
@@ -919,7 +919,7 @@ public class BindRequestTest extends Abs
 
         assertEquals( 1, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );
-        assertEquals( "", bindRequest.getName().toString() );
+        assertEquals( "", bindRequest.getName() );
         assertTrue( bindRequest.isSimple() );
         assertEquals( "", Strings.utf8ToString(bindRequest.getCredentials()) );
 
@@ -1021,7 +1021,7 @@ public class BindRequestTest extends Abs
 
         assertEquals( 1, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );
-        assertEquals( "", bindRequest.getName().toString() );
+        assertEquals( "", bindRequest.getName() );
         assertFalse( bindRequest.isSimple() );
         assertEquals( "", bindRequest.getSaslMechanism() );
 
@@ -1127,7 +1127,7 @@ public class BindRequestTest extends Abs
 
         assertEquals( 1, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );
-        assertEquals( "", bindRequest.getName().toString() );
+        assertEquals( "", bindRequest.getName() );
         assertFalse( bindRequest.isSimple() );
         assertEquals( "", bindRequest.getSaslMechanism() );
         assertEquals( "", Strings.utf8ToString(bindRequest.getCredentials()) );
@@ -1198,7 +1198,7 @@ public class BindRequestTest extends Abs
 
         assertEquals( 1, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );
-        assertEquals( "", bindRequest.getName().toString() );
+        assertEquals( "", bindRequest.getName() );
         assertFalse( bindRequest.isSimple() );
         assertEquals( "", bindRequest.getSaslMechanism() );
         assertEquals( "", Strings.utf8ToString(bindRequest.getCredentials()) );
@@ -1278,7 +1278,7 @@ public class BindRequestTest extends Abs
 
         assertEquals( 1, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );
-        assertEquals( "", bindRequest.getName().toString() );
+        assertEquals( "", bindRequest.getName() );
         assertFalse( bindRequest.isSimple() );
         assertEquals( "", bindRequest.getSaslMechanism() );
         assertEquals( "", Strings.utf8ToString(bindRequest.getCredentials()) );

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=1233925&r1=1233924&r2=1233925&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 Jan 20 14:28:25 2012
@@ -97,28 +97,53 @@ public interface BindRequest extends Sin
 
 
     /**
-     * Gets the distinguished name of the subject in this authentication
+     * Gets the 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.
+     * includes the name in the credentials.
      * 
-     * @return the Dn of the authenticating user.
+     * @return the name of the authenticating user.
      */
-    Dn getName();
+    String getName();
 
 
     /**
-     * Sets the distinguished name of the subject in this authentication
+     * Sets the  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.
+     * mechanism that includes the name in the credentials.
      * 
-     * @param name the Dn of the authenticating user - leave null for annonymous user.
+     * @param name the name of the authenticating user - leave null for anonymous user.
      * @return The BindRequest instance
      */
-    BindRequest setName( Dn name );
+    BindRequest setName( String name );
+
+
+    /**
+     * Gets the DN 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.
+     */
+    Dn getDn();
+
+
+    /**
+     * Sets the DN 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 anonymous user.
+     * @return The BindRequest instance
+     */
+    BindRequest setDn( Dn name );
 
 
     /**
@@ -188,20 +213,20 @@ public interface BindRequest extends Sin
      * {@inheritDoc}
      */
     BindRequest setMessageId( int messageId );
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
     BindRequest addControl( Control control ) throws MessageException;
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
     BindRequest addAllControls( Control[] controls ) throws MessageException;
-    
-    
+
+
     /**
      * {@inheritDoc}
      */

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=1233925&r1=1233924&r2=1233925&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 Jan 20 14:28:25 2012
@@ -23,9 +23,12 @@ package org.apache.directory.shared.ldap
 import java.util.Arrays;
 
 import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.model.exception.MessageException;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -36,11 +39,21 @@ import org.apache.directory.shared.util.
  */
 public class BindRequestImpl extends AbstractAbandonableRequest implements BindRequest
 {
+
+    /** A logger */
+    private static final Logger LOG = LoggerFactory.getLogger( BindRequestImpl.class );
+
     /**
      * Distinguished name identifying the name of the authenticating subject -
      * defaults to the empty string
      */
-    private Dn name;
+    private Dn dn;
+
+    /**
+     * String identifying the name of the authenticating subject -
+     * defaults to the empty string
+     */
+    private String name;
 
     /** The passwords, keys or tickets used to verify user identity */
     private byte[] credentials;
@@ -102,7 +115,7 @@ public class BindRequestImpl extends Abs
     public BindRequest setSimple( boolean simple )
     {
         this.isSimple = simple;
-        
+
         return this;
     }
 
@@ -121,7 +134,7 @@ public class BindRequestImpl extends Abs
      */
     public BindRequest setCredentials( String credentials )
     {
-        return setCredentials( Strings.getBytesUtf8(credentials) );
+        return setCredentials( Strings.getBytesUtf8( credentials ) );
     }
 
 
@@ -154,7 +167,7 @@ public class BindRequestImpl extends Abs
         {
             hCredentials = 0;
         }
-        
+
         return this;
     }
 
@@ -175,7 +188,7 @@ public class BindRequestImpl extends Abs
     {
         this.isSimple = false;
         this.mechanism = saslMechanism;
-        
+
         return this;
     }
 
@@ -183,7 +196,7 @@ public class BindRequestImpl extends Abs
     /**
      * {@inheritDoc}
      */
-    public Dn getName()
+    public String getName()
     {
         return name;
     }
@@ -192,10 +205,41 @@ public class BindRequestImpl extends Abs
     /**
      * {@inheritDoc}
      */
-    public BindRequest setName( Dn name )
+    public BindRequest setName( String name )
     {
         this.name = name;
-        
+
+        try
+        {
+            this.dn = new Dn( name );
+        }
+        catch ( LdapInvalidDnException e )
+        {
+            LOG.warn( "Enable to convert the name to a DN.", e );
+            this.dn = null;
+        }
+
+        return this;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Dn getDn()
+    {
+        return dn;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public BindRequest setDn( Dn dn )
+    {
+        this.dn = dn;
+        this.name = dn.getName();
+
         return this;
     }
 
@@ -224,46 +268,46 @@ public class BindRequestImpl extends Abs
     public BindRequest setVersion3( boolean version3 )
     {
         this.isVersion3 = version3;
-        
+
         return this;
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
     public BindRequest setMessageId( int messageId )
     {
         super.setMessageId( messageId );
-        
+
         return this;
     }
 
-    
+
     /**
      * {@inheritDoc}
      */
     public BindRequest addControl( Control control ) throws MessageException
     {
-        return (BindRequest)super.addControl( control );
+        return ( BindRequest ) super.addControl( control );
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
     public BindRequest addAllControls( Control[] controls ) throws MessageException
     {
-        return (BindRequest)super.addAllControls( controls );
+        return ( BindRequest ) super.addAllControls( controls );
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
     public BindRequest removeControl( Control control ) throws MessageException
     {
-        return (BindRequest)super.removeControl( control );
+        return ( BindRequest ) super.removeControl( control );
     }
 
 
@@ -319,7 +363,7 @@ public class BindRequestImpl extends Abs
             return true;
         }
 
-        if ( ( obj == null ) || !( obj instanceof BindRequest) )
+        if ( ( obj == null ) || !( obj instanceof BindRequest ) )
         {
             return false;
         }
@@ -341,10 +385,32 @@ public class BindRequestImpl extends Abs
             return false;
         }
 
-        Dn dn1 = req.getName();
-        Dn dn2 = getName();
+        String name1 = req.getName();
+        String name2 = getName();
+
+        if ( Strings.isEmpty( name1 ) )
+        {
+            if ( !Strings.isEmpty( name2 ) )
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if ( Strings.isEmpty( name2 ) )
+            {
+                return false;
+            }
+            else if ( !name2.equals( name1 ) )
+            {
+                return false;
+            }
+        }
+
+        Dn dn1 = req.getDn();
+        Dn dn2 = getDn();
 
-        if ( Dn.isNullOrEmpty( dn1) )
+        if ( Dn.isNullOrEmpty( dn1 ) )
         {
             if ( !Dn.isNullOrEmpty( dn2 ) )
             {
@@ -394,11 +460,12 @@ public class BindRequestImpl extends Abs
     public String toString()
     {
         StringBuffer sb = new StringBuffer();
-        
+
         sb.append( "    BindRequest\n" );
         sb.append( "        Version : '" ).append( isVersion3 ? "3" : "2" ).append( "'\n"
);
 
-        if ( ( (name == null ) || Strings.isEmpty(name.getNormName() ) ) && isSimple
)
+        if ( ( ( Strings.isEmpty( name ) ) || ( dn == null ) || Strings.isEmpty( dn.getNormName()
) )
+            && isSimple )
         {
             sb.append( "        Name : anonymous\n" );
         }
@@ -408,8 +475,8 @@ public class BindRequestImpl extends Abs
 
             if ( isSimple )
             {
-                sb.append( "        Simple authentication : '" ).append( Strings.utf8ToString(credentials)
)
-                    .append( '/' ).append( Strings.dumpBytes(credentials) ).append( "'\n"
);
+                sb.append( "        Simple authentication : '" ).append( Strings.utf8ToString(
credentials ) )
+                    .append( '/' ).append( Strings.dumpBytes( credentials ) ).append( "'\n"
);
             }
             else
             {

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/BindRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/BindRequestImplTest.java?rev=1233925&r1=1233924&r2=1233925&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/BindRequestImplTest.java
(original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/BindRequestImplTest.java
Fri Jan 20 14:28:25 2012
@@ -70,14 +70,14 @@ public class BindRequestImplTest
         BindRequestImpl req0 = new BindRequestImpl();
         req0.setMessageId( 5 );
         req0.setCredentials( "password".getBytes() );
-        req0.setName( new Dn( "cn=admin,dc=example,dc=com" ) );
+        req0.setDn( new Dn( "cn=admin,dc=example,dc=com" ) );
         req0.setSimple( true );
         req0.setVersion3( true );
 
         BindRequestImpl req1 = new BindRequestImpl();
         req1.setMessageId( 5 );
         req1.setCredentials( "password".getBytes() );
-        req1.setName( new Dn( "cn=admin,dc=example,dc=com" ) );
+        req1.setDn( new Dn( "cn=admin,dc=example,dc=com" ) );
         req1.setSimple( true );
         req1.setVersion3( true );
 
@@ -94,14 +94,14 @@ public class BindRequestImplTest
         BindRequestImpl req0 = new BindRequestImpl();
         req0.setMessageId( 7 );
         req0.setCredentials( "password".getBytes() );
-        req0.setName( new Dn( "cn=admin,dc=example,dc=com" ) );
+        req0.setDn( new Dn( "cn=admin,dc=example,dc=com" ) );
         req0.setSimple( true );
         req0.setVersion3( true );
 
         BindRequestImpl req1 = new BindRequestImpl();
         req1.setMessageId( 5 );
         req1.setCredentials( "password".getBytes() );
-        req1.setName( new Dn( "cn=admin,dc=example,dc=com" ) );
+        req1.setDn( new Dn( "cn=admin,dc=example,dc=com" ) );
         req1.setSimple( true );
         req1.setVersion3( true );
 
@@ -118,14 +118,14 @@ public class BindRequestImplTest
         BindRequestImpl req0 = new BindRequestImpl();
         req0.setMessageId( 5 );
         req0.setCredentials( "abcdefg".getBytes() );
-        req0.setName( new Dn( "cn=admin,dc=example,dc=com" ) );
+        req0.setDn( new Dn( "cn=admin,dc=example,dc=com" ) );
         req0.setSimple( true );
         req0.setVersion3( true );
 
         BindRequestImpl req1 = new BindRequestImpl();
         req1.setMessageId( 5 );
         req1.setCredentials( "password".getBytes() );
-        req1.setName( new Dn( "cn=admin,dc=example,dc=com" ) );
+        req1.setDn( new Dn( "cn=admin,dc=example,dc=com" ) );
         req1.setSimple( true );
         req1.setVersion3( true );
 
@@ -142,14 +142,14 @@ public class BindRequestImplTest
         BindRequestImpl req0 = new BindRequestImpl();
         req0.setMessageId( 5 );
         req0.setCredentials( "password".getBytes() );
-        req0.setName( new Dn( "uid=akarasulu,dc=example,dc=com" ) );
+        req0.setDn( new Dn( "uid=akarasulu,dc=example,dc=com" ) );
         req0.setSimple( true );
         req0.setVersion3( true );
 
         BindRequestImpl req1 = new BindRequestImpl();
         req1.setMessageId( 5 );
         req1.setCredentials( "password".getBytes() );
-        req1.setName( new Dn( "cn=admin,dc=example,dc=com" ) );
+        req1.setDn( new Dn( "cn=admin,dc=example,dc=com" ) );
         req1.setSimple( true );
         req1.setVersion3( true );
 
@@ -166,14 +166,14 @@ public class BindRequestImplTest
         BindRequestImpl req0 = new BindRequestImpl();
         req0.setMessageId( 5 );
         req0.setCredentials( "password".getBytes() );
-        req0.setName( new Dn( "cn=admin,dc=example,dc=com" ) );
+        req0.setDn( new Dn( "cn=admin,dc=example,dc=com" ) );
         req0.setSimple( false );
         req0.setVersion3( true );
 
         BindRequestImpl req1 = new BindRequestImpl();
         req1.setMessageId( 5 );
         req1.setCredentials( "password".getBytes() );
-        req1.setName( new Dn( "cn=admin,dc=example,dc=com" ) );
+        req1.setDn( new Dn( "cn=admin,dc=example,dc=com" ) );
         req1.setSimple( true );
         req1.setVersion3( true );
 
@@ -190,14 +190,14 @@ public class BindRequestImplTest
         BindRequestImpl req0 = new BindRequestImpl();
         req0.setMessageId( 5 );
         req0.setCredentials( "password".getBytes() );
-        req0.setName( new Dn( "cn=admin,dc=example,dc=com" ) );
+        req0.setDn( new Dn( "cn=admin,dc=example,dc=com" ) );
         req0.setSimple( true );
         req0.setVersion3( false );
 
         BindRequestImpl req1 = new BindRequestImpl();
         req1.setMessageId( 5 );
         req1.setCredentials( "password".getBytes() );
-        req1.setName( new Dn( "cn=admin,dc=example,dc=com" ) );
+        req1.setDn( new Dn( "cn=admin,dc=example,dc=com" ) );
         req1.setSimple( true );
         req1.setVersion3( true );
 
@@ -249,13 +249,25 @@ public class BindRequestImplTest
             }
 
 
-            public Dn getName()
+            public String getName()
             {
                 return null;
             }
 
 
-            public BindRequest setName( Dn name )
+            public BindRequest setName( String name )
+            {
+                return this;
+            }
+
+
+            public Dn getDn()
+            {
+                return null;
+            }
+
+
+            public BindRequest setDn( Dn dn )
             {
                 return this;
             }



Mime
View raw message