干凈利落直接講主題:
簡述:
技術 SpringMVC Mybatis shiro thymeleaf
登錄表單 username password + verify
Post提交首先執行了自定義FormAuthenticationFilter過濾器(ps:此過濾器主要執行了驗證碼校驗)
if (判斷驗證碼是否相等) {
//如果校驗失敗則返回true 則后續不會執行身份驗證
return true;
}
//重點在這里 執行了onAccessDenied之后
return super.onAccessDenied(request, response);
項目斷點查看到 package org.apache.shiro.web.servlet.AdviceFilter這個類 其中132行log.isTraceEnabled()這里這個開關為false
我就向前翻發現執行了過濾前的preHandle
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception { if (this.appliedPaths == null || this.appliedPaths.isEmpty()) { if (log.isTraceEnabled()) { log.trace("appliedPaths property is null or empty. This Filter will passthrough immediately."); } return true; } for (String path : this.appliedPaths.keySet()) { if (pathsMatch(path, request)) { log.trace("Current requestURI matches pattern '{}'. Determining filter chain execution...", path); //加載了映射 見下圖
Object config = this.appliedPaths.get(path); return isFilterChainContinued(request, response, path, config); } } return true; }
authcappliedPaths將我們的配置filterChainDefinitions過濾鏈變成了Map。其中shiroFilter中的loginUrl
例:<property name="loginUrl" value="/login.htm" />也會加載到authcappliedPaths中
所以我便開始查看我的配置文件 在shiroFilter中找到我的這個loginUrl
發現其不正確改成我的controller的requestMapper請求映射后正常執行自定義Realm
發現是這個原因場面一度十分尷尬。希望對大家有所幫助。如果寫的有什么不正確的請大家指導一下.
下面是我看過的源碼解析和官方API方法摘要
參考博客:http://www.aichengxu.com/other/10985615.htm
官方API:http://shiro.apache.org/static/1.3.2/apidocs/org/apache/shiro/subject/Subject.html