自定義登錄form攔截器:org.apache.shiro.web.filter.authc.FormAuthenticationFilter
問題描述
使用shiro進行系統身份驗證-權限控制,登錄界面進行登錄操作何時觸發
boolean org.apache.shiro.web.filter.authc..executeLogin( request,
response) throws 方法?
問題分析
探知login.jsp的form與shiro form filter的識別認證規則需要查看org.apache.shiro.web.filter.authc.FormAuthenticationFilter中的源碼。
第一、輸入控件name命名:
在此可知,登錄表單的用戶名、密碼等輸入控件的name默認值。
第二、表單action與login.jsp的訪問地址規則:
shiro過濾器的配置:
boolean org.apache.shiro.web.filter.authc..onAccessDenied( request,
response) throws
文字選中方法:boolean org.apache.shiro.web.filter.authc..executeLogin( request,
response) throws 該方法在
org.apache.shiro.web.filter.authc.AuthenticatingFilter中有具體實現:
當登錄表單需要擴展時,需要在擴展類裏重新實現此方法,比如,登錄時增加驗證碼,實現如下:
本文重點探究該方法何時被正確出發?
1. 判斷當前URL是否爲登錄地址:
shiroFilter的loginUrl值。
boolean org.apache.shiro.web.filter..isLoginRequest(
request, response);
2. 如果當前請求URL爲登錄地址時,判斷是否爲form提交。
boolean org.apache.shiro.web.filter.authc..isLoginSubmission(
request, response);
在此兩點可以總結出登錄表單及登錄界面URL的規則,即:
get loginUrl:進入登錄界面
post loginUrl:提交登錄表單
username:表單用戶名
password:表單密碼
探究結論
shiroFilter配置的loginUrl的GET請求進入登錄界面,POST請求爲提交登錄表單。
觸發
boolean org.apache.shiro.web.filter.authc..executeLogin( request, response)
throws 方法。