فهرست منبع

added fix to preserve custom UserDetails implementations (Matt DeHoust fix recommendation)

Mark St. Godard 20 سال پیش
والد
کامیت
24394b7b2b

+ 1 - 1
core/src/main/java/org/acegisecurity/ui/switchuser/SwitchUserProcessingFilter.java

@@ -462,7 +462,7 @@ public class SwitchUserProcessingFilter implements Filter, InitializingBean,
         authorities = (GrantedAuthority[]) newAuths.toArray(authorities);
         authorities = (GrantedAuthority[]) newAuths.toArray(authorities);
 
 
         // create the new authentication token
         // create the new authentication token
-        targetUserRequest = new UsernamePasswordAuthenticationToken(username,
+        targetUserRequest = new UsernamePasswordAuthenticationToken(targetUser,
                 targetUser.getPassword(), authorities);
                 targetUser.getPassword(), authorities);
 
 
         // set details
         // set details

+ 2 - 1
core/src/test/java/org/acegisecurity/ui/switchuser/SwitchUserProcessingFilterTests.java

@@ -355,7 +355,8 @@ public class SwitchUserProcessingFilterTests extends TestCase {
         Authentication targetAuth = SecurityContextHolder.getContext()
         Authentication targetAuth = SecurityContextHolder.getContext()
                                                          .getAuthentication();
                                                          .getAuthentication();
         assertNotNull(targetAuth);
         assertNotNull(targetAuth);
-        assertEquals("jacklord", targetAuth.getPrincipal());
+        assertTrue(targetAuth.getPrincipal() instanceof UserDetails);
+        assertEquals("jacklord", ((User)targetAuth.getPrincipal()).getUsername());        
     }
     }
 
 
     private MockHttpServletRequest createMockSwitchRequest() {
     private MockHttpServletRequest createMockSwitchRequest() {