SEC-427: Fix. Added NullAuthoritiesPopulator and extra constructor.

This commit is contained in:
Luke Taylor
2007-08-30 21:12:16 +00:00
parent 301626fd6e
commit 0c4916ee98
2 changed files with 32 additions and 5 deletions

View File

@@ -47,7 +47,6 @@ public class LdapAuthenticationProviderTests extends TestCase {
}
public LdapAuthenticationProviderTests() {
super();
}
//~ Methods ========================================================================================================
@@ -86,8 +85,7 @@ public class LdapAuthenticationProviderTests extends TestCase {
}
public void testEmptyPasswordIsRejected() {
LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(new MockAuthenticator(),
new MockAuthoritiesPopulator());
LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(new MockAuthenticator());
try {
ldapProvider.retrieveUser("jen", new UsernamePasswordAuthenticationToken("jen", ""));
fail("Expected BadCredentialsException for empty password");
@@ -116,6 +114,14 @@ public class LdapAuthenticationProviderTests extends TestCase {
ldapProvider.additionalAuthenticationChecks(user, authRequest);
}
public void testUseWithNullAuthoritiesPopulatorReturnsCorrectRole() {
LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(new MockAuthenticator());
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken("bob", "bobspassword");
UserDetails user = ldapProvider.retrieveUser("bob", authRequest);
assertEquals(1, user.getAuthorities().length);
assertEquals("ROLE_FROM_ENTRY", user.getAuthorities()[0].getAuthority());
}
//~ Inner Classes ==================================================================================================
class MockAuthenticator implements LdapAuthenticator {