{security-api-url}org/springframework/security/core/userdetails/UserDetailsService.html[UserDetailsService
] is used by DaoAuthenticationProvider
for retrieving a username, a password, and other attributes for authenticating with a username and password.
Spring Security provides in-memory, JDBC, and caching implementations of UserDetailsService
.
You can define custom authentication by exposing a custom UserDetailsService
as a bean.
For example, the following listing customizes authentication, assuming that CustomUserDetailsService
implements UserDetailsService
:
Note
|
This is only used if the |
Example 1. Custom UserDetailsService Bean
- Java
-
@Bean CustomUserDetailsService customUserDetailsService() { return new CustomUserDetailsService(); }
- XML
-
<b:bean class="example.CustomUserDetailsService"/>
- Kotlin
-
@Bean fun customUserDetailsService() = CustomUserDetailsService()