From commits-return-18532-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Fri Jun 06 21:23:11 2008 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 70878 invoked from network); 6 Jun 2008 21:23:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Jun 2008 21:23:11 -0000 Received: (qmail 92885 invoked by uid 500); 6 Jun 2008 21:23:14 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 92844 invoked by uid 500); 6 Jun 2008 21:23:13 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 92835 invoked by uid 99); 6 Jun 2008 21:23:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Jun 2008 14:23:13 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Jun 2008 21:22:31 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0CE752388A06; Fri, 6 Jun 2008 14:22:49 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r664134 - in /directory/apacheds/branches/bigbang: core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java core/src/main/java/org/apache/directory/server/core/jndi/CoreContextFactory.java Date: Fri, 06 Jun 2008 21:22:48 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080606212249.0CE752388A06@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: akarasulu Date: Fri Jun 6 14:22:48 2008 New Revision: 664134 URL: http://svn.apache.org/viewvc?rev=664134&view=rev Log: fixed bug with setting principalDn on bind and corrected some tests Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/CoreContextFactory.java Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java?rev=664134&r1=664133&r2=664134&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java (original) +++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java Fri Jun 6 14:22:48 2008 @@ -25,6 +25,8 @@ import org.apache.directory.server.core.jndi.ServerLdapContext; import static org.apache.directory.server.core.integ.IntegrationUtils.*; + +import org.apache.directory.shared.ldap.constants.AuthenticationLevel; import org.apache.directory.shared.ldap.message.AttributeImpl; import org.apache.directory.shared.ldap.message.ModificationItemImpl; import org.apache.directory.shared.ldap.name.LdapDN; @@ -35,7 +37,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -79,7 +80,8 @@ { LdapDN dn = new LdapDN( bindDn ); dn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() ); - return null; // TODO service.getJndiContext( new LdapPrincipal( dn, AuthenticationLevel.SIMPLE ) ); + return new ServerLdapContext( service, + service.getSession( new LdapPrincipal( dn, AuthenticationLevel.SIMPLE ) ), new LdapDN() ); } throw new IllegalStateException( "Cannot acquire rootDSE before the service has been started!" ); @@ -92,7 +94,8 @@ { LdapDN dn = new LdapDN( "uid=admin,ou=system" ); dn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() ); - return null; // TODO service.getJndiContext( new LdapPrincipal( dn, AuthenticationLevel.SIMPLE ), "ou=system" ); + return new ServerLdapContext( service, + service.getSession( new LdapPrincipal( dn, AuthenticationLevel.SIMPLE ) ), new LdapDN( "ou=system" ) ); } throw new IllegalStateException( "Cannot acquire rootDSE before the service has been started!" ); @@ -105,7 +108,8 @@ { LdapDN dn = new LdapDN( bindDn ); dn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() ); - return null; // TODO service.getJndiContext( new LdapPrincipal( dn, AuthenticationLevel.SIMPLE ), "ou=system" ); + return new ServerLdapContext( service, + service.getSession( new LdapPrincipal( dn, AuthenticationLevel.SIMPLE ) ), new LdapDN( "ou=system" ) ); } throw new IllegalStateException( "Cannot acquire rootDSE before the service has been started!" ); @@ -219,12 +223,13 @@ @Test - @Ignore ( "broken until authentication is fixed" ) public void test11InvalidateCredentialCache() throws Exception { apply( getRootDSE(), getUserAddLdif() ); String userDn = "uid=akarasulu,ou=users,ou=system"; - LdapContext ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); + + LdapContext ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); assertNotNull( ctx ); Attributes attrs = ctx.getAttributes( "" ); Attribute ou = attrs.get( "ou" ); @@ -255,20 +260,21 @@ // close and try with old password (should fail) ctx.close(); - // TODO - fix it - // try -// { -// // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); -// fail( "Authentication with old password should fail" ); -// } -// catch ( NamingException e ) -// { -// // we should fail -// } + try + { + new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); + fail( "Authentication with old password should fail" ); + } + catch ( NamingException e ) + { + // we should fail + } // close and try again now with new password (should fail) ctx.close(); - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "newpwd".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "newpwd".getBytes() ), new LdapDN( userDn ) ); attrs = ctx.getAttributes( "" ); ou = attrs.get( "ou" ); assertTrue( ou.contains( "Engineering" ) ); @@ -293,12 +299,12 @@ @Test - @Ignore ( "broken until authentication is fixed" ) public void testSHA() throws Exception { apply( getRootDSE(), getUserAddLdif() ); String userDn = "uid=akarasulu,ou=users,ou=system"; - LdapContext ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); + LdapContext ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); // Check that we can get the attributes Attributes attrs = ctx.getAttributes( "" ); @@ -315,7 +321,8 @@ try { - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); fail( "Authentication with old password should fail" ); } catch ( Exception e ) @@ -331,7 +338,8 @@ } // try again now with new password (should be successfull) - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "secret".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "secret".getBytes() ), new LdapDN( userDn ) ); attrs = ctx.getAttributes( "" ); assertNotNull( attrs ); assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) ); @@ -339,7 +347,8 @@ // close and try again now with new password, to check that the // cache is updated (should be successfull) ctx.close(); - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "secret".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "secret".getBytes() ), new LdapDN( userDn ) ); attrs = ctx.getAttributes( "" ); assertNotNull( attrs ); assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) ); @@ -347,12 +356,12 @@ @Test - @Ignore ( "broken until authentication is fixed" ) public void testSSHA() throws Exception { apply( getRootDSE(), getUserAddLdif() ); String userDn = "uid=akarasulu,ou=users,ou=system"; - LdapContext ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); + LdapContext ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); // Check that we can get the attributes Attributes attrs = ctx.getAttributes( "" ); @@ -369,7 +378,8 @@ try { - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); fail( "Authentication with old password should fail" ); } catch ( Exception e ) @@ -385,14 +395,16 @@ } // try again now with new password (should be successfull) - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "secret".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "secret".getBytes() ), new LdapDN( 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) - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "secret".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "secret".getBytes() ), new LdapDN( userDn ) ); attrs = ctx.getAttributes( "" ); assertNotNull( attrs ); assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) ); @@ -400,12 +412,12 @@ @Test - @Ignore ( "broken until authentication is fixed" ) public void testMD5() throws Exception { apply( getRootDSE(), getUserAddLdif() ); String userDn = "uid=akarasulu,ou=users,ou=system"; - LdapContext ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); + LdapContext ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); // Check that we can get the attributes Attributes attrs = ctx.getAttributes( "" ); @@ -422,7 +434,8 @@ try { - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); fail( "Authentication with old password should fail" ); } catch ( Exception e ) @@ -438,14 +451,16 @@ } // try again now with new password (should be successfull) - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "secret".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "secret".getBytes() ), new LdapDN( 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) - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "secret".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "secret".getBytes() ), new LdapDN( userDn ) ); attrs = ctx.getAttributes( "" ); assertNotNull( attrs ); assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) ); @@ -453,12 +468,12 @@ @Test - @Ignore ( "broken until authentication is fixed" ) public void testSMD5() throws Exception { apply( getRootDSE(), getUserAddLdif() ); String userDn = "uid=akarasulu,ou=users,ou=system"; - LdapContext ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); + LdapContext ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); // Check that we can get the attributes Attributes attrs = ctx.getAttributes( "" ); @@ -475,7 +490,8 @@ try { - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); fail( "Authentication with old password should fail" ); } catch ( Exception e ) @@ -491,14 +507,16 @@ } // try again now with new password (should be successfull) - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "secret".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "secret".getBytes() ), new LdapDN( 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) - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "secret".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "secret".getBytes() ), new LdapDN( userDn ) ); attrs = ctx.getAttributes( "" ); assertNotNull( attrs ); assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) ); @@ -506,12 +524,12 @@ @Test - @Ignore ( "broken until authentication is fixed" ) public void testCRYPT() throws Exception { apply( getRootDSE(), getUserAddLdif() ); String userDn = "uid=akarasulu,ou=users,ou=system"; - LdapContext ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); + LdapContext ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); // Check that we can get the attributes Attributes attrs = ctx.getAttributes( "" ); @@ -528,7 +546,8 @@ try { - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); fail( "Authentication with old password should fail" ); } catch ( Exception e ) @@ -544,14 +563,16 @@ } // try again now with new password (should be successfull) - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "secret".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "secret".getBytes() ), new LdapDN( 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) - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "secret".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "secret".getBytes() ), new LdapDN( userDn ) ); attrs = ctx.getAttributes( "" ); assertNotNull( attrs ); assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) ); @@ -559,19 +580,20 @@ @Test - @Ignore ( "broken until authentication is fixed" ) public void testInvalidateCredentialCacheForUpdatingAnotherUsersPassword() throws Exception { apply( getRootDSE(), getUserAddLdif() ); // bind as akarasulu String userDn = "uid=akarasulu,ou=users,ou=system"; - LdapContext ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); + LdapContext ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); ctx.close(); // bind as admin userDn = "uid=admin,ou=system"; - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "secret".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "secret".getBytes() ), new LdapDN( userDn ) ); // now modify the password for akarasulu (while we're admin) AttributeImpl userPasswordAttribute = new AttributeImpl( "userPassword", "newpwd" ); @@ -581,7 +603,8 @@ try { - ctx = null; // TODO service.getJndiContext( new LdapDN( userDn ), userDn, "test".getBytes(), "simple", userDn ); + ctx = new ServerLdapContext( service, + service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ); fail( "Authentication with old password should fail" ); } catch ( Exception e ) Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/CoreContextFactory.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/CoreContextFactory.java?rev=664134&r1=664133&r2=664134&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/CoreContextFactory.java (original) +++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/CoreContextFactory.java Fri Jun 6 14:22:48 2008 @@ -46,16 +46,7 @@ public synchronized Context getInitialContext( Hashtable env ) throws NamingException { env = ( Hashtable ) env.clone(); - LdapDN principalDn = null; - if ( env.containsKey( Context.SECURITY_PRINCIPAL ) ) - { - if ( env.get( Context.SECURITY_PRINCIPAL ) instanceof LdapDN ) - { - principalDn = ( LdapDN ) env.get( Context.SECURITY_PRINCIPAL ); - } - } - - String principal = getPrincipal( env ); + LdapDN principalDn = new LdapDN( getPrincipal( env ) ); byte[] credential = getCredential( env ); String authentication = getAuthentication( env ); String providerUrl = getProviderUrl( env );