SEC-576: Renamed PreAuthenticateduserDetailsService to AuthenticationUserdetailsService and changed signature accordingly.

This commit is contained in:
Luke Taylor 2008-01-31 14:24:12 +00:00
parent 311add2270
commit 5394350cc8
8 changed files with 27 additions and 24 deletions

View File

@ -2,6 +2,7 @@ package org.springframework.security.providers.preauth;
import org.springframework.security.userdetails.UsernameNotFoundException;
import org.springframework.security.userdetails.UserDetails;
import org.springframework.security.Authentication;
/**
@ -9,18 +10,18 @@ import org.springframework.security.userdetails.UserDetails;
* PreAuthenticatedAuthenticationToken object.
*
* @author Ruud Senden
* @version $Id$
* @since 2.0
*/
public interface PreAuthenticatedUserDetailsService {
public interface AuthenticationUserDetailsService {
/**
*
* @param token
* The pre-authenticated authentication token
* @param token The pre-authenticated authentication token
* @return UserDetails for the given authentication token.
* @throws UsernameNotFoundException
* if no user details can be found for the given authentication
* token
*/
UserDetails getUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException;
UserDetails loadUserDetails(Authentication token) throws UsernameNotFoundException;
}

View File

@ -20,8 +20,7 @@ import org.springframework.util.Assert;
* <p>
* This authentication provider will not perform any checks on authentication
* requests, as they should already be pre- authenticated. However, the
* PreAuthenticatedUserDetailsService implementation may still throw for exampe
* a UsernameNotFoundException.
* AuthenticationUserDetailsService implementation may still throw a UsernameNotFoundException, for example.
*
* @author Ruud Senden
* @version $Id$
@ -30,7 +29,7 @@ import org.springframework.util.Assert;
public class PreAuthenticatedAuthenticationProvider implements AuthenticationProvider, InitializingBean, Ordered {
private static final Log logger = LogFactory.getLog(PreAuthenticatedAuthenticationProvider.class);
private PreAuthenticatedUserDetailsService preAuthenticatedUserDetailsService = null;
private AuthenticationUserDetailsService preAuthenticatedUserDetailsService = null;
private int order = -1; // default: same as non-ordered
@ -38,7 +37,7 @@ public class PreAuthenticatedAuthenticationProvider implements AuthenticationPro
* Check whether all required properties have been set.
*/
public void afterPropertiesSet() {
Assert.notNull(preAuthenticatedUserDetailsService, "A PreAuthenticatedUserDetailsService must be set");
Assert.notNull(preAuthenticatedUserDetailsService, "A AuthenticationUserDetailsService must be set");
}
/**
@ -53,7 +52,7 @@ public class PreAuthenticatedAuthenticationProvider implements AuthenticationPro
logger.debug("PreAuthenticated authentication request: " + authentication);
}
UserDetails ud = preAuthenticatedUserDetailsService.getUserDetails((PreAuthenticatedAuthenticationToken) authentication);
UserDetails ud = preAuthenticatedUserDetailsService.loadUserDetails((PreAuthenticatedAuthenticationToken) authentication);
if (ud == null) {
return null;
@ -79,7 +78,7 @@ public class PreAuthenticatedAuthenticationProvider implements AuthenticationPro
*
* @param aPreAuthenticatedUserDetailsService
*/
public void setPreAuthenticatedUserDetailsService(PreAuthenticatedUserDetailsService aPreAuthenticatedUserDetailsService) {
public void setPreAuthenticatedUserDetailsService(AuthenticationUserDetailsService aPreAuthenticatedUserDetailsService) {
this.preAuthenticatedUserDetailsService = aPreAuthenticatedUserDetailsService;
}

View File

@ -4,12 +4,13 @@ import org.springframework.security.userdetails.UserDetails;
import org.springframework.security.userdetails.User;
import org.springframework.security.GrantedAuthority;
import org.springframework.security.AuthenticationException;
import org.springframework.security.Authentication;
import org.springframework.util.Assert;
/**
* <p>
* This PreAuthenticatedUserDetailsService implementation creates a UserDetails
* This AuthenticationUserDetailsService implementation creates a UserDetails
* object based solely on the information contained in the given
* PreAuthenticatedAuthenticationToken. The user name is set to the name as
* returned by PreAuthenticatedAuthenticationToken.getName(), the password is
@ -27,14 +28,14 @@ import org.springframework.util.Assert;
* @author Ruud Senden
* @since 2.0
*/
public class PreAuthenticatedGrantedAuthoritiesUserDetailsService implements PreAuthenticatedUserDetailsService {
public class PreAuthenticatedGrantedAuthoritiesUserDetailsService implements AuthenticationUserDetailsService {
/**
* Get a UserDetails object based on the user name contained in the given
* token, and the GrantedAuthorities as returned by the
* PreAuthenticatedGrantedAuthoritiesRetriever implementation as returned by
* the token.getDetails() method.
*/
public UserDetails getUserDetails(PreAuthenticatedAuthenticationToken token) throws AuthenticationException {
public UserDetails loadUserDetails(Authentication token) throws AuthenticationException {
Assert.notNull(token.getDetails());
Assert.isInstanceOf(PreAuthenticatedGrantedAuthoritiesRetriever.class, token.getDetails());
GrantedAuthority[] preAuthenticatedGrantedAuthorities = ((PreAuthenticatedGrantedAuthoritiesRetriever) token.getDetails())

View File

@ -3,19 +3,20 @@ package org.springframework.security.providers.preauth;
import org.springframework.security.userdetails.UserDetails;
import org.springframework.security.userdetails.UserDetailsService;
import org.springframework.security.userdetails.UsernameNotFoundException;
import org.springframework.security.Authentication;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessException;
import org.springframework.util.Assert;
/**
* This implementation for PreAuthenticatedUserDetailsService wraps a regular
* This implementation for AuthenticationUserDetailsService wraps a regular
* Spring Security UserDetailsService implementation, to retrieve a UserDetails object
* based on the user name contained in a PreAuthenticatedAuthenticationToken.
*
* @author Ruud Senden
* @since 2.0
*/
public class UserDetailsByNameServiceWrapper implements PreAuthenticatedUserDetailsService, InitializingBean {
public class UserDetailsByNameServiceWrapper implements AuthenticationUserDetailsService, InitializingBean {
private UserDetailsService userDetailsService = null;
/**
@ -31,7 +32,7 @@ public class UserDetailsByNameServiceWrapper implements PreAuthenticatedUserDeta
* Get the UserDetails object from the wrapped UserDetailsService
* implementation
*/
public UserDetails getUserDetails(PreAuthenticatedAuthenticationToken aJ2eeAuthenticationToken) throws UsernameNotFoundException,
public UserDetails loadUserDetails(Authentication aJ2eeAuthenticationToken) throws UsernameNotFoundException,
DataAccessException {
return userDetailsService.loadUserByUsername(aJ2eeAuthenticationToken.getName());
}

View File

@ -87,9 +87,9 @@ public class PreAuthenticatedAuthenticationProviderTests extends TestCase {
return result;
}
private PreAuthenticatedUserDetailsService getPreAuthenticatedUserDetailsService(final UserDetails aUserDetails) {
return new PreAuthenticatedUserDetailsService() {
public UserDetails getUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException {
private AuthenticationUserDetailsService getPreAuthenticatedUserDetailsService(final UserDetails aUserDetails) {
return new AuthenticationUserDetailsService() {
public UserDetails loadUserDetails(Authentication token) throws UsernameNotFoundException {
if (aUserDetails != null && aUserDetails.getUsername().equals(token.getName())) {
return aUserDetails;
} else {

View File

@ -21,7 +21,7 @@ public class PreAuthenticatedGrantedAuthoritiesUserDetailsServiceTests extends T
PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken("dummy", "dummy");
token.setDetails(new Object());
try {
svc.getUserDetails(token);
svc.loadUserDetails(token);
fail("Expected exception didn't occur");
} catch (IllegalArgumentException expected) {
}
@ -32,7 +32,7 @@ public class PreAuthenticatedGrantedAuthoritiesUserDetailsServiceTests extends T
PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken("dummy", "dummy");
token.setDetails(null);
try {
svc.getUserDetails(token);
svc.loadUserDetails(token);
fail("Expected exception didn't occur");
} catch (IllegalArgumentException expected) {
}
@ -58,7 +58,7 @@ public class PreAuthenticatedGrantedAuthoritiesUserDetailsServiceTests extends T
return gas;
}
});
UserDetails ud = svc.getUserDetails(token);
UserDetails ud = svc.loadUserDetails(token);
assertTrue(ud.isAccountNonExpired());
assertTrue(ud.isAccountNonLocked());
assertTrue(ud.isCredentialsNonExpired());

View File

@ -42,9 +42,9 @@ public class UserDetailsByNameServiceWrapperTests extends TestCase {
}
});
svc.afterPropertiesSet();
UserDetails result1 = svc.getUserDetails(new PreAuthenticatedAuthenticationToken("dummy", "dummy"));
UserDetails result1 = svc.loadUserDetails(new PreAuthenticatedAuthenticationToken("dummy", "dummy"));
assertEquals("Result doesn't match original user", user, result1);
UserDetails result2 = svc.getUserDetails(new PreAuthenticatedAuthenticationToken("dummy2", "dummy"));
UserDetails result2 = svc.loadUserDetails(new PreAuthenticatedAuthenticationToken("dummy2", "dummy"));
assertNull("Result should have been null", result2);
}

View File

@ -18,5 +18,6 @@
<module>contacts</module>
<module>tutorial</module>
<module>dms</module>
<module>preauth</module>
</modules>
</project>