From 53b6735c3e193914606f998497a7ef8eaf6b9a6e Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Sun, 21 May 2006 03:03:50 +0000 Subject: [PATCH] Make sure the username and password are set on the final UserDetails object returned by the provider. --- .../providers/ldap/LdapAuthenticationProvider.java | 12 ++++++++---- .../ldap/LdapAuthenticationProviderTests.java | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/acegisecurity/providers/ldap/LdapAuthenticationProvider.java b/core/src/main/java/org/acegisecurity/providers/ldap/LdapAuthenticationProvider.java index a79a1a0d73..fb3f43529c 100644 --- a/core/src/main/java/org/acegisecurity/providers/ldap/LdapAuthenticationProvider.java +++ b/core/src/main/java/org/acegisecurity/providers/ldap/LdapAuthenticationProvider.java @@ -153,7 +153,7 @@ public class LdapAuthenticationProvider extends AbstractUserDetailsAuthenticatio LdapUserDetails ldapUser = authenticator.authenticate(username, password); - return createUserDetails(ldapUser); + return createUserDetails(ldapUser, username, password); } /** @@ -166,16 +166,20 @@ public class LdapAuthenticationProvider extends AbstractUserDetailsAuthenticatio *

* Can be overridden to customize the creation of the final UserDetails instance. The * default will merge any additional authorities retrieved from the populator with the - * original ldapUser object. + * propertis of original ldapUser object and set the values of the username and password. *

* - * @param ldapUser The intermediate LdapUserDetails instance returned from the authenticator. + * @param ldapUser The intermediate LdapUserDetails instance returned by the authenticator. + * @param username the username submitted to the provider + * @param password the password submitted to the provider * * @return The UserDetails for the successfully authenticated user. */ - protected UserDetails createUserDetails(LdapUserDetails ldapUser) { + protected UserDetails createUserDetails(LdapUserDetails ldapUser, String username, String password) { LdapUserDetailsImpl.Essence user = new LdapUserDetailsImpl.Essence(ldapUser); + user.setUsername(username); + user.setPassword(password); GrantedAuthority[] extraAuthorities = authoritiesPopulator.getGrantedAuthorities(ldapUser); diff --git a/core/src/test/java/org/acegisecurity/providers/ldap/LdapAuthenticationProviderTests.java b/core/src/test/java/org/acegisecurity/providers/ldap/LdapAuthenticationProviderTests.java index 1adee835d1..f9216de46d 100644 --- a/core/src/test/java/org/acegisecurity/providers/ldap/LdapAuthenticationProviderTests.java +++ b/core/src/test/java/org/acegisecurity/providers/ldap/LdapAuthenticationProviderTests.java @@ -37,6 +37,8 @@ public class LdapAuthenticationProviderTests extends AbstractLdapServerTestCase UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("bob","bobspassword"); UserDetails user = ldapProvider.retrieveUser("bob", token); assertEquals(2, user.getAuthorities().length); + assertEquals("bobspassword", user.getPassword()); + assertEquals("bob", user.getUsername()); ArrayList authorities = new ArrayList(); authorities.add(user.getAuthorities()[0].getAuthority()); @@ -101,6 +103,7 @@ public class LdapAuthenticationProviderTests extends AbstractLdapServerTestCase if(username.equals("bob") && password.equals("bobspassword")) { LdapUserDetailsImpl.Essence userEssence = new LdapUserDetailsImpl.Essence(); userEssence.setDn("cn=bob,ou=people,dc=acegisecurity,dc=org"); + userEssence.setPassword("{SHA}anencodedpassword"); userEssence.setAttributes(userAttributes); userEssence.addAuthority(new GrantedAuthorityImpl("ROLE_FROM_ENTRY")); return userEssence.createUserDetails();