SEC-1641: Remove the private setGroupSearchBase method and allowed a null value to be set for the group search base in the constructor.

This commit is contained in:
Luke Taylor 2010-12-19 16:18:30 +00:00
parent 4dea140331
commit 952af853ac
2 changed files with 17 additions and 22 deletions

View File

@ -124,12 +124,6 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator
* The pattern to be used for the user search. {0} is the user's DN * The pattern to be used for the user search. {0} is the user's DN
*/ */
private String groupSearchFilter = "(member={0})"; private String groupSearchFilter = "(member={0})";
/**
* Attributes of the User's LDAP Object that contain role name information.
*/
// private String[] userRoleAttributes = null;
private String rolePrefix = "ROLE_"; private String rolePrefix = "ROLE_";
private boolean convertToUpperCase = true; private boolean convertToUpperCase = true;
@ -141,13 +135,17 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator
* *
* @param contextSource supplies the contexts used to search for user roles. * @param contextSource supplies the contexts used to search for user roles.
* @param groupSearchBase if this is an empty string the search will be performed from the root DN of the * @param groupSearchBase if this is an empty string the search will be performed from the root DN of the
* context factory. * context factory. If null, no search will be performed.
*/ */
public DefaultLdapAuthoritiesPopulator(ContextSource contextSource, String groupSearchBase) { public DefaultLdapAuthoritiesPopulator(ContextSource contextSource, String groupSearchBase) {
Assert.notNull(contextSource, "contextSource must not be null"); Assert.notNull(contextSource, "contextSource must not be null");
ldapTemplate = new SpringSecurityLdapTemplate(contextSource); ldapTemplate = new SpringSecurityLdapTemplate(contextSource);
ldapTemplate.setSearchControls(searchControls); ldapTemplate.setSearchControls(searchControls);
setGroupSearchBase(groupSearchBase); this.groupSearchBase = groupSearchBase;
if (groupSearchBase.length() == 0) {
logger.info("groupSearchBase is empty. Searches will be performed from the context source base");
}
} }
//~ Methods ======================================================================================================== //~ Methods ========================================================================================================
@ -232,20 +230,6 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator
return ldapTemplate.getContextSource(); return ldapTemplate.getContextSource();
} }
/**
* Set the group search base (name to search under)
*
* @param groupSearchBase if this is an empty string the search will be performed from the root DN of the context
* factory.
*/
private void setGroupSearchBase(String groupSearchBase) {
Assert.notNull(groupSearchBase, "The groupSearchBase (name to search under), must not be null.");
this.groupSearchBase = groupSearchBase;
if (groupSearchBase.length() == 0) {
logger.info("groupSearchBase is empty. Searches will be performed from the context source base");
}
}
protected String getGroupSearchBase() { protected String getGroupSearchBase() {
return groupSearchBase; return groupSearchBase;
} }

View File

@ -56,6 +56,17 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER")); assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER"));
} }
@Test
public void nullSearchBaseIsAccepted() throws Exception {
populator = new DefaultLdapAuthoritiesPopulator(getContextSource(), "ou=groups");
populator.setDefaultRole("ROLE_USER");
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(
new DirContextAdapter(new DistinguishedName("cn=notfound")), "notfound");
assertEquals(1, authorities.size());
assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER"));
}
@Test @Test
public void groupSearchReturnsExpectedRoles() { public void groupSearchReturnsExpectedRoles() {
populator.setRolePrefix("ROLE_"); populator.setRolePrefix("ROLE_");