# DAoAuthenticationProvider
[DaoAuthenticationProvider
](https://DOCS. Spring.io/ Spring-security/site/DOCS/5.6.2/api/org/springframework/security/authentication/dao/daoauthenticationprovider.html)是一种[AuthenticationProvider
](../architecture.html.html.html# Servlet-attentification-authnationprovider)实现,利用[<UserDetailsService
](user-details-service.html# Servlet-html#[userauthentification]-html# Servlet-
让我们来看看DaoAuthenticationProvider
在 Spring 安全性中是如何工作的。该图详细说明了读取用户名和密码图中的[AuthenticationManager
](../architecture.html# Servlet-authentication-authenticationmanager)是如何工作的。
图 1。DaoAuthenticationProvider
用法
来自读取用户名和密码的身份验证
Filter
将一个UsernamePasswordAuthenticationToken
传递到AuthenticationManager
,这是由[ProviderManager
](../architecture.html# Servlet-assertification-providerManager)实现的。
ProviderManager
被配置为使用身份验证提供者类型的DaoAuthenticationProvider
。
DaoAuthenticationProvider
从UserDetailsService
中查找UserDetails
。
DaoAuthenticationProvider
然后使用[PasswordEncoder
](password-encoder.html# Servlet-authentication-password-storage)在上一步返回的UserDetails
上验证密码。
当身份验证成功时,返回的[
Authentication
](../architecture.html# Servlet-Authentication-Authentication)类型为UsernamePasswordAuthenticationToken
,并且具有一个主体,即配置的UserDetailsService
返回的UserDetails
。最终,返回的UsernamePasswordAuthenticationToken
将由身份验证Filter
设置在[SecurityContextHolder
](../architecture.html# Servlet-authentication-securitycontextholder)上。