UserDetailsService
DaoAuthenticationProvider
使用 {security-api-url}org/springframework/security/core/userdetails/UserDetailsService.html[UserDetailsService
] 来检索用户名、密码和用于通过用户名和密码进行身份验证的其他属性。Spring Security 提供 `UserDetailsService`的 in-memory、JDBC和 caching实现。
{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
.
您可以通过将自定义 UserDetailsService
作为 bean 呈现来定义自定义验证。例如,以下清单自定义了验证,假定 CustomUserDetailsService
实现了 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
:
仅当 This is only used if the |
-
Java
-
XML
-
Kotlin
@Bean
CustomUserDetailsService customUserDetailsService() {
return new CustomUserDetailsService();
}
<b:bean class="example.CustomUserDetailsService"/>
@Bean
fun customUserDetailsService() = CustomUserDetailsService()