public class AuthenticationManagerBuilder extends AbstractConfiguredSecurityBuilder<org.springframework.security.authentication.AuthenticationManager,AuthenticationManagerBuilder> implements ProviderManagerBuilder<AuthenticationManagerBuilder>
SecurityBuilder used to create an AuthenticationManager. Allows for
easily building in memory authentication, LDAP authentication, JDBC based
authentication, adding UserDetailsService, and adding
AuthenticationProvider's.| Constructor and Description |
|---|
AuthenticationManagerBuilder(ObjectPostProcessor<Object> objectPostProcessor)
Creates a new instance
|
| Modifier and Type | Method and Description |
|---|---|
AuthenticationManagerBuilder |
authenticationEventPublisher(org.springframework.security.authentication.AuthenticationEventPublisher eventPublisher)
Sets the
AuthenticationEventPublisher |
AuthenticationManagerBuilder |
authenticationProvider(org.springframework.security.authentication.AuthenticationProvider authenticationProvider)
Add authentication based upon the custom
AuthenticationProvider that is
passed in. |
AuthenticationManagerBuilder |
eraseCredentials(boolean eraseCredentials) |
org.springframework.security.core.userdetails.UserDetailsService |
getDefaultUserDetailsService()
Gets the default
UserDetailsService for the
AuthenticationManagerBuilder. |
InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder> |
inMemoryAuthentication()
Add in memory authentication to the
AuthenticationManagerBuilder and return
a InMemoryUserDetailsManagerConfigurer to allow customization of the in
memory authentication. |
boolean |
isConfigured()
Determines if the
AuthenticationManagerBuilder is configured to build a non
null AuthenticationManager. |
JdbcUserDetailsManagerConfigurer<AuthenticationManagerBuilder> |
jdbcAuthentication()
Add JDBC authentication to the
AuthenticationManagerBuilder and return a
JdbcUserDetailsManagerConfigurer to allow customization of the JDBC
authentication. |
LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> |
ldapAuthentication()
Add LDAP authentication to the
AuthenticationManagerBuilder and return a
LdapAuthenticationProviderConfigurer to allow customization of the LDAP
authentication. |
AuthenticationManagerBuilder |
parentAuthenticationManager(org.springframework.security.authentication.AuthenticationManager authenticationManager)
Allows providing a parent
AuthenticationManager that will be tried if this
AuthenticationManager was unable to attempt to authenticate the provided
Authentication. |
protected org.springframework.security.authentication.ProviderManager |
performBuild()
Subclasses must implement this method to build the object that is being returned.
|
<T extends org.springframework.security.core.userdetails.UserDetailsService> |
userDetailsService(T userDetailsService)
Add authentication based upon the custom
UserDetailsService that is passed
in. |
apply, apply, beforeConfigure, beforeInit, doBuild, getConfigurer, getConfigurers, getOrBuild, getSharedObject, getSharedObjects, objectPostProcessor, postProcess, removeConfigurer, removeConfigurers, setSharedObjectbuild, getObjectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuildpublic AuthenticationManagerBuilder(ObjectPostProcessor<Object> objectPostProcessor)
objectPostProcessor - the ObjectPostProcessor instance to use.public AuthenticationManagerBuilder parentAuthenticationManager(org.springframework.security.authentication.AuthenticationManager authenticationManager)
AuthenticationManager that will be tried if this
AuthenticationManager was unable to attempt to authenticate the provided
Authentication.authenticationManager - the AuthenticationManager that should be used
if the current AuthenticationManager was unable to attempt to authenticate
the provided Authentication.AuthenticationManagerBuilder for further adding types of
authenticationpublic AuthenticationManagerBuilder authenticationEventPublisher(org.springframework.security.authentication.AuthenticationEventPublisher eventPublisher)
AuthenticationEventPublishereventPublisher - the AuthenticationEventPublisher to useAuthenticationManagerBuilder for further customizationspublic AuthenticationManagerBuilder eraseCredentials(boolean eraseCredentials)
eraseCredentials - true if AuthenticationManager should clear the
credentials from the Authentication object after authenticatingAuthenticationManagerBuilder for further customizationspublic InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder> inMemoryAuthentication() throws Exception
AuthenticationManagerBuilder and return
a InMemoryUserDetailsManagerConfigurer to allow customization of the in
memory authentication.
This method also ensure that a UserDetailsService is available for the
getDefaultUserDetailsService() method. Note that additional
UserDetailsService's may override this UserDetailsService as the
default.
InMemoryUserDetailsManagerConfigurer to allow customization of
the in memory authenticationException - if an error occurs when adding the in memory authenticationpublic JdbcUserDetailsManagerConfigurer<AuthenticationManagerBuilder> jdbcAuthentication() throws Exception
AuthenticationManagerBuilder and return a
JdbcUserDetailsManagerConfigurer to allow customization of the JDBC
authentication.
When using with a persistent data store, it is best to add users external of configuration using something like Flyway or Liquibase to create the schema and adding users to ensure these steps are only done once and that the optimal SQL is used.
This method also ensure that a UserDetailsService is available for the
getDefaultUserDetailsService() method. Note that additional
UserDetailsService's may override this UserDetailsService as the
default. See the User Schema section of the reference for the default schema.
JdbcUserDetailsManagerConfigurer to allow customization of the
JDBC authenticationException - if an error occurs when adding the JDBC authenticationpublic <T extends org.springframework.security.core.userdetails.UserDetailsService> DaoAuthenticationConfigurer<AuthenticationManagerBuilder,T> userDetailsService(T userDetailsService) throws Exception
UserDetailsService that is passed
in. It then returns a DaoAuthenticationConfigurer to allow customization of
the authentication.
This method also ensure that the UserDetailsService is available for the
getDefaultUserDetailsService() method. Note that additional
UserDetailsService's may override this UserDetailsService as the
default.
DaoAuthenticationConfigurer to allow customization of the DAO
authenticationException - if an error occurs when adding the UserDetailsService
based authenticationpublic LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapAuthentication() throws Exception
AuthenticationManagerBuilder and return a
LdapAuthenticationProviderConfigurer to allow customization of the LDAP
authentication.
This method does NOT ensure that a UserDetailsService is available
for the getDefaultUserDetailsService() method.
LdapAuthenticationProviderConfigurer to allow customization of
the LDAP authenticationException - if an error occurs when adding the LDAP authenticationpublic AuthenticationManagerBuilder authenticationProvider(org.springframework.security.authentication.AuthenticationProvider authenticationProvider)
AuthenticationProvider that is
passed in. Since the AuthenticationProvider implementation is unknown, all
customizations must be done externally and the AuthenticationManagerBuilder
is returned immediately.
This method does NOT ensure that the UserDetailsService is available
for the getDefaultUserDetailsService() method.
Note that an Exception might be thrown if an error occurs when adding the AuthenticationProvider.
authenticationProvider in interface ProviderManagerBuilder<AuthenticationManagerBuilder>AuthenticationManagerBuilder to allow further authentication to
be provided to the AuthenticationManagerBuilderprotected org.springframework.security.authentication.ProviderManager performBuild()
throws Exception
AbstractConfiguredSecurityBuilderperformBuild in class AbstractConfiguredSecurityBuilder<org.springframework.security.authentication.AuthenticationManager,AuthenticationManagerBuilder>Exceptionpublic boolean isConfigured()
AuthenticationManagerBuilder is configured to build a non
null AuthenticationManager. This means that either a non-null parent is
specified or at least one AuthenticationProvider has been specified.
When using SecurityConfigurer instances, the
AuthenticationManagerBuilder will not be configured until the
SecurityConfigurer.configure(SecurityBuilder) methods. This means a
SecurityConfigurer that is last could check this method and provide a
default configuration in the SecurityConfigurer.configure(SecurityBuilder)
method.
public org.springframework.security.core.userdetails.UserDetailsService getDefaultUserDetailsService()
UserDetailsService for the
AuthenticationManagerBuilder. The result may be null in some circumstances.UserDetailsService for the
AuthenticationManagerBuilder