Class AbstractUserInDirectoryAuthenticationProvider
java.lang.Object
com.foreach.across.modules.user.security.AbstractUserInDirectoryAuthenticationProvider
- All Implemented Interfaces:
 org.springframework.beans.factory.Aware,org.springframework.beans.factory.InitializingBean,org.springframework.context.MessageSourceAware,org.springframework.security.authentication.AuthenticationProvider
- Direct Known Subclasses:
 InternalUserDirectoryAuthenticationProvider
public abstract class AbstractUserInDirectoryAuthenticationProvider
extends Object
implements org.springframework.security.authentication.AuthenticationProvider, org.springframework.beans.factory.InitializingBean, org.springframework.context.MessageSourceAware
Alternative for 
AbstractUserDetailsAuthenticationProvider
 that fetches a User by username from a single UserDirectory.  It also allows disabling of
 exception throwing if user is not found, making it useful for iterating over multiple providers.- Since:
 - 2.0.0
 - Author:
 - Arne Vandamme
 - See Also:
 
- 
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.commons.logging.Logprotected org.springframework.context.support.MessageSourceAccessorprotected UserDirectory - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidadditionalAuthenticationChecks(org.springframework.security.core.userdetails.UserDetails userDetails, org.springframework.security.authentication.UsernamePasswordAuthenticationToken authentication) Allows subclasses to perform any additional checks of a returned (or cached)UserDetailsfor a given authentication request.final voidorg.springframework.security.core.Authenticationauthenticate(org.springframework.security.core.Authentication authentication) protected abstract org.springframework.security.core.userdetails.UserDetailsbuildUserDetails(User user, org.springframework.security.authentication.UsernamePasswordAuthenticationToken authentication) Allows subclasses to build theUserDetailsfor a givenUser.protected org.springframework.security.core.AuthenticationcreateSuccessAuthentication(Object principal, org.springframework.security.core.Authentication authentication, org.springframework.security.core.userdetails.UserDetails user) Creates a successfulAuthenticationobject.protected voidprotected UserretrieveUser(String username) Retrieve the user instance from the user directory.voidsetAuthoritiesMapper(org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper authoritiesMapper) voidsetForcePrincipalAsString(boolean forcePrincipalAsString) voidsetMessageSource(org.springframework.context.MessageSource messageSource) voidsetPostAuthenticationChecks(org.springframework.security.core.userdetails.UserDetailsChecker postAuthenticationChecks) voidsetPreAuthenticationChecks(org.springframework.security.core.userdetails.UserDetailsChecker preAuthenticationChecks) Sets the policy will be used to verify the status of the loaded UserDetails before validation of the credentials takes place.voidsetThrowExceptionIfUserNotFound(boolean throwExceptionIfUserNotFound) voidsetUserCache(org.springframework.security.core.userdetails.UserCache userCache) voidsetUserDirectory(UserDirectory userDirectory) voidsetUserService(UserService userService) boolean 
- 
Field Details
- 
LOG
protected final org.apache.commons.logging.Log LOG - 
messages
protected org.springframework.context.support.MessageSourceAccessor messages - 
userDirectory
 
 - 
 - 
Constructor Details
- 
AbstractUserInDirectoryAuthenticationProvider
public AbstractUserInDirectoryAuthenticationProvider() 
 - 
 - 
Method Details
- 
setMessageSource
public void setMessageSource(org.springframework.context.MessageSource messageSource) - Specified by:
 setMessageSourcein interfaceorg.springframework.context.MessageSourceAware
 - 
setUserDirectory
 - 
setUserService
 - 
setUserCache
public void setUserCache(org.springframework.security.core.userdetails.UserCache userCache)  - 
setForcePrincipalAsString
public void setForcePrincipalAsString(boolean forcePrincipalAsString)  - 
setPreAuthenticationChecks
public void setPreAuthenticationChecks(org.springframework.security.core.userdetails.UserDetailsChecker preAuthenticationChecks) Sets the policy will be used to verify the status of the loaded UserDetails before validation of the credentials takes place.- Parameters:
 preAuthenticationChecks- strategy to be invoked prior to authentication.
 - 
setPostAuthenticationChecks
public void setPostAuthenticationChecks(org.springframework.security.core.userdetails.UserDetailsChecker postAuthenticationChecks)  - 
setAuthoritiesMapper
public void setAuthoritiesMapper(org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper authoritiesMapper)  - 
setThrowExceptionIfUserNotFound
public void setThrowExceptionIfUserNotFound(boolean throwExceptionIfUserNotFound)  - 
additionalAuthenticationChecks
protected abstract void additionalAuthenticationChecks(org.springframework.security.core.userdetails.UserDetails userDetails, org.springframework.security.authentication.UsernamePasswordAuthenticationToken authentication) throws org.springframework.security.core.AuthenticationException Allows subclasses to perform any additional checks of a returned (or cached)UserDetailsfor a given authentication request. Generally a subclass will at least compare theAuthentication.getCredentials()with aUserDetails.getPassword(). If custom logic is needed to compare additional properties ofUserDetailsand/orUsernamePasswordAuthenticationToken, these should also appear in this method.- Parameters:
 userDetails- as retrieved from thebuildUserDetails(User, UsernamePasswordAuthenticationToken)orUserCacheauthentication- the current request that needs to be authenticated- Throws:
 org.springframework.security.core.AuthenticationException- AuthenticationException if the credentials could not be validated (generally aBadCredentialsException, anAuthenticationServiceException)
 - 
afterPropertiesSet
- Specified by:
 afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
 Exception
 - 
authenticate
public org.springframework.security.core.Authentication authenticate(org.springframework.security.core.Authentication authentication) throws org.springframework.security.core.AuthenticationException - Specified by:
 authenticatein interfaceorg.springframework.security.authentication.AuthenticationProvider- Throws:
 org.springframework.security.core.AuthenticationException
 - 
createSuccessAuthentication
protected org.springframework.security.core.Authentication createSuccessAuthentication(Object principal, org.springframework.security.core.Authentication authentication, org.springframework.security.core.userdetails.UserDetails user) Creates a successfulAuthenticationobject.Protected so subclasses can override.
Subclasses will usually store the original credentials the user supplied (not salted or encoded passwords) in the returned
Authenticationobject.- Parameters:
 principal- that should be the principal in the returned objectauthentication- that was presented to the provider for validationuser- that was loaded by the implementation- Returns:
 - the successful authentication token
 
 - 
doAfterPropertiesSet
- Throws:
 Exception
 - 
buildUserDetails
protected abstract org.springframework.security.core.userdetails.UserDetails buildUserDetails(User user, org.springframework.security.authentication.UsernamePasswordAuthenticationToken authentication) throws org.springframework.security.core.AuthenticationException Allows subclasses to build theUserDetailsfor a givenUser. Actual credential validation can be performed and anAuthenticationExceptionthrown if validation fails. In case the method returnsnullthis will end in anullAuthenticationbeing returned by this provider. Note thatUseralready implementsUserDetails. If validation is successful, that same user instance can be returned by the method implementation.- Parameters:
 user- The user found with the username from the authenticationauthentication- The authentication request, which subclasses may need to perform a binding-based retrieval of theUserDetails- Returns:
 - the user information, can be 
nullto fall back to being "unable to authenticate" - Throws:
 org.springframework.security.core.AuthenticationException- if the credentials could not be validated
 - 
retrieveUser
protected User retrieveUser(String username) throws org.springframework.security.core.AuthenticationException Retrieve the user instance from the user directory.- Parameters:
 username- The username to retrieve- Returns:
 - user instance or 
nullif not found - Throws:
 org.springframework.security.core.AuthenticationException- if no user found andthrowExceptionIfUserNotFoundistrue
 - 
supports
- Specified by:
 supportsin interfaceorg.springframework.security.authentication.AuthenticationProvider
 
 -