-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DaoAuthenticationProvider is autoconfigured when more than one AuthenticationProvider is registered #10005
Comments
Any progress on this? |
Issue is still present in latest version 5.6.1 |
Thanks for reaching out @gbaso. The class that initializes the authentication based on the
To register multiple For example: @Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.httpBasic(basic -> {})
.authorizeRequests(authorize -> authorize.anyRequest().authenticated())
.authenticationProvider(new FirstProvider())
.authenticationProvider(new SecondProvider())
.build();
} Feel free to give this a try and let us know if you have any trouble. |
Thanks @eleftherias, your suggested approach works fine. However, it still feels weird to me that The autoconfiguration for What do you think? |
I still have been facing the same issue with 5.7.3 version. I am implementing multiple securityfilterchain with different authentication provider. Do we have any update on this? |
Also on new 6.x versions, the behavbiour is the same. I did some debug and I found that how HttpSecurity bean is firstly initialized on HttpSecurityConfiguration . The proccess is starting here where the If you take a look closer here, there is a lit of 3 These 3 objects of type
Since we have the situation where we have more than one AuthenticationProvider bean or none beans of this type, then It seems that even if you register Java objects with
we are receiving on filter the The solution for me is the following:
|
Describe the bug
By default, the
AuthenticationManagerBuilder
is autoconfigured with anAuthenticationProvider
, if registered, or with aDaoAuthenticationProvider
, if anUserDetailsService
is registered. Both configurer back off if theAuthenticationManagerBuilder
is already configured, i.e. if at least oneAuthenticationProvider
has been specified.In particular, if a user registers their own
AuthenticationProvider
bean, it is added to the manager's providers list byInitializeAuthenticationProviderManagerConfigurer
, andInitializeUserDetailsManagerConfigurer
does nothing since it consider the manager already configured.However,
InitializeAuthenticationProviderManagerConfigurer
only add the provider if there's just a single registered one. If multiple beans are registered, the configurer does nothing, but because the manager's providers list is still emptyInitializeUserDetailsManagerConfigurer
thinks that the manager was not yet configured, and creates theDaoAuthenticationProvider
.This is a problem if I want both a
DaoAuthenticationProvider
to handleUsernamePasswordAuthenticationToken
and a second provider to handle SSO tokens. If I only register the second provider, SSO works but theDaoAuthenticationProvider
is not present in theProviderManager
's providers list, so I cannot log in with username/password. If I also register aDaoAuthenticationProvider
, the default one also will be created, possibly with a different configuration (e.g. a differentPasswordEncoder
).The workaround I found is to register my SSO provider:
and a dummy one:
so I can use my SSO provider and the Dao provider configured by
InitializeUserDetailsManagerConfigurer
, but this is clearly not the intended way to do it.To Reproduce
Register a
UserDetailsService
and multipleAuthenticationProvider
s in a@Configuration
.Expected behavior
InitializeUserDetailsManagerConfigurer
should behave the same if either one or more than oneAuthenticationProvider
beans are registered.Sample
spring-security-dao-configurer
The text was updated successfully, but these errors were encountered: