zoukankan      html  css  js  c++  java
  • shiro中unauthorizedUrl不起作用

    解决方法:

    在shiro配置文件中添加(异常全路径做key,错误页面做value)

    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
            <property name="exceptionMappings">
                <props>
                    <prop key="org.apache.shiro.authz.UnauthorizedException">/403</prop>
                </props>
            </property>
        </bean>

    原因:这是因为shiro源代码中判断了filter是否为AuthorizationFilter,只有perms,roles,ssl,rest,port才是属于AuthorizationFilter,而anon,authcBasic,auchc,user是AuthenticationFilter,所以unauthorizedUrl设置后不起作用。

    shiro源代码

        private void applyUnauthorizedUrlIfNecessary(Filter filter) {
            String unauthorizedUrl = getUnauthorizedUrl();
            if (StringUtils.hasText(unauthorizedUrl) && (filter instanceof AuthorizationFilter)) {
                AuthorizationFilter authzFilter = (AuthorizationFilter) filter;
                //only apply the unauthorizedUrl if they haven't explicitly configured one already:
                String existingUnauthorizedUrl = authzFilter.getUnauthorizedUrl();
                if (existingUnauthorizedUrl == null) {
                    authzFilter.setUnauthorizedUrl(unauthorizedUrl);
                }
            }
        }

    shiro默认过滤器(10个) 

      • anon -- org.apache.shiro.web.filter.authc.AnonymousFilter
      • authc -- org.apache.shiro.web.filter.authc.FormAuthenticationFilter
      • authcBasic -- org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter
      • perms -- org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter
      • port -- org.apache.shiro.web.filter.authz.PortFilter
      • rest -- org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter
      • roles -- org.apache.shiro.web.filter.authz.RolesAuthorizationFilter
      • ssl -- org.apache.shiro.web.filter.authz.SslFilter
      • user -- org.apache.shiro.web.filter.authc.UserFilter
      • logout -- org.apache.shiro.web.filter.authc.LogoutFilter
  • 相关阅读:
    SQL2014还原到2008
    SQL SERVER2014 安装 Error code 0x858C001B.
    c++builder XE7 C++11 C++0x 新语法
    c++Builder XE6 MD5 加密算法 BASE64 URL 编码
    手机新功能
    xe fmx 怎么改变button颜色
    XE6 任务栏 控件
    js里面return 和 return false的区别
    web.xml的contextConfigLocation作用及自动加载applicationContext.xml
    mybatis-config.xml配置
  • 原文地址:https://www.cnblogs.com/qlong8807/p/5524381.html
Copyright © 2011-2022 走看看