测试Shiro过滤器和DispatcherServlet的调用顺序

Posted john123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了测试Shiro过滤器和DispatcherServlet的调用顺序相关的知识,希望对你有一定的参考价值。

web.xml

 1     <!--shiro filter-->
 2     <filter>
 3         <filter-name>shiroFilter</filter-name>
 4         <filter-class>
 5             org.springframework.web.filter.DelegatingFilterProxy
 6         </filter-class>
 7     </filter>
 8     <filter-mapping>
 9         <filter-name>shiroFilter</filter-name>
10         <url-pattern>/shiro/*</url-pattern>
11     </filter-mapping> 

 

applicationContext.xml

 1  <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
 2         <property name="securityManager" ref="securityManager"/>
 3         <!-- override these for application-specific URLs if you like:
 4         <property name="loginUrl" value="/login.jsp"/>
 5         <property name="successUrl" value="/home.jsp"/>
 6         <property name="unauthorizedUrl" value="/unauthorized.jsp"/> -->
 7         <!-- The ‘filters‘ property is not necessary since any declared javax.servlet.Filter bean  -->
 8         <!-- defined will be automatically acquired and available via its beanName in chain        -->
 9         <!-- definitions, but you can perform instance overrides or name aliases here if you like: -->
10         <!-- <property name="filters">
11             <util:map>
12                 <entry key="anAlias" value-ref="someFilter"/>
13             </util:map>
14         </property> -->
15         <property name="filterChainDefinitions">
16             <value>
17                 # some example chain definitions:
18                 /admin/** = authc, roles[admin]
19                 /docs/** = authc, perms[document:read]
20                 /shiro/** = authc
21                 # more URL-to-FilterChain definitions here
22             </value>
23         </property>
24     </bean>

 

测试url:  /shiro/test

结果: shiroFilter - 》DispatcherServlet

 

测试url:  /other/test

结果: DispatcherServlet 

 

结论:当请的url能被shiro过滤器匹配到时,先走shiro过滤器,再走DispatcherServlet ;

     否则只走DispatcherServlet。

 

以上是关于测试Shiro过滤器和DispatcherServlet的调用顺序的主要内容,如果未能解决你的问题,请参考以下文章

带你深入使用shiro,自定义token过滤器

带你深入使用shiro,自定义token过滤器

带你深入使用shiro,自定义token过滤器

带你深入使用shiro,自定义token过滤器

shiro+spring

Shiro权限管理框架:Shiro中权限过滤器的初始化流程和实现原理