UsernamePasswordAuthenticationFilter學習之基礎

UsernamePasswordAuthenticationFilter是登陸用戶密碼驗證過濾器,它繼承了AbstractAuthenticationProcessingFilter過濾器(真正的Filter),是spring security3的第4個過濾器。

UsernamePasswordAuthenticationFilter有3個表單參數,是我們需要知道的

1、usernameParameter:對應登錄時的用戶名需要傳的參數名稱,默認爲j_username,比如你輸入用戶hello,表單提交時是這樣的 j_username=hello

2、passwordParameter:對應登錄時的密碼提交時的參數名稱,默認爲j_password,比如你輸入密碼是123123,表單提交是這樣的 j_password=123123

3、filterProcessesUrl(放在了AbstractAuthenticationProcessingFilter):表單提交地址,默認爲/j_spring_security_check,這個地址才能被UsernamePasswordAuthenticationFilter所截取,進行登錄認證。

UsernamePasswordAuthenticationFilter會將表單提交的用戶密碼以及一些用戶的其他信息(比如remoteAddr,seesionId),先放入UsernamePasswordAuthenticationToken中

UsernamePasswordAuthenticationToken繼承了AbstractAuthenticationToken,AbstractAuthenticationToken繼承了Authentication(Authentication存放用戶的所有的認證信息)

UsernamePasswordAuthenticationToken 中有2個參數Object principal(主要的身份認證信息),Object credentials(用於證明principal是正確的信息,比如密碼)

在一個帶有username和password的權限認證請求中,principal就會被賦值username,credentials就會被賦值password;在使用AuthenticationManager的時候,principal會被賦值更多具有豐富內容的信息,比如被賦值成一個UserDetails對象,credentials可能會被賦值密碼類似的東西,比如一個特殊的類吧。

AbstractAuthenticationToken中有3個參數Object details,Collection<GrantedAuthority> authorities,boolean authenticated

1、details:額外的認證信息,比如被賦值用戶的IP地址

2、authorities:授權信息,比如被賦值用戶的角色信息

3、authenticated :是否被驗證通過

上面的5個參數是Authentication(是一個接口)必須的

瞭解以上信息,對理解用戶登陸權限的驗證過程有很大幫助

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