zoukankan      html  css  js  c++  java
  • 测试Shiro过滤器和DispatcherServlet的调用顺序

    web.xml

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

  • 相关阅读:
    设计模式学习笔记之设计原则
    设计模式学习笔记之生成器模式
    设计模式学习笔记之适配器模式、外观模式
    java中的日期类型之间转换
    JS刷新当前页面的几种方法总结
    Java_枚举
    动态规划详解_2
    Java算法-动态规划详解
    Java经典算法题_2
    Java算法
  • 原文地址:https://www.cnblogs.com/john123/p/11173370.html
Copyright © 2011-2022 走看看