Shiro不执行自定义AuthorizingRealm

 

 

干净利落直接讲主题:

简述:

技术 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

posted @ 2017-03-14 18:09  简叙。  阅读(3849)  评论(0编辑  收藏  举报