public abstract class AbstractUserInDirectoryAuthenticationProvider extends Object implements org.springframework.security.authentication.AuthenticationProvider, org.springframework.beans.factory.InitializingBean, org.springframework.context.MessageSourceAware
org.springframework.security.authentication.dao.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.UserDirectoryAuthenticationProvider| Modifier and Type | Field and Description |
|---|---|
protected org.apache.commons.logging.Log |
LOG |
protected org.springframework.context.support.MessageSourceAccessor |
messages |
protected UserDirectory |
userDirectory |
| Constructor and Description |
|---|
AbstractUserInDirectoryAuthenticationProvider() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
additionalAuthenticationChecks(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)
UserDetails
for a given authentication request. |
void |
afterPropertiesSet() |
org.springframework.security.core.Authentication |
authenticate(org.springframework.security.core.Authentication authentication) |
protected abstract org.springframework.security.core.userdetails.UserDetails |
buildUserDetails(User user,
org.springframework.security.authentication.UsernamePasswordAuthenticationToken authentication)
Allows subclasses to build the
UserDetails for a given User. |
protected org.springframework.security.core.Authentication |
createSuccessAuthentication(Object principal,
org.springframework.security.core.Authentication authentication,
org.springframework.security.core.userdetails.UserDetails user)
Creates a successful
Authentication object. |
protected void |
doAfterPropertiesSet() |
protected User |
retrieveUser(String username)
Retrieve the user instance from the user directory.
|
void |
setAuthoritiesMapper(org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper authoritiesMapper) |
void |
setForcePrincipalAsString(boolean forcePrincipalAsString) |
void |
setMessageSource(org.springframework.context.MessageSource messageSource) |
void |
setPostAuthenticationChecks(org.springframework.security.core.userdetails.UserDetailsChecker postAuthenticationChecks) |
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.
|
void |
setThrowExceptionIfUserNotFound(boolean throwExceptionIfUserNotFound) |
void |
setUserCache(org.springframework.security.core.userdetails.UserCache userCache) |
void |
setUserDirectory(UserDirectory userDirectory) |
void |
setUserService(UserService userService) |
boolean |
supports(Class<?> authentication) |
protected final org.apache.commons.logging.Log LOG
protected org.springframework.context.support.MessageSourceAccessor messages
protected UserDirectory userDirectory
public AbstractUserInDirectoryAuthenticationProvider()
public void setMessageSource(org.springframework.context.MessageSource messageSource)
setMessageSource in interface org.springframework.context.MessageSourceAwarepublic void setUserDirectory(UserDirectory userDirectory)
public void setUserService(UserService userService)
public void setUserCache(org.springframework.security.core.userdetails.UserCache userCache)
public void setForcePrincipalAsString(boolean forcePrincipalAsString)
public void setPreAuthenticationChecks(org.springframework.security.core.userdetails.UserDetailsChecker preAuthenticationChecks)
preAuthenticationChecks - strategy to be invoked prior to authentication.public void setPostAuthenticationChecks(org.springframework.security.core.userdetails.UserDetailsChecker postAuthenticationChecks)
public void setAuthoritiesMapper(org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper authoritiesMapper)
public void setThrowExceptionIfUserNotFound(boolean throwExceptionIfUserNotFound)
protected abstract void additionalAuthenticationChecks(org.springframework.security.core.userdetails.UserDetails userDetails,
org.springframework.security.authentication.UsernamePasswordAuthenticationToken authentication)
throws org.springframework.security.core.AuthenticationException
UserDetails
for a given authentication request. Generally a subclass will at least compare the Authentication.getCredentials() with a UserDetails.getPassword(). If custom logic is needed to compare
additional properties of UserDetails and/or UsernamePasswordAuthenticationToken,
these should also appear in this method.userDetails - as retrieved from the buildUserDetails(User, UsernamePasswordAuthenticationToken) or
UserCacheauthentication - the current request that needs to be authenticatedorg.springframework.security.core.AuthenticationException - AuthenticationException if the credentials could not be validated (generally a
BadCredentialsException, an AuthenticationServiceException)public final void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanExceptionpublic org.springframework.security.core.Authentication authenticate(org.springframework.security.core.Authentication authentication)
throws org.springframework.security.core.AuthenticationException
authenticate in interface org.springframework.security.authentication.AuthenticationProviderorg.springframework.security.core.AuthenticationExceptionprotected org.springframework.security.core.Authentication createSuccessAuthentication(Object principal, org.springframework.security.core.Authentication authentication, org.springframework.security.core.userdetails.UserDetails user)
Authentication object.Protected so subclasses can override.
Subclasses will usually store the original credentials the user supplied (not salted or encoded
passwords) in the returned Authentication object.
principal - that should be the principal in the returned objectauthentication - that was presented to the provider for validationuser - that was loaded by the implementationprotected abstract org.springframework.security.core.userdetails.UserDetails buildUserDetails(User user, org.springframework.security.authentication.UsernamePasswordAuthenticationToken authentication) throws org.springframework.security.core.AuthenticationException
UserDetails for a given User.
Actual credential validation can be performed and an AuthenticationException thrown if
validation fails. In case the method returns null this will end in a null
Authentication being returned by this provider.
Note that User already implements UserDetails. If validation is successful, that same
user instance can be returned by the method implementation.user - The user found with the username from the authenticationauthentication - The authentication request, which subclasses may need to perform a binding-based
retrieval of the UserDetailsnull to fall back to being "unable to authenticate"org.springframework.security.core.AuthenticationException - if the credentials could not be validatedprotected User retrieveUser(String username) throws org.springframework.security.core.AuthenticationException
username - The username to retrievenull if not foundorg.springframework.security.core.AuthenticationException - if no user found and throwExceptionIfUserNotFound is truepublic boolean supports(Class<?> authentication)
supports in interface org.springframework.security.authentication.AuthenticationProviderCopyright © 2020. All rights reserved.