Browse Source

SEC-1641: Correct code and test for null groupSearchBase.

pull/1/head
Luke Taylor 15 years ago
parent
commit
dbe270f132
  1. 6
      ldap/src/main/java/org/springframework/security/ldap/userdetails/DefaultLdapAuthoritiesPopulator.java
  2. 2
      ldap/src/test/java/org/springframework/security/ldap/populator/DefaultLdapAuthoritiesPopulatorTests.java

6
ldap/src/main/java/org/springframework/security/ldap/userdetails/DefaultLdapAuthoritiesPopulator.java

@ -146,7 +146,9 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator @@ -146,7 +146,9 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator
ldapTemplate.setSearchControls(searchControls);
this.groupSearchBase = groupSearchBase;
if (groupSearchBase.length() == 0) {
if (groupSearchBase == null) {
logger.info("groupSearchBase is null. No group search will be performed.");
} else if (groupSearchBase.length() == 0) {
logger.info("groupSearchBase is empty. Searches will be performed from the context source base");
}
}
@ -200,7 +202,7 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator @@ -200,7 +202,7 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator
public Set<GrantedAuthority> getGroupMembershipRoles(String userDn, String username) {
if (getGroupSearchBase() == null) {
return Collections.emptySet();
return new HashSet<GrantedAuthority>();
}
Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();

2
ldap/src/test/java/org/springframework/security/ldap/populator/DefaultLdapAuthoritiesPopulatorTests.java

@ -58,7 +58,7 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio @@ -58,7 +58,7 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
@Test
public void nullSearchBaseIsAccepted() throws Exception {
populator = new DefaultLdapAuthoritiesPopulator(getContextSource(), "ou=groups");
populator = new DefaultLdapAuthoritiesPopulator(getContextSource(), null);
populator.setDefaultRole("ROLE_USER");
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(

Loading…
Cancel
Save