Skip to content

When I added a custom UserDetailService, there seemed to be some issues with the ProviderManager #1372

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

Closed
zhangpan-soft opened this issue Sep 21, 2023 · 7 comments
Assignees
Labels
for: external-project For an external project and not something we can fix

Comments

@zhangpan-soft
Copy link

When I add a custom UserDetailService, it loses its default Provider correspondence

Tracking code found that in ProviderManger, the parent of ProviderManager is empty

When I do not add a custom UserDetailService, the parent of the ProviderManager has a value, and there is a corresponding provider in the providers

When I comment out this code

image
image

When I release the comment

image
image

I don't know what I should do to solve this problem

@zhangpan-soft zhangpan-soft added the type: bug A general bug label Sep 21, 2023
@lorenzoAgainAgainAgain
Copy link

Hi, obvious question as I don't see them: did you set the DaoAuthenticationProvider and the AuthenticationManager to manage your UserDetailsService and the PasswordEncoder?

@zhangpan-soft
Copy link
Author

Hi, obvious question as I don't see them: did you set the DaoAuthenticationProvider and the AuthenticationManager to manage your UserDetailsService and the PasswordEncoder?

I did not proactively set up DaoAuthenticationProvider and AuthenticationManager I think it should be automatically loaded. If not, how should I set them?

@lorenzoAgainAgainAgain
Copy link

lorenzoAgainAgainAgain commented Sep 21, 2023

In my use case I've set them like this:
@Bean(BeanIds.AUTHENTICATION_MANAGER) public AuthenticationManager authenticationManagerBean(AuthenticationConfiguration authConfiguration) throws Exception { return authConfiguration.getAuthenticationManager(); }

@Bean public DaoAuthenticationProvider authenticationProvider() { DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); authProvider.setUserDetailsService(userDetailsService()); authProvider.setPasswordEncoder(passwordEncoder()); return authProvider; }

I'd like to have a feedback if this work even for you.
Sorry I can't format the code more than this.

@zhangpan-soft
Copy link
Author

In my use case I've set them like this: Bean(BeanIds.AUTHENTICATION_MANAGER) public AuthenticationManager authenticationManagerBean(AuthenticationConfiguration authConfiguration) throws Exception { return authConfiguration.getAuthenticationManager(); } Bean public DaoAuthenticationProvider authenticationProvider() { DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); authProvider.setUserDetailsService(userDetailsService()); authProvider.setPasswordEncoder(passwordEncoder()); return authProvider; }

I'd like to have a feedback if this work even for you.Sorry I can't format the code more than this.

In my use case I've set them like this: @Bean(BeanIds.AUTHENTICATION_MANAGER) public AuthenticationManager authenticationManagerBean(AuthenticationConfiguration authConfiguration) throws Exception { return authConfiguration.getAuthenticationManager(); }

@Bean public DaoAuthenticationProvider authenticationProvider() { DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); authProvider.setUserDetailsService(userDetailsService()); authProvider.setPasswordEncoder(passwordEncoder()); return authProvider; }

I'd like to have a feedback if this work even for you.Sorry I can't format the code more than this.

It has indeed taken effect, as long as DaoAuthenticationProvider is redefined here The ProviderManager will load the parent, which is strange In spring boot 3.1.3, I did not redefine DaoAuthenticationProvider, only defined UserDetailService, which will take effect

@lorenzoAgainAgainAgain
Copy link

Glad this helped you, but maybe someone else can explain why in v3.1.3 it's not necessary to set the DaoAuthenticationProvider and the AuthenticationManager? In fact, I didn't have to define them in my Spring Boot 3 projects either, but only with older versions as 2.7

@zhangpan-soft
Copy link
Author

Glad this helped you, but maybe someone else can explain why in v3.1.3 it's not necessary to set the DaoAuthenticationProvider and the AuthenticationManager? In fact, I didn't have to define them in my Spring Boot 3 projects either, but only with older versions as 2.7

Thanks

@jgrandja jgrandja added for: external-project For an external project and not something we can fix and removed type: bug A general bug labels Sep 21, 2023
@jgrandja jgrandja self-assigned this Sep 21, 2023
@zhangpan-soft
Copy link
Author

Glad this helped you, but maybe someone else can explain why in v3.1.3 it's not necessary to set the DaoAuthenticationProvider and the AuthenticationManager? In fact, I didn't have to define them in my Spring Boot 3 projects either, but only with older versions as 2.7

I know why, just like I was #1370 As said There is another UserDetailService under DefaultSecurityConfig

I suggest organizing the documents, such as creating a timeline diagram for the samples project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

3 participants