From 04f4c9881dd9efa7eccbc9b5b08023823b2b22a5 Mon Sep 17 00:00:00 2001 From: Ben Alex Date: Fri, 13 Aug 2004 01:07:32 +0000 Subject: [PATCH] Added original Authentication.getDetails() to DaoAuthenticationProvider response. --- changelog.txt | 2 ++ .../providers/dao/DaoAuthenticationProvider.java | 12 +++++++++--- .../dao/DaoAuthenticationProviderTests.java | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/changelog.txt b/changelog.txt index 6d28905932..afc767d285 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,8 @@ Changes in version 0.x (2004-xx-xx) ----------------------------------- +* Added additional DaoAuthenticationProvider event when user not found +* Added Authentication.getDetails() to DaoAuthenticationProvider response * Fixed EH-CACHE-based caching implementation behaviour when cache exists Changes in version 0.6 (2004-08-09) diff --git a/core/src/main/java/org/acegisecurity/providers/dao/DaoAuthenticationProvider.java b/core/src/main/java/org/acegisecurity/providers/dao/DaoAuthenticationProvider.java index 546be6389d..0638fc3514 100644 --- a/core/src/main/java/org/acegisecurity/providers/dao/DaoAuthenticationProvider.java +++ b/core/src/main/java/org/acegisecurity/providers/dao/DaoAuthenticationProvider.java @@ -320,9 +320,15 @@ public class DaoAuthenticationProvider implements AuthenticationProvider, protected Authentication createSuccessAuthentication(Object principal, Authentication authentication, UserDetails user) { // Ensure we return the original credentials the user supplied, - // so subsequent attempts are successful even with encoded passwords - return new UsernamePasswordAuthenticationToken(principal, - authentication.getCredentials(), user.getAuthorities()); + // so subsequent attempts are successful even with encoded passwords. + // Also ensure we return the original getDetails(), so that future + // authentication events after cache expiry contain the details + UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(principal, + authentication.getCredentials(), user.getAuthorities()); + result.setDetails((authentication.getDetails() != null) + ? authentication.getDetails().toString() : null); + + return result; } private UserDetails getUserFromBackend(String username) { diff --git a/core/src/test/java/org/acegisecurity/providers/dao/DaoAuthenticationProviderTests.java b/core/src/test/java/org/acegisecurity/providers/dao/DaoAuthenticationProviderTests.java index b76e737b04..acba3cc7b8 100644 --- a/core/src/test/java/org/acegisecurity/providers/dao/DaoAuthenticationProviderTests.java +++ b/core/src/test/java/org/acegisecurity/providers/dao/DaoAuthenticationProviderTests.java @@ -154,6 +154,7 @@ public class DaoAuthenticationProviderTests extends TestCase { public void testAuthenticates() { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("marissa", "koala"); + token.setDetails("192.168.0.1"); DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); provider.setAuthenticationDao(new MockAuthenticationDaoUserMarissa()); @@ -171,6 +172,7 @@ public class DaoAuthenticationProviderTests extends TestCase { assertEquals("koala", castResult.getCredentials()); assertEquals("ROLE_ONE", castResult.getAuthorities()[0].getAuthority()); assertEquals("ROLE_TWO", castResult.getAuthorities()[1].getAuthority()); + assertEquals("192.168.0.1", castResult.getDetails()); } public void testAuthenticatesASecondTime() {