mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-29 15:22:15 +00:00
Added some further tests for LDAP searching with a different user search base.
This commit is contained in:
parent
feb790ea83
commit
e82dfd3f1a
@ -38,6 +38,16 @@ public class LdapUserServiceBeanDefinitionParserTests {
|
|||||||
assertEquals(2, ben.getAuthorities().length);
|
assertEquals(2, ben.getAuthorities().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void differentUserSearchBaseWorksAsExpected() throws Exception {
|
||||||
|
setContext("<ldap-user-service id='ldapUDS' user-search-base='ou=otherpeople' user-search-filter='(cn={0})' group-search-filter='member={0}' /><ldap-server />");
|
||||||
|
|
||||||
|
UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
|
||||||
|
UserDetails joe = uds.loadUserByUsername("Joe Smeth");
|
||||||
|
|
||||||
|
assertEquals("Joe Smeth", joe.getUsername());
|
||||||
|
}
|
||||||
|
|
||||||
private void setContext(String context) {
|
private void setContext(String context) {
|
||||||
appCtx = new InMemoryXmlApplicationContext(context);
|
appCtx = new InMemoryXmlApplicationContext(context);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicSearch() {
|
public void basicSearchSucceeds() {
|
||||||
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people", "(uid={0})", dirCtxFactory);
|
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people", "(uid={0})", dirCtxFactory);
|
||||||
locator.setSearchSubtree(false);
|
locator.setSearchSubtree(false);
|
||||||
locator.setSearchTimeLimit(0);
|
locator.setSearchTimeLimit(0);
|
||||||
@ -58,7 +58,7 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
|
|||||||
|
|
||||||
// Try some funny business with filters.
|
// Try some funny business with filters.
|
||||||
@Test
|
@Test
|
||||||
public void testExtraFilterPartToExcludeBob() throws Exception {
|
public void extraFilterPartToExcludeBob() throws Exception {
|
||||||
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people",
|
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people",
|
||||||
"(&(cn=*)(!(|(uid={0})(uid=rod))))", dirCtxFactory);
|
"(&(cn=*)(!(|(uid={0})(uid=rod))))", dirCtxFactory);
|
||||||
|
|
||||||
@ -70,19 +70,19 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IncorrectResultSizeDataAccessException.class)
|
@Test(expected=IncorrectResultSizeDataAccessException.class)
|
||||||
public void testFailsOnMultipleMatches() {
|
public void searchFailsOnMultipleMatches() {
|
||||||
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people", "(cn=*)", dirCtxFactory);
|
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people", "(cn=*)", dirCtxFactory);
|
||||||
locator.searchForUser("Ignored");
|
locator.searchForUser("Ignored");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=UsernameNotFoundException.class)
|
@Test(expected=UsernameNotFoundException.class)
|
||||||
public void testSearchForInvalidUserFails() {
|
public void searchForInvalidUserFails() {
|
||||||
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people", "(uid={0})", dirCtxFactory);
|
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people", "(uid={0})", dirCtxFactory);
|
||||||
locator.searchForUser("Joe");
|
locator.searchForUser("Joe");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSubTreeSearchSucceeds() {
|
public void subTreeSearchSucceeds() {
|
||||||
// Don't set the searchBase, so search from the root.
|
// Don't set the searchBase, so search from the root.
|
||||||
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("", "(cn={0})", dirCtxFactory);
|
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("", "(cn={0})", dirCtxFactory);
|
||||||
locator.setSearchSubtree(true);
|
locator.setSearchSubtree(true);
|
||||||
@ -93,5 +93,11 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
|
|||||||
assertEquals(new DistinguishedName("uid=ben,ou=people"), ben.getDn());
|
assertEquals(new DistinguishedName("uid=ben,ou=people"), ben.getDn());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add test with non-uid username
|
@Test
|
||||||
|
public void searchWithDifferentSearchBaseIsSuccessful() throws Exception {
|
||||||
|
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=otherpeople", "(cn={0})", dirCtxFactory);
|
||||||
|
DirContextOperations joe = locator.searchForUser("Joe Smeth");
|
||||||
|
assertEquals("Joe Smeth", joe.getStringAttribute("cn"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,11 @@ objectclass: top
|
|||||||
objectclass: organizationalUnit
|
objectclass: organizationalUnit
|
||||||
ou: people
|
ou: people
|
||||||
|
|
||||||
|
dn: ou=otherpeople,dc=springframework,dc=org
|
||||||
|
objectclass: top
|
||||||
|
objectclass: organizationalUnit
|
||||||
|
ou: otherpeople
|
||||||
|
|
||||||
dn: uid=ben,ou=people,dc=springframework,dc=org
|
dn: uid=ben,ou=people,dc=springframework,dc=org
|
||||||
objectclass: top
|
objectclass: top
|
||||||
objectclass: person
|
objectclass: person
|
||||||
@ -33,6 +38,16 @@ sn: Hamilton
|
|||||||
uid: bob
|
uid: bob
|
||||||
userPassword: bobspassword
|
userPassword: bobspassword
|
||||||
|
|
||||||
|
dn: uid=joe,ou=otherpeople,dc=springframework,dc=org
|
||||||
|
objectclass: top
|
||||||
|
objectclass: person
|
||||||
|
objectclass: organizationalPerson
|
||||||
|
objectclass: inetOrgPerson
|
||||||
|
cn: Joe Smeth
|
||||||
|
sn: Smeth
|
||||||
|
uid: joe
|
||||||
|
userPassword: joespassword
|
||||||
|
|
||||||
dn: cn=developers,ou=groups,dc=springframework,dc=org
|
dn: cn=developers,ou=groups,dc=springframework,dc=org
|
||||||
objectclass: top
|
objectclass: top
|
||||||
objectclass: groupOfNames
|
objectclass: groupOfNames
|
||||||
|
Loading…
x
Reference in New Issue
Block a user