I am working on Spring Security Java-based configuration.
I have created my own MyAuthenticationProvider which I want to register in the ProviderManager (single instance of AuthenticationManager).
I have found that ProviderManager has a list of providers to which I can register my single
MyAuthenticationProvider.
Here is the part of my Configuration:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(MyAuthenticationProvider);
}
}
I found out that AuthenticationManagerBuilder has parentAuthenticationManager, defaultUserDetailsService and many other fields.
My questions are:
- Where is this
@Autowiredannotation addingAuthenticationManagerBuilderauth from? Is theAuthenticationManagerBuilderalready created in the application context? - What would be the default state of
AuthenticationManagerBuilderwhich is being injected? By default state I mean will there be someparentAuthenticationManager,authenticationProviders already registered in theAuthenticationManagerBuilder? - If I am adding
auth.authenticationProvider(MyAuthenticationProvider), does this mean that I am adding one more provider in theAuthenticationManagerBuilder? What does this mean? Taken from Spring Documentation
The name of the configureGlobal method is not important. However, it is important to only configure AuthenticationManagerBuilder in a class annotated with either @EnableWebSecurity, @EnableWebMvcSecurity, @EnableGlobalMethodSecurity, or @EnableGlobalAuthentication. Doing otherwise has unpredictable results.