DaoAuthenticationProvider
{security-api-url}org/springframework/security/authentication/dao/DaoAuthenticationProvider.html[DaoAuthenticationProvider] 是一个 AuthenticationProvider实现,它使用 UserDetailsService和 PasswordEncoder来对用户名和密码进行身份验证。
本节探讨了 DaoAuthenticationProvider`如何在 Spring Security 中工作。下图说明了来自 Reading the Username & Password部分各图中 `AuthenticationManager的工作原理。
DaoAuthenticationProvider Usage
来自 Reading the Username & Password部分的身份验证 Filter`将 `UsernamePasswordAuthenticationToken`传递给 `AuthenticationManager,它由 ProviderManager实现。
配置为使用类型为 `DaoAuthenticationProvider`的 AuthenticationProvider。
DaoAuthenticationProvider 从 UserDetailsService 中查找 UserDetails。
DaoAuthenticationProvider`使用 `PasswordEncoder验证在上一步中返回的 `UserDetails`上的密码。
当身份验证成功时,返回的 Authentication类型为 UsernamePasswordAuthenticationToken,其主体是已配置的 UserDetailsService`返回的 `UserDetails。最终,返回的 UsernamePasswordAuthenticationToken`由身份验证 `Filter`设置在 `SecurityContextHolder上。