|
@@ -1,7 +1,6 @@
|
|
package org.springframework.security.ldap.userdetails;
|
|
package org.springframework.security.ldap.userdetails;
|
|
|
|
|
|
-import static org.junit.Assert.assertEquals;
|
|
|
|
-import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
+import static org.junit.Assert.*;
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
@@ -14,8 +13,7 @@ import org.springframework.security.core.GrantedAuthority;
|
|
import org.springframework.security.core.authority.AuthorityUtils;
|
|
import org.springframework.security.core.authority.AuthorityUtils;
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
import org.springframework.security.ldap.authentication.MockUserSearch;
|
|
import org.springframework.security.ldap.authentication.MockUserSearch;
|
|
-import org.springframework.security.ldap.userdetails.LdapUserDetailsMapper;
|
|
|
|
-import org.springframework.security.ldap.userdetails.LdapUserDetailsService;
|
|
|
|
|
|
+import org.springframework.security.ldap.authentication.NullLdapAuthoritiesPopulator;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Tests for {@link LdapUserDetailsService}
|
|
* Tests for {@link LdapUserDetailsService}
|
|
@@ -27,7 +25,7 @@ public class LdapUserDetailsServiceTests {
|
|
|
|
|
|
@Test(expected = IllegalArgumentException.class)
|
|
@Test(expected = IllegalArgumentException.class)
|
|
public void rejectsNullSearchObject() {
|
|
public void rejectsNullSearchObject() {
|
|
- new LdapUserDetailsService(null, new MockAuthoritiesPopulator());
|
|
|
|
|
|
+ new LdapUserDetailsService(null, new NullLdapAuthoritiesPopulator());
|
|
}
|
|
}
|
|
|
|
|
|
@Test(expected = IllegalArgumentException.class)
|
|
@Test(expected = IllegalArgumentException.class)
|
|
@@ -50,6 +48,15 @@ public class LdapUserDetailsServiceTests {
|
|
assertTrue(authorities.contains("ROLE_FROM_POPULATOR"));
|
|
assertTrue(authorities.contains("ROLE_FROM_POPULATOR"));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void nullPopulatorConstructorReturnsEmptyAuthoritiesList() throws Exception {
|
|
|
|
+ DirContextAdapter userData = new DirContextAdapter(new DistinguishedName("uid=joe"));
|
|
|
|
+
|
|
|
|
+ LdapUserDetailsService service = new LdapUserDetailsService(new MockUserSearch(userData));
|
|
|
|
+ UserDetails user = service.loadUserByUsername("doesntmatterwegetjoeanyway");
|
|
|
|
+ assertEquals(0, user.getAuthorities().size());
|
|
|
|
+ }
|
|
|
|
+
|
|
class MockAuthoritiesPopulator implements LdapAuthoritiesPopulator {
|
|
class MockAuthoritiesPopulator implements LdapAuthoritiesPopulator {
|
|
public List<GrantedAuthority> getGrantedAuthorities(DirContextOperations userCtx, String username) {
|
|
public List<GrantedAuthority> getGrantedAuthorities(DirContextOperations userCtx, String username) {
|
|
return AuthorityUtils.createAuthorityList("ROLE_FROM_POPULATOR");
|
|
return AuthorityUtils.createAuthorityList("ROLE_FROM_POPULATOR");
|