This repository was archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
This repository was archived by the owner on Jun 7, 2024. It is now read-only.
Why does overwriting a method( configure(AuthenticationManagerBuilder builder) ) influence a local AuthenticationManager?Not global? #20
Copy link
Copy link
Open
Description
The author hello!
I looked at the documentation on the website, and it says this:
@Configuration
public class ApplicationSecurity extends WebSecurityConfigurerAdapter {
@Autowired
DataSource dataSource;
... // web stuff here
@Override
public void configure(AuthenticationManagerBuilder builder) {
builder.jdbcAuthentication().dataSource(dataSource).withUser("dave")
.password("secret").roles("USER");
}
}
If we had used an @Override of a method in the configurer, the AuthenticationManagerBuilder would be used only to build a “local” AuthenticationManager, which would be a child of the global one. In a Spring Boot application, you can @Autowired the global one into another bean, but you cannot do that with the local one unless you explicitly expose it yourself.
If we rewrote the method (configure) ,WebSecurityConfigurerAdapter`s disableLocalConfigureAuthenticationBldr is not true.
But I was a little confused in the process of using it, and I think the end result is a global one.
configure(AuthenticationManagerBuilder auth) Not rewritten:
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//If we rewrote the method ,it is not true.
this.disableLocalConfigureAuthenticationBldr = true;
}
getHttp():
if (this.http != null) {
return this.http;
} else {
DefaultAuthenticationEventPublisher eventPublisher = (DefaultAuthenticationEventPublisher)this.objectPostProcessor.postProcess(new DefaultAuthenticationEventPublisher());
this.localConfigureAuthenticationBldr.authenticationEventPublisher(eventPublisher);
//fellow authenticationManager()
AuthenticationManager authenticationManager = this.authenticationManager();
// It is parentAuthenticationManager ()
this.authenticationBuilder.parentAuthenticationManager(authenticationManager);
.......
authenticationManager():
protected AuthenticationManager authenticationManager() throws Exception {
if (!this.authenticationManagerInitialized) {
// This is the method that we overwrote(configure)
this.configure(this.localConfigureAuthenticationBldr);
if (this.disableLocalConfigureAuthenticationBldr) {
this.authenticationManager = this.authenticationConfiguration.getAuthenticationManager();
} else {
//disableLocalConfigureAuthenticationBldr is not true
//Overridden methods(configure) are used for the localConfigureAuthenticationBldr
this.authenticationManager = (AuthenticationManager)this.localConfigureAuthenticationBldr.build();
}
this.authenticationManagerInitialized = true;
}
return this.authenticationManager;
}
So I think you end up with a global authenticationManager instead of a local authenticationManager.
Maybe my English is too poor to understand what the author says. I hope you can give me some advice. Thank you~
Metadata
Metadata
Assignees
Labels
No labels