DaoAuthenticationProvider

DaoAuthenticationProvider 是一個 AuthenticationProvider 實現,它使用 UserDetailsServicePasswordEncoder 來認證使用者名稱和密碼。

本節探討 DaoAuthenticationProvider 在 Spring Security 中的工作原理。下圖解釋了 讀取使用者名稱和密碼 部分中 AuthenticationManager 的工作原理。

daoauthenticationprovider
圖 1. DaoAuthenticationProvider 用法

數字 1 讀取使用者名稱和密碼 部分中的認證 FilterUsernamePasswordAuthenticationToken 傳遞給由 ProviderManager 實現的 AuthenticationManager

數字 2 ProviderManager 被配置為使用型別為 DaoAuthenticationProviderAuthenticationProvider

數字 3 DaoAuthenticationProviderUserDetailsService 中查詢 UserDetails

數字 4 DaoAuthenticationProvider 使用 PasswordEncoder 驗證上一步中返回的 UserDetails 的密碼。

數字 5 認證成功時,返回的 Authentication 型別為 UsernamePasswordAuthenticationToken,其主體是配置的 UserDetailsService 返回的 UserDetails,並且許可權集至少包含 FACTOR_PASSWORD。最終,返回的 UsernamePasswordAuthenticationToken 由認證 Filter 設定到 SecurityContextHolder 中。

© . This site is unofficial and not affiliated with VMware.