Browse Source

Added original Authentication.getDetails() to DaoAuthenticationProvider response.

Ben Alex 21 years ago
parent
commit
04f4c9881d

+ 2 - 0
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)

+ 9 - 3
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) {

+ 2 - 0
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() {