springboot 登陸實現源代碼解析

springboot 能夠使用springsecurity 做爲安全框架,咱們能夠使用springsecurity 實現安全登陸。spring

springsecurity 是使用一系列的過濾器來實現安全的。安全

實現用戶登陸使用的是:springboot

UsernamePasswordAuthenticationFilter過濾器來實現。框架

他在過濾器鏈中的位置以下:spa

這個代碼的實現邏輯是:3d

1.攔截地址爲 /login的URL。code

2.若是地址欄的地址爲login 則進行以後的邏輯處理,不然跳過。blog

3.驗證用戶接口

這個attemptAuthentication方法由 UsernamePasswordAuthenticationFilter 實現,在上下文中獲取 用戶名和密碼。it

從上面的代碼咱們能夠看出,代碼經過 AuthenticationManager 獲取用戶接口獲取信息。

當成功時:

執行上面都代碼:

1.設置上下文

2.處理記住密碼登陸成功消息。

3.調用自定義成功處理器。

當失敗時:

失敗處理接口

public interface AuthenticationFailureHandler {
    void onAuthenticationFailure(HttpServletRequest var1, HttpServletResponse var2, AuthenticationException var3) throws IOException, ServletException;
}
相關文章
相關標籤/搜索