Added test for new class LookupAttemptingCallback.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package org.springframework.ldap.core.support;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.springframework.ldap.core.AuthenticatedLdapEntryContextCallback;
|
||||
import org.springframework.ldap.core.LdapEntryIdentification;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
|
||||
/**
|
||||
* Attempts to perform an LDAP operation in the authenticated context, because
|
||||
* Active Directory might allow bind with incorrect password (specifically empty
|
||||
* password), and later refuse operations. We want to fail fast when
|
||||
* authenticating.
|
||||
*
|
||||
* @author Hugo Josefson
|
||||
* @since 1.3.1
|
||||
*/
|
||||
public class LookupAttemptingCallback implements AuthenticatedLdapEntryContextCallback {
|
||||
public void executeWithContext(DirContext ctx, LdapEntryIdentification ldapEntryIdentification) {
|
||||
try {
|
||||
ctx.lookup(ldapEntryIdentification.getRelativeDn());
|
||||
}
|
||||
catch (NamingException e) {
|
||||
// rethrow, because we aren't allowed to throw checked exceptions.
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.LdapEntryIdentification;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.CollectingAuthenticationErrorCallback;
|
||||
import org.springframework.ldap.core.support.LookupAttemptingCallback;
|
||||
import org.springframework.ldap.filter.AndFilter;
|
||||
import org.springframework.ldap.filter.EqualsFilter;
|
||||
import org.springframework.ldap.filter.WhitespaceWildcardsFilter;
|
||||
@@ -106,4 +107,12 @@ public class LdapTemplateAuthenticationITest extends AbstractLdapTemplateIntegra
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new WhitespaceWildcardsFilter("uid", "some.person"));
|
||||
assertFalse(tested.authenticate("", filter.toString(), "password"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupAttemptingCallback() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
LookupAttemptingCallback callback = new LookupAttemptingCallback();
|
||||
assertTrue(tested.authenticate("", filter.encode(), "password", callback));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,12 +40,12 @@ import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Integration tests for ContextSourceImpl.
|
||||
* Integration tests for LdapContextSource.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapContextSourcelITest extends AbstractLdapTemplateIntegrationTest {
|
||||
public class LdapContextSourceIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ContextSource tested;
|
||||
@@ -25,12 +25,12 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
/**
|
||||
* Integration tests for ContextSourceImpl.
|
||||
* Advanced integration tests for LdapContextSource.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapContextSourceTestContext.xml" })
|
||||
public class LdapContextSourcelMultiServerITest extends AbstractJUnit4SpringContextTests {
|
||||
public class LdapContextSourceMultiServerIntegrationTest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private LdapContextSource tested;
|
||||
Reference in New Issue
Block a user