Skip to content
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

Remember me should detect UserDetailsService bean #11170

Closed
eleftherias opened this issue Apr 27, 2022 · 1 comment
Closed

Remember me should detect UserDetailsService bean #11170

eleftherias opened this issue Apr 27, 2022 · 1 comment
Assignees
Labels
in: config An issue in spring-security-config type: enhancement A general enhancement
Milestone

Comments

@eleftherias
Copy link
Contributor

eleftherias commented Apr 27, 2022

Consider the following configuration:

@Configuration
public class SecurityConfiguration {

	@Bean
	SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
		http.formLogin(withDefaults()).rememberMe(withDefaults());
		return http.build();
	}

	@Bean
	public InMemoryUserDetailsManager customUserDetailsService() {
		UserDetails user = User.withDefaultPasswordEncoder()
				.username("test")
				.password("password")
				.roles("USER")
				.build();
		return new InMemoryUserDetailsManager(user);
	}
}

When starting the application, an error is thrown because we have not specified the UserDetailsService that should be used in the remember me configuration.

java.lang.IllegalStateException: userDetailsService cannot be null. Invoke RememberMeConfigurer#userDetailsService(UserDetailsService) or see its javadoc for alternative approaches.

We should change this behavior so that the UserDetailsService bean is picked up in the remember me configuration, without requiring the user to explicitly specify it.

Note: I've updated the description to only cover the case where a SecurityFilterChain bean is used. Adding the same changes to the WebSecurityConfigurerAdapter would break backwards compatibility.

@eleftherias eleftherias added in: config An issue in spring-security-config type: enhancement A general enhancement labels Apr 27, 2022
@eleftherias eleftherias self-assigned this Apr 27, 2022
@eleftherias
Copy link
Contributor Author

Closed via 8e34ced

@eleftherias eleftherias added this to the 5.7.0 milestone Apr 28, 2022
eleftherias added a commit that referenced this issue Apr 28, 2022
Describe the new behaviour for retrieving the UserDetailsService

Issue gh-11170
eleftherias added a commit that referenced this issue Apr 28, 2022
Describe the new behaviour for retrieving the UserDetailsService

Issue gh-11170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: config An issue in spring-security-config type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant