For the latest stable version, please use Spring Security 6.4.1!spring-doc.cn

UserDetailsService

UserDetailsService is used by DaoAuthenticationProvider for retrieving a username, password, and other attributes for authenticating with a username and password. Spring Security provides in-memory and JDBC implementations of UserDetailsService.spring-doc.cn

You can define custom authentication by exposing a custom UserDetailsService as a bean. For example, the following will customize authentication assuming that CustomUserDetailsService implements UserDetailsService:spring-doc.cn

This is only used if the AuthenticationManagerBuilder has not been populated and no AuthenticationProviderBean is defined.
Custom UserDetailsService Bean
@Bean
CustomUserDetailsService customUserDetailsService() {
	return new CustomUserDetailsService();
}
<b:bean class="example.CustomUserDetailsService"/>
@Bean
fun customUserDetailsService() = CustomUserDetailsService()