SEC-1459: Generifying AuthenticationUserDetailsService. Now parameterized with <? extends Authentication>.
This commit is contained in:
+15
-15
@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
|
||||
public class PreAuthenticatedAuthenticationProvider implements AuthenticationProvider, InitializingBean, Ordered {
|
||||
private static final Log logger = LogFactory.getLog(PreAuthenticatedAuthenticationProvider.class);
|
||||
|
||||
private AuthenticationUserDetailsService preAuthenticatedUserDetailsService = null;
|
||||
private AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken> preAuthenticatedUserDetailsService = null;
|
||||
private UserDetailsChecker userDetailsChecker = new AccountStatusUserDetailsChecker();
|
||||
private boolean throwExceptionWhenTokenRejected = false;
|
||||
|
||||
@@ -77,7 +77,7 @@ public class PreAuthenticatedAuthenticationProvider implements AuthenticationPro
|
||||
return null;
|
||||
}
|
||||
|
||||
UserDetails ud = preAuthenticatedUserDetailsService.loadUserDetails(authentication);
|
||||
UserDetails ud = preAuthenticatedUserDetailsService.loadUserDetails((PreAuthenticatedAuthenticationToken)authentication);
|
||||
|
||||
userDetailsChecker.check(ud);
|
||||
|
||||
@@ -91,25 +91,17 @@ public class PreAuthenticatedAuthenticationProvider implements AuthenticationPro
|
||||
/**
|
||||
* Indicate that this provider only supports PreAuthenticatedAuthenticationToken (sub)classes.
|
||||
*/
|
||||
public boolean supports(Class<? extends Object> authentication) {
|
||||
public final boolean supports(Class<? extends Object> authentication) {
|
||||
return PreAuthenticatedAuthenticationToken.class.isAssignableFrom(authentication);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the AuthenticatedUserDetailsServices to be used.
|
||||
* Set the AuthenticatedUserDetailsService to be used to load the {@code UserDetails} for the authenticated user.
|
||||
*
|
||||
* @param aPreAuthenticatedUserDetailsService
|
||||
* @param uds
|
||||
*/
|
||||
public void setPreAuthenticatedUserDetailsService(AuthenticationUserDetailsService aPreAuthenticatedUserDetailsService) {
|
||||
this.preAuthenticatedUserDetailsService = aPreAuthenticatedUserDetailsService;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(int i) {
|
||||
order = i;
|
||||
public void setPreAuthenticatedUserDetailsService(AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken> uds) {
|
||||
this.preAuthenticatedUserDetailsService = uds;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,4 +122,12 @@ public class PreAuthenticatedAuthenticationProvider implements AuthenticationPro
|
||||
Assert.notNull(userDetailsChecker, "userDetailsChacker cannot be null");
|
||||
this.userDetailsChecker = userDetailsChecker;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(int i) {
|
||||
order = i;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -30,14 +30,15 @@ import org.springframework.util.Assert;
|
||||
* @author Ruud Senden
|
||||
* @since 2.0
|
||||
*/
|
||||
public class PreAuthenticatedGrantedAuthoritiesUserDetailsService implements AuthenticationUserDetailsService {
|
||||
public class PreAuthenticatedGrantedAuthoritiesUserDetailsService
|
||||
implements AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken> {
|
||||
/**
|
||||
* Get a UserDetails object based on the user name contained in the given
|
||||
* token, and the GrantedAuthorities as returned by the
|
||||
* GrantedAuthoritiesContainer implementation as returned by
|
||||
* the token.getDetails() method.
|
||||
*/
|
||||
public final UserDetails loadUserDetails(Authentication token) throws AuthenticationException {
|
||||
public final UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws AuthenticationException {
|
||||
Assert.notNull(token.getDetails());
|
||||
Assert.isInstanceOf(GrantedAuthoritiesContainer.class, token.getDetails());
|
||||
List<GrantedAuthority> authorities = ((GrantedAuthoritiesContainer) token.getDetails()).getGrantedAuthorities();
|
||||
|
||||
+4
-3
@@ -104,9 +104,10 @@ public class PreAuthenticatedAuthenticationProviderTests {
|
||||
return result;
|
||||
}
|
||||
|
||||
private AuthenticationUserDetailsService getPreAuthenticatedUserDetailsService(final UserDetails aUserDetails) {
|
||||
return new AuthenticationUserDetailsService() {
|
||||
public UserDetails loadUserDetails(Authentication token) throws UsernameNotFoundException {
|
||||
private AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken>
|
||||
getPreAuthenticatedUserDetailsService(final UserDetails aUserDetails) {
|
||||
return new AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken>() {
|
||||
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException {
|
||||
if (aUserDetails != null && aUserDetails.getUsername().equals(token.getName())) {
|
||||
return aUserDetails;
|
||||
}
|
||||
|
||||
+1
@@ -31,6 +31,7 @@ public class WebSphere2SpringSecurityPropagationInterceptorTests {
|
||||
}
|
||||
|
||||
/** SEC-1078 */
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void createdAuthenticationTokenIsAcceptableToPreauthProvider () throws Throwable {
|
||||
WASUsernameAndGroupsExtractor helper = mock(WASUsernameAndGroupsExtractor.class);
|
||||
|
||||
Reference in New Issue
Block a user