Spring Security 之 UsernamePasswordAuthenticationFilter 源碼

UsernamePasswordAuthenticationFilter AbstractAuthenticationProcessingFilter 的子類,主要作用是對用戶身份信息的驗證。
關於 AbstractAuthenticationProcessingFilter 的分析見此:

AbstractAuthenticationProcessingFilter 源碼解析

繼承關係

UsernamePasswordAuthenticationFilter 繼承自AbstractAuthenticationProcessingFilter

public class UsernamePasswordAuthenticationFilter extends
        AbstractAuthenticationProcessingFilter {

sernamePasswordAuthenticationFilter 實現的父類方法 attemptAuthentication() 中的用戶身份驗證邏輯。

 

  • 1,2兩個代碼是從request中提取用戶名稱和密碼
  • 3 代碼爲構造 UsernamePasswordAuthenticationToken 對象,其繼承AbstractAuthenticationToken,AbstractAuthenticationToken 實現了Authentication,它是用戶信息的載體,從來存儲和傳遞用戶名稱和密碼。
  • 4 代碼調用了this.getAuthenticationManager()方法或AuthenticationManager實例,
  •   protected AuthenticationManager getAuthenticationManager() {
            return this.authenticationManager;
        }
    
    然後是調用到AuthenticationManager實例的authenticate()方法,將authRequest【也就是UsernamePasswordAuthenticationToken 】(用戶名稱和密碼)

  •  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章