Skip to content

X509 should detect UserDetailsService bean #11174

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
eleftherias opened this issue Apr 28, 2022 · 1 comment
Closed

X509 should detect UserDetailsService bean #11174

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

Comments

@eleftherias
Copy link
Contributor

Consider the following configuration:

@Configuration
public class SecurityConfiguration {

	@Bean
	SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
		http.x509(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 X509 configuration.

Cannot invoke "org.springframework.security.core.userdetails.UserDetailsService.loadUserByUsername(String)" because "this.userDetailsService" is nulljava.lang.NullPointerException: Cannot invoke "org.springframework.security.core.userdetails.UserDetailsService.loadUserByUsername(String)" because "this.userDetailsService" is null
	at org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper.loadUserDetails(UserDetailsByNameServiceWrapper.java:71)

Note: This only applies to 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 28, 2022
@eleftherias eleftherias self-assigned this Apr 28, 2022
@eleftherias eleftherias added this to the 5.7.0 milestone Apr 28, 2022
@eleftherias
Copy link
Contributor Author

Closed via 5ac5edc

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