From 01b8def4550ae62a982c999439e00463d55798c3 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Wed, 3 Jun 2009 17:13:33 +0000 Subject: [PATCH] SEC-1145: Added test to confirm that there is no pooling issue in the trunk. There are already checks for the presence of the pooling flag. --- ...faultSpringSecurityContextSourceTests.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/ldap/src/test/java/org/springframework/security/ldap/DefaultSpringSecurityContextSourceTests.java b/ldap/src/test/java/org/springframework/security/ldap/DefaultSpringSecurityContextSourceTests.java index e010603f92..5a8489cdd8 100644 --- a/ldap/src/test/java/org/springframework/security/ldap/DefaultSpringSecurityContextSourceTests.java +++ b/ldap/src/test/java/org/springframework/security/ldap/DefaultSpringSecurityContextSourceTests.java @@ -4,7 +4,10 @@ import static org.junit.Assert.*; import java.util.Hashtable; +import javax.naming.directory.DirContext; + import org.junit.Test; +import org.springframework.ldap.AuthenticationException; import org.springframework.ldap.core.support.AbstractContextSource; @@ -12,7 +15,7 @@ import org.springframework.ldap.core.support.AbstractContextSource; * @author Luke Taylor * @version $Id$ */ -public class DefaultSpringSecurityContextSourceTests { +public class DefaultSpringSecurityContextSourceTests extends AbstractLdapIntegrationTests { @Test public void instantiationSucceedsWithExpectedProperties() { @@ -47,6 +50,23 @@ public class DefaultSpringSecurityContextSourceTests { assertFalse(ctxSrc.getAuthenticatedEnvForTest("user", "password").containsKey(AbstractContextSource.SUN_LDAP_POOLING_FLAG)); } + // SEC-1145. Confirms that there is no issue here with pooling. + @Test(expected=AuthenticationException.class) + public void cantBindWithWrongPasswordImmediatelyAfterSuccessfulBind() throws Exception { + DirContext ctx = null; + try { + ctx = getContextSource().getContext("uid=Bob,ou=people,dc=springframework,dc=org", "bobspassword"); + } catch (Exception e) { + } + assertNotNull(ctx); +// com.sun.jndi.ldap.LdapPoolManager.showStats(System.out); + ctx.close(); +// com.sun.jndi.ldap.LdapPoolManager.showStats(System.out); + // Now get it gain, with wrong password. Should fail. + ctx = getContextSource().getContext("uid=Bob,ou=people,dc=springframework,dc=org", "wrongpassword"); + } + + static class EnvExposingDefaultSpringSecurityContextSource extends DefaultSpringSecurityContextSource { public EnvExposingDefaultSpringSecurityContextSource(String providerUrl) { super(providerUrl);