Class ProviderManager
- java.lang.Object
- 
- org.springframework.security.authentication.ProviderManager
 
- 
- All Implemented Interfaces:
- org.springframework.beans.factory.Aware,- org.springframework.beans.factory.InitializingBean,- org.springframework.context.MessageSourceAware,- AuthenticationManager
 
 public class ProviderManager extends java.lang.Object implements AuthenticationManager, org.springframework.context.MessageSourceAware, org.springframework.beans.factory.InitializingBean Iterates anAuthenticationrequest through a list ofAuthenticationProviders.AuthenticationProviders are usually tried in order until one provides a non-null response. A non-null response indicates the provider had authority to decide on the authentication request and no further providers are tried. If a subsequent provider successfully authenticates the request, the earlier authentication exception is disregarded and the successful authentication will be used. If no subsequent provider provides a non-null response, or a new AuthenticationException, the lastAuthenticationExceptionreceived will be used. If no provider returns a non-null response, or indicates it can even process anAuthentication, theProviderManagerwill throw aProviderNotFoundException. A parentAuthenticationManagercan also be set, and this will also be tried if none of the configured providers can perform the authentication. This is intended to support namespace configuration options though and is not a feature that should normally be required.The exception to this process is when a provider throws an AccountStatusException, in which case no further providers in the list will be queried. Post-authentication, the credentials will be cleared from the returnedAuthenticationobject, if it implements theCredentialsContainerinterface. This behaviour can be controlled by modifying theeraseCredentialsAfterAuthenticationproperty.Event PublishingAuthentication event publishing is delegated to the configured AuthenticationEventPublisherwhich defaults to a null implementation which doesn't publish events, so if you are configuring the bean yourself you must inject a publisher bean if you want to receive events. The standard implementation isDefaultAuthenticationEventPublisherwhich maps common exceptions to events (in the case of authentication failure) and publishes anAuthenticationSuccessEventif authentication succeeds. If you are using the namespace then an instance of this bean will be used automatically by the <http> configuration, so you will receive events from the web part of your application automatically.Note that the implementation also publishes authentication failure events when it obtains an authentication result (or an exception) from the "parent" AuthenticationManagerif one has been set. So in this situation, the parent should not generally be configured to publish events or there will be duplicates.- See Also:
- DefaultAuthenticationEventPublisher
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected org.springframework.context.support.MessageSourceAccessormessages
 - 
Constructor SummaryConstructors Constructor Description ProviderManager(java.util.List<AuthenticationProvider> providers)Construct aProviderManagerusing the givenAuthenticationProvidersProviderManager(java.util.List<AuthenticationProvider> providers, AuthenticationManager parent)Construct aProviderManagerusing the provided parametersProviderManager(AuthenticationProvider... providers)Construct aProviderManagerusing the givenAuthenticationProviders
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Authenticationauthenticate(Authentication authentication)Attempts to authenticate the passedAuthenticationobject.java.util.List<AuthenticationProvider>getProviders()booleanisEraseCredentialsAfterAuthentication()voidsetAuthenticationEventPublisher(AuthenticationEventPublisher eventPublisher)voidsetEraseCredentialsAfterAuthentication(boolean eraseSecretData)If set to, a resultingAuthenticationwhich implements theCredentialsContainerinterface will have itseraseCredentialsmethod called before it is returned from theauthenticate()method.voidsetMessageSource(org.springframework.context.MessageSource messageSource)
 
- 
- 
- 
Constructor Detail- 
ProviderManagerpublic ProviderManager(AuthenticationProvider... providers) Construct aProviderManagerusing the givenAuthenticationProviders- Parameters:
- providers- the- AuthenticationProviders to use
 
 - 
ProviderManagerpublic ProviderManager(java.util.List<AuthenticationProvider> providers) Construct aProviderManagerusing the givenAuthenticationProviders- Parameters:
- providers- the- AuthenticationProviders to use
 
 - 
ProviderManagerpublic ProviderManager(java.util.List<AuthenticationProvider> providers, AuthenticationManager parent) Construct aProviderManagerusing the provided parameters- Parameters:
- providers- the- AuthenticationProviders to use
- parent- a parent- AuthenticationManagerto fall back to
 
 
- 
 - 
Method Detail- 
afterPropertiesSetpublic void afterPropertiesSet() - Specified by:
- afterPropertiesSetin interface- org.springframework.beans.factory.InitializingBean
 
 - 
authenticatepublic Authentication authenticate(Authentication authentication) throws AuthenticationException Attempts to authenticate the passedAuthenticationobject.The list of AuthenticationProviders will be successively tried until anAuthenticationProviderindicates it is capable of authenticating the type ofAuthenticationobject passed. Authentication will then be attempted with thatAuthenticationProvider.If more than one AuthenticationProvidersupports the passedAuthenticationobject, the first one able to successfully authenticate theAuthenticationobject determines theresult, overriding any possibleAuthenticationExceptionthrown by earlier supportingAuthenticationProviders. On successful authentication, no subsequentAuthenticationProviders will be tried. If authentication was not successful by any supportingAuthenticationProviderthe last thrownAuthenticationExceptionwill be rethrown.- Specified by:
- authenticatein interface- AuthenticationManager
- Parameters:
- authentication- the authentication request object.
- Returns:
- a fully authenticated object including credentials.
- Throws:
- AuthenticationException- if authentication fails.
 
 - 
getProviderspublic java.util.List<AuthenticationProvider> getProviders() 
 - 
setMessageSourcepublic void setMessageSource(org.springframework.context.MessageSource messageSource) - Specified by:
- setMessageSourcein interface- org.springframework.context.MessageSourceAware
 
 - 
setAuthenticationEventPublisherpublic void setAuthenticationEventPublisher(AuthenticationEventPublisher eventPublisher) 
 - 
setEraseCredentialsAfterAuthenticationpublic void setEraseCredentialsAfterAuthentication(boolean eraseSecretData) If set to, a resultingAuthenticationwhich implements theCredentialsContainerinterface will have itseraseCredentialsmethod called before it is returned from theauthenticate()method.- Parameters:
- eraseSecretData- set to false to retain the credentials data in memory. Defaults to true.
 
 - 
isEraseCredentialsAfterAuthenticationpublic boolean isEraseCredentialsAfterAuthentication() 
 
- 
 
-