You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/03/05 07:32:11 UTC

svn commit: r919311 - in /directory/apacheds/branches/apacheds-1.5.6/core-integ: pom.xml src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java

Author: kayyagari
Date: Fri Mar  5 06:32:11 2010
New Revision: 919311

URL: http://svn.apache.org/viewvc?rev=919311&view=rev
Log:
reverting the changes done to migrate tests to use client-api

Modified:
    directory/apacheds/branches/apacheds-1.5.6/core-integ/pom.xml
    directory/apacheds/branches/apacheds-1.5.6/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java

Modified: directory/apacheds/branches/apacheds-1.5.6/core-integ/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-1.5.6/core-integ/pom.xml?rev=919311&r1=919310&r2=919311&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-1.5.6/core-integ/pom.xml (original)
+++ directory/apacheds/branches/apacheds-1.5.6/core-integ/pom.xml Fri Mar  5 06:32:11 2010
@@ -60,12 +60,6 @@
       <artifactId>commons-io</artifactId>
       <version>${commons.io.version}</version>
     </dependency>
-    
-    <dependency>
-      <groupId>org.apache.directory.client.ldap</groupId>
-      <artifactId>ldap-client-api</artifactId>
-      <version>0.1-SNAPSHOT</version>
-    </dependency> 
   </dependencies>
 
   <profiles>

Modified: directory/apacheds/branches/apacheds-1.5.6/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-1.5.6/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java?rev=919311&r1=919310&r2=919311&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-1.5.6/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java (original)
+++ directory/apacheds/branches/apacheds-1.5.6/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java Fri Mar  5 06:32:11 2010
@@ -22,21 +22,21 @@
 
 import static org.apache.directory.server.core.integ.IntegrationUtils.apply;
 import static org.apache.directory.server.core.integ.IntegrationUtils.getUserAddLdif;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.ldap.LdapContext;
 
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.message.ModifyRequest;
-import org.apache.directory.ldap.client.api.message.SearchResultEntry;
-import org.apache.directory.server.annotations.CreateLdapServer;
-import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
-import org.apache.directory.shared.ldap.entry.Entry;
-import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.server.core.jndi.ServerLdapContext;
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.util.ArrayUtils;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -51,24 +51,22 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-@RunWith(FrameworkRunner.class)
-@CreateLdapServer(transports =
-    { @CreateTransport(protocol = "LDAP") })
+@RunWith( FrameworkRunner.class )
 public class SimpleAuthenticationIT extends AbstractLdapTestUnit
 {
     /**
      * Checks all attributes of the admin account entry minus the userPassword
      * attribute.
      *
-     * @param entry the entries attributes
+     * @param attrs the entries attributes
      */
-    protected void performAdminAccountChecks( Entry entry )
+    protected void performAdminAccountChecks( Attributes attrs )
     {
-        assertTrue( entry.get( "objectClass" ).contains( "top" ) );
-        assertTrue( entry.get( "objectClass" ).contains( "person" ) );
-        assertTrue( entry.get( "objectClass" ).contains( "organizationalPerson" ) );
-        assertTrue( entry.get( "objectClass" ).contains( "inetOrgPerson" ) );
-        assertTrue( entry.get( "displayName" ).contains( "Directory Superuser" ) );
+        assertTrue( attrs.get( "objectClass" ).contains( "top" ) );
+        assertTrue( attrs.get( "objectClass" ).contains( "person" ) );
+        assertTrue( attrs.get( "objectClass" ).contains( "organizationalPerson" ) );
+        assertTrue( attrs.get( "objectClass" ).contains( "inetOrgPerson" ) );
+        assertTrue( attrs.get( "displayName" ).contains( "Directory Superuser" ) );
     }
 
 
@@ -81,25 +79,22 @@
     public void testAdminAccountCreation() throws Exception
     {
         String userDn = "uid=admin,ou=system";
-        LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
-        connection.bind( userDn, "secret" );
-
-        Entry entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        performAdminAccountChecks( entry );
-        assertTrue( ArrayUtils.isEquals( entry.get( "userPassword" ).get().getBytes(), StringTools
-            .getBytesUtf8( "secret" ) ) );
-        connection.close();
-
-        ldapServer.stop();
-        ldapServer.start();
-
-        connection = new LdapConnection( "localhost", ldapServer.getPort() );
-        connection.bind( userDn, "secret" );
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        performAdminAccountChecks( entry );
-        assertTrue( ArrayUtils.isEquals( entry.get( "userPassword" ).get().getBytes(), StringTools
-            .getBytesUtf8( "secret" ) ) );
-        connection.close();
+        LdapContext ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( "ou=system" ) );
+        Attributes attrs = ctx.getAttributes( "uid=admin" );
+        performAdminAccountChecks( attrs );
+        assertTrue( ArrayUtils.isEquals( attrs.get( "userPassword" ).get(), StringTools.getBytesUtf8( "secret" ) ) );
+        ctx.close();
+
+        service.shutdown();
+        service.startup();
+
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( "ou=system" ) );
+        attrs = ctx.getAttributes( "uid=admin" );
+        performAdminAccountChecks( attrs );
+        assertTrue( ArrayUtils.isEquals( attrs.get( "userPassword" ).get(), StringTools.getBytesUtf8( "secret" ) ) );
+        ctx.close();
     }
 
 
@@ -108,30 +103,29 @@
     {
         apply( service, getUserAddLdif() );
         String userDn = "uid=akarasulu,ou=users,ou=system";
-        LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
-        connection.bind( userDn, "test" );
+        LdapContext ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
 
-        Entry entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        EntryAttribute ou = entry.get( "ou" );
+        Attributes attrs = ctx.getAttributes( "" );
+        Attribute ou = attrs.get( "ou" );
         assertTrue( ou.contains( "Engineering" ) );
         assertTrue( ou.contains( "People" ) );
 
-        EntryAttribute objectClass = entry.get( "objectClass" );
+        Attribute objectClass = attrs.get( "objectClass" );
         assertTrue( objectClass.contains( "top" ) );
         assertTrue( objectClass.contains( "person" ) );
         assertTrue( objectClass.contains( "organizationalPerson" ) );
         assertTrue( objectClass.contains( "inetOrgPerson" ) );
 
-        assertTrue( entry.get( "telephonenumber" ).contains( "+1 408 555 4798" ) );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
-        assertTrue( entry.get( "givenname" ).contains( "Alex" ) );
-        assertTrue( entry.get( "mail" ).contains( "akarasulu@apache.org" ) );
-        assertTrue( entry.get( "l" ).contains( "Bogusville" ) );
-        assertTrue( entry.get( "sn" ).contains( "Karasulu" ) );
-        assertTrue( entry.get( "cn" ).contains( "Alex Karasulu" ) );
-        assertTrue( entry.get( "facsimiletelephonenumber" ).contains( "+1 408 555 9751" ) );
-        assertTrue( entry.get( "roomnumber" ).contains( "4612" ) );
-        connection.close();
+        assertTrue( attrs.get( "telephonenumber" ).contains( "+1 408 555 4798" ) );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
+        assertTrue( attrs.get( "givenname" ).contains( "Alex" ) );
+        assertTrue( attrs.get( "mail" ).contains( "akarasulu@apache.org" ) );
+        assertTrue( attrs.get( "l" ).contains( "Bogusville" ) );
+        assertTrue( attrs.get( "sn" ).contains( "Karasulu" ) );
+        assertTrue( attrs.get( "cn" ).contains( "Alex Karasulu" ) );
+        assertTrue( attrs.get( "facsimiletelephonenumber" ).contains( "+1 408 555 9751" ) );
+        assertTrue( attrs.get( "roomnumber" ).contains( "4612" ) );
     }
 
 
@@ -145,10 +139,8 @@
     public void test8PassPrincAuthTypeSimple() throws Exception
     {
         String userDn = "uid=admin,ou=system";
-        LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
-        connection.bind( userDn, "secret" );
-        assertTrue( connection.isAuthenticated() );
-        connection.close();
+        assertNotNull( new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) ) );
     }
 
 
@@ -163,10 +155,8 @@
     {
         apply( service, getUserAddLdif() );
         String userDn = "uid=akarasulu,ou=users,ou=system";
-        LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
-        connection.bind( userDn, "test" );
-        assertTrue( connection.isAuthenticated() );
-        connection.close();
+        assertNotNull( new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) ) );
     }
 
 
@@ -175,66 +165,74 @@
     {
         apply( service, getUserAddLdif() );
         String userDn = "uid=akarasulu,ou=users,ou=system";
-
-        LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
-        connection.bind( userDn, "test" );
-
-        Entry entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        EntryAttribute ou = entry.get( "ou" );
+        
+        LdapContext ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
+        assertNotNull( ctx );
+        Attributes attrs = ctx.getAttributes( "" );
+        Attribute ou = attrs.get( "ou" );
         assertTrue( ou.contains( "Engineering" ) );
         assertTrue( ou.contains( "People" ) );
 
-        EntryAttribute objectClass = entry.get( "objectClass" );
+        Attribute objectClass = attrs.get( "objectClass" );
         assertTrue( objectClass.contains( "top" ) );
         assertTrue( objectClass.contains( "person" ) );
         assertTrue( objectClass.contains( "organizationalPerson" ) );
         assertTrue( objectClass.contains( "inetOrgPerson" ) );
 
-        assertTrue( entry.get( "telephonenumber" ).contains( "+1 408 555 4798" ) );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
-        assertTrue( entry.get( "givenname" ).contains( "Alex" ) );
-        assertTrue( entry.get( "mail" ).contains( "akarasulu@apache.org" ) );
-        assertTrue( entry.get( "l" ).contains( "Bogusville" ) );
-        assertTrue( entry.get( "sn" ).contains( "Karasulu" ) );
-        assertTrue( entry.get( "cn" ).contains( "Alex Karasulu" ) );
-        assertTrue( entry.get( "facsimiletelephonenumber" ).contains( "+1 408 555 9751" ) );
-        assertTrue( entry.get( "roomnumber" ).contains( "4612" ) );
+        assertTrue( attrs.get( "telephonenumber" ).contains( "+1 408 555 4798" ) );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
+        assertTrue( attrs.get( "givenname" ).contains( "Alex" ) );
+        assertTrue( attrs.get( "mail" ).contains( "akarasulu@apache.org" ) );
+        assertTrue( attrs.get( "l" ).contains( "Bogusville" ) );
+        assertTrue( attrs.get( "sn" ).contains( "Karasulu" ) );
+        assertTrue( attrs.get( "cn" ).contains( "Alex Karasulu" ) );
+        assertTrue( attrs.get( "facsimiletelephonenumber" ).contains( "+1 408 555 9751" ) );
+        assertTrue( attrs.get( "roomnumber" ).contains( "4612" ) );
 
         // now modify the password for akarasulu
-        ModifyRequest modReq = new ModifyRequest( new DN( userDn ) );
-        modReq.replace( "userPassword", "newpwd" );
-        connection.modify( modReq );
+        Attribute userPasswordAttribute = new BasicAttribute( "userPassword", "newpwd" );
+        ctx.modifyAttributes( "", new ModificationItem[] {
+            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );
 
         // close and try with old password (should fail)
-        connection.close();
+        ctx.close();
 
-        connection.bind( userDn, "test" );
-        assertFalse( connection.isAuthenticated() );
+        try
+        {
+            new ServerLdapContext( service, 
+                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
+            fail( "Authentication with old password should fail" );
+        }
+        catch ( NamingException e )
+        {
+            // we should fail
+        }
 
         // close and try again now with new password (should fail)
-        connection.close();
-        connection.bind( userDn, "newpwd" );
-
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        ou = entry.get( "ou" );
+        ctx.close();
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "newpwd".getBytes() ), new DN( userDn ) ); 
+        attrs = ctx.getAttributes( "" );
+        ou = attrs.get( "ou" );
         assertTrue( ou.contains( "Engineering" ) );
         assertTrue( ou.contains( "People" ) );
 
-        objectClass = entry.get( "objectClass" );
+        objectClass = attrs.get( "objectClass" );
         assertTrue( objectClass.contains( "top" ) );
         assertTrue( objectClass.contains( "person" ) );
         assertTrue( objectClass.contains( "organizationalPerson" ) );
         assertTrue( objectClass.contains( "inetOrgPerson" ) );
 
-        assertTrue( entry.get( "telephonenumber" ).contains( "+1 408 555 4798" ) );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
-        assertTrue( entry.get( "givenname" ).contains( "Alex" ) );
-        assertTrue( entry.get( "mail" ).contains( "akarasulu@apache.org" ) );
-        assertTrue( entry.get( "l" ).contains( "Bogusville" ) );
-        assertTrue( entry.get( "sn" ).contains( "Karasulu" ) );
-        assertTrue( entry.get( "cn" ).contains( "Alex Karasulu" ) );
-        assertTrue( entry.get( "facsimiletelephonenumber" ).contains( "+1 408 555 9751" ) );
-        assertTrue( entry.get( "roomnumber" ).contains( "4612" ) );
+        assertTrue( attrs.get( "telephonenumber" ).contains( "+1 408 555 4798" ) );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
+        assertTrue( attrs.get( "givenname" ).contains( "Alex" ) );
+        assertTrue( attrs.get( "mail" ).contains( "akarasulu@apache.org" ) );
+        assertTrue( attrs.get( "l" ).contains( "Bogusville" ) );
+        assertTrue( attrs.get( "sn" ).contains( "Karasulu" ) );
+        assertTrue( attrs.get( "cn" ).contains( "Alex Karasulu" ) );
+        assertTrue( attrs.get( "facsimiletelephonenumber" ).contains( "+1 408 555 9751" ) );
+        assertTrue( attrs.get( "roomnumber" ).contains( "4612" ) );
     }
 
 
@@ -243,42 +241,55 @@
     {
         apply( service, getUserAddLdif() );
         String userDn = "uid=akarasulu,ou=users,ou=system";
-        LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
-        connection.bind( userDn, "test" );
+        LdapContext ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) ); 
 
         // Check that we can get the attributes
-
-        Entry entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        Attributes attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
 
         // now modify the password for akarasulu : 'secret', encrypted using SHA
-        ModifyRequest modReq = new ModifyRequest( new DN( userDn ) );
-        modReq.replace( "userPassword", "{SHA}5en6G6MezRroT3XKqkdPOmY/BfQ=" );
-        connection.modify( modReq );
+        Attribute userPasswordAttribute = new BasicAttribute( "userPassword", "{SHA}5en6G6MezRroT3XKqkdPOmY/BfQ=" );
+        ctx.modifyAttributes( "", new ModificationItem[] {
+            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );
 
         // close and try with old password (should fail)
-        connection.close();
+        ctx.close();
 
-        connection.bind( userDn, "test" );
-        assertFalse( connection.isAuthenticated() );
-        connection.close();
+        try
+        {
+            ctx = new ServerLdapContext( service, 
+                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
+            fail( "Authentication with old password should fail" );
+        }
+        catch ( Exception e )
+        {
+            // we should fail
+        }
+        finally
+        {
+            if ( ctx != null )
+            {
+                ctx.close();
+            }
+        }
 
         // try again now with new password (should be successfull)
-        connection.bind( userDn, "secret" );
-        assertTrue( connection.isAuthenticated() );
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
+        attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
 
         // close and try again now with new password, to check that the
         // cache is updated (should be successfull)
-        connection.close();
-        connection.bind( userDn, "secret" );
-        assertTrue( connection.isAuthenticated() );
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        ctx.close();
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) ); 
+        attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
     }
 
 
@@ -287,80 +298,110 @@
     {
         apply( service, getUserAddLdif() );
         String userDn = "uid=akarasulu,ou=users,ou=system";
-        LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
-        connection.bind( userDn, "test" );
+        LdapContext ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
 
         // Check that we can get the attributes
-        Entry entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        Attributes attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
 
         // now modify the password for akarasulu : 'secret', encrypted using SHA
-        ModifyRequest modReq = new ModifyRequest( new DN( userDn ) );
-        modReq.replace( "userPassword", "{SSHA}mjVVxasFkk59wMW4L1Ldt+YCblfhULHs03WW7g==" );
-        connection.modify( modReq );
+        BasicAttribute userPasswordAttribute = new BasicAttribute( "userPassword", "{SSHA}mjVVxasFkk59wMW4L1Ldt+YCblfhULHs03WW7g==" );
+        ctx.modifyAttributes( "", new ModificationItem[] {
+            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );
 
         // close and try with old password (should fail)
-        connection.close();
+        ctx.close();
 
-        connection.bind( userDn, "test" );
-        assertFalse( connection.isAuthenticated() );
-        connection.close();
+        try
+        {
+            ctx = new ServerLdapContext( service, 
+                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
+            fail( "Authentication with old password should fail" );
+        }
+        catch ( Exception e )
+        {
+            // we should fail
+        }
+        finally
+        {
+            if ( ctx != null )
+            {
+                ctx.close();
+            }
+        }
 
         // try again now with new password (should be successfull)
-        connection.bind( userDn, "secret" );
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
+        attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
 
         // close and try again now with new password, to check that the
         // cache is updated (should be successfull)
-        connection.close();
-        connection.bind( userDn, "secret" );
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
+        attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
     }
-
-
+    
+    
     @Test
     public void testSSHA4BytesSalt() throws Exception
     {
         apply( service, getUserAddLdif() );
         String userDn = "uid=akarasulu,ou=users,ou=system";
-        LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
-        connection.bind( userDn, "test" );
+        LdapContext ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
 
         // Check that we can get the attributes
-        Entry entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        Attributes attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
 
         // now modify the password for akarasulu : 'test123', encrypted using SHA with a 4 bytes salt
-        ModifyRequest modReq = new ModifyRequest( new DN( userDn ) );
-        modReq.replace( "userPassword", "{SSHA}0TT388zsWzHKtMEpIU/8/W68egchNEWp" );
-        connection.modify( modReq );
+        BasicAttribute userPasswordAttribute = new BasicAttribute( "userPassword", "{SSHA}0TT388zsWzHKtMEpIU/8/W68egchNEWp" );
+        ctx.modifyAttributes( "", new ModificationItem[] {
+            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );
 
         // close and try with old password (should fail)
-        connection.close();
+        ctx.close();
 
-        connection.bind( userDn, "test" );
-        assertFalse( connection.isAuthenticated() );
-        connection.close();
+        try
+        {
+            ctx = new ServerLdapContext( service, 
+                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
+            fail( "Authentication with old password should fail" );
+        }
+        catch ( Exception e )
+        {
+            // we should fail
+        }
+        finally
+        {
+            if ( ctx != null )
+            {
+                ctx.close();
+            }
+        }
 
         // try again now with new password (should be successful)
-        connection.bind( userDn, "test123" );
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "test123".getBytes() ), new DN( userDn ) );
+        attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
 
         // close and try again now with new password, to check that the
         // cache is updated (should be successfull)
-        connection.close();
-        connection.bind( userDn, "test123" );
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "test123".getBytes() ), new DN( userDn ) );
+        attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
     }
 
 
@@ -369,40 +410,54 @@
     {
         apply( service, getUserAddLdif() );
         String userDn = "uid=akarasulu,ou=users,ou=system";
-        LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
-        connection.bind( userDn, "test" );
+        LdapContext ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
 
         // Check that we can get the attributes
-        Entry entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        Attributes attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
 
         // now modify the password for akarasulu : 'secret', encrypted using MD5
-        ModifyRequest modReq = new ModifyRequest( new DN( userDn ) );
-        modReq.replace( "userPassword", "{MD5}Xr4ilOzQ4PCOq3aQ0qbuaQ==" );
-        connection.modify( modReq );
+        Attribute userPasswordAttribute = new BasicAttribute( "userPassword", "{MD5}Xr4ilOzQ4PCOq3aQ0qbuaQ==" );
+        ctx.modifyAttributes( "", new ModificationItem[] {
+            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );
 
         // close and try with old password (should fail)
-        connection.close();
+        ctx.close();
 
-        connection.bind( userDn, "test" );
-        assertFalse( connection.isAuthenticated() );
-        connection.close();
+        try
+        {
+            ctx = new ServerLdapContext( service, 
+                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
+            fail( "Authentication with old password should fail" );
+        }
+        catch ( Exception e )
+        {
+            // we should fail
+        }
+        finally
+        {
+            if ( ctx != null )
+            {
+                ctx.close();
+            }
+        }
 
         // try again now with new password (should be successfull)
-        connection.bind( userDn, "secret" );
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
+        attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
 
         // try again now with new password, to check that the
         // cache is updated (should be successfull)
-
-        connection.close();
-        connection.bind( userDn, "secret" );
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
+        attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
     }
 
 
@@ -411,39 +466,54 @@
     {
         apply( service, getUserAddLdif() );
         String userDn = "uid=akarasulu,ou=users,ou=system";
-        LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
-        connection.bind( userDn, "test" );
+        LdapContext ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
 
         // Check that we can get the attributes
-        Entry entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        Attributes attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
 
         // now modify the password for akarasulu : 'secret', encrypted using SMD5
-        ModifyRequest modReq = new ModifyRequest( new DN( userDn ) );
-        modReq.replace( "userPassword", "{SMD5}tQ9wo/VBuKsqBtylMMCcORbnYOJFMyDJ" );
-        connection.modify( modReq );
+        Attribute userPasswordAttribute = new BasicAttribute( "userPassword", "{SMD5}tQ9wo/VBuKsqBtylMMCcORbnYOJFMyDJ" );
+        ctx.modifyAttributes( "", new ModificationItem[] {
+            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );
 
         // close and try with old password (should fail)
-        connection.close();
+        ctx.close();
 
-        connection.bind( userDn, "test" );
-        assertFalse( connection.isAuthenticated() );
-        connection.close();
+        try
+        {
+            ctx = new ServerLdapContext( service, 
+                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
+            fail( "Authentication with old password should fail" );
+        }
+        catch ( Exception e )
+        {
+            // we should fail
+        }
+        finally
+        {
+            if ( ctx != null )
+            {
+                ctx.close();
+            }
+        }
 
         // try again now with new password (should be successful)
-        connection.bind( userDn, "secret" );
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
+        attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
 
         // try again now with new password, to check that the
         // cache is updated (should be successfull)
-        connection.close();
-        connection.bind( userDn, "secret" );
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
+        attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
     }
 
 
@@ -452,38 +522,54 @@
     {
         apply( service, getUserAddLdif() );
         String userDn = "uid=akarasulu,ou=users,ou=system";
-        LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
-        connection.bind( userDn, "test" );
+        LdapContext ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
 
         // Check that we can get the attributes
-        Entry entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        Attributes attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
 
         // now modify the password for akarasulu : 'secret', encrypted using CRYPT
-        ModifyRequest modReq = new ModifyRequest( new DN( userDn ) );
-        modReq.replace( "userPassword", "{crypt}qFkH8Z1woBlXw" );
-        connection.modify( modReq );
+        Attribute userPasswordAttribute = new BasicAttribute( "userPassword", "{crypt}qFkH8Z1woBlXw" );
+        ctx.modifyAttributes( "", new ModificationItem[] {
+            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );
 
         // close and try with old password (should fail)
-        connection.close();
+        ctx.close();
 
-        connection.bind( userDn, "test" );
-        assertFalse( connection.isAuthenticated() );
-        connection.close();
+        try
+        {
+            ctx = new ServerLdapContext( service, 
+                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
+            fail( "Authentication with old password should fail" );
+        }
+        catch ( Exception e )
+        {
+            // we should fail
+        }
+        finally
+        {
+            if ( ctx != null )
+            {
+                ctx.close();
+            }
+        }
 
         // try again now with new password (should be successfull)
-        connection.bind( userDn, "secret" );
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
+        attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
 
         // try again now with new password, to check that the
         // cache is updated (should be successfull)
-        connection.bind( userDn, "secret" );
-        entry = ( ( SearchResultEntry ) connection.lookup( userDn ) ).getEntry();
-        assertNotNull( entry );
-        assertTrue( entry.get( "uid" ).contains( "akarasulu" ) );
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) ); 
+        attrs = ctx.getAttributes( "" );
+        assertNotNull( attrs );
+        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
     }
 
 
@@ -494,22 +580,37 @@
 
         // bind as akarasulu
         String userDn = "uid=akarasulu,ou=users,ou=system";
-        LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() );
-        connection.bind( userDn, "test" );
-        connection.close();
+        LdapContext ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
+        ctx.close();
 
         // bind as admin
-        String adminUserDn = "uid=admin,ou=system";
-        connection.bind( adminUserDn, "secret" );
+        userDn = "uid=admin,ou=system";
+        ctx = new ServerLdapContext( service, 
+            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
 
         // now modify the password for akarasulu (while we're admin)
-        ModifyRequest modReq = new ModifyRequest( new DN( userDn ) );
-        modReq.replace( "userPassword", "newpwd" );
-        connection.modify( modReq );
-        connection.close();
-
-        connection.bind( userDn, "test" );
-        assertFalse( connection.isAuthenticated() );
-        connection.close();
+        Attribute userPasswordAttribute = new BasicAttribute( "userPassword", "newpwd" );
+        ctx.modifyAttributes( "", new ModificationItem[] {
+            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );
+        ctx.close();
+
+        try
+        {
+            ctx = new ServerLdapContext( service, 
+                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
+            fail( "Authentication with old password should fail" );
+        }
+        catch ( Exception e )
+        {
+            // we should fail
+        }
+        finally
+        {
+            if ( ctx != null )
+            {
+                ctx.close();
+            }
+        }
     }
 }