web.xml

<!-- Shiro Filter is defined in the spring application context: -->
    <!-- 1. 配置 Shiro 的 shiroFilter. 2. DelegatingFilterProxy 实际上是 Filter 的一个代理对象.
        默认情况下, Spring 会到 IOC 容器中查找和 <filter-name> 对应的 filter bean. 也可以通过 targetBeanName
        的初始化参数来配置 filter bean 的 id.
        <init-param>
            <param-name>targetBeanName</param-name>
            <param-value>shiroFilter</param-value>
        </init-param>
        -->
    <filter>
        <filter-name>shiroFilter</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        <init-param>
            <param-name>targetFilterLifecycle</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>shiroFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- =========================================================
         Shiro Spring-specific integration
         ========================================================= -->
    <!-- Post processor that automatically invokes init() and destroy() methods
         for Spring-configured Shiro objects so you don't have to
         1) specify an init-method and destroy-method attributes for every bean
            definition and
         2) even know which Shiro objects require these methods to be
            called. -->
    <!--
    4. 配置 LifecycleBeanPostProcessor. 可以自定的来调用配置在 Spring IOC 容器中 shiro bean 的生命周期方法.
    -->
    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

    <!-- Enable Shiro Annotations for Spring-configured beans.  Only run after
         the lifecycleBeanProcessor has run: -->
    <!--
    5. 启用 IOC 容器中使用 shiro 的注解. 但必须在配置了 LifecycleBeanPostProcessor 之后才可以使用.
    -->
    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
          depends-on="lifecycleBeanPostProcessor"/>
    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
        <property name="securityManager" ref="securityManager"/>
    </bean>

    <!-- Define the Shiro Filter here (as a FactoryBean) instead of directly in web.xml -
         web.xml uses the DelegatingFilterProxy to access this bean.  This allows us
         to wire things with more control as well utilize nice Spring things such as
         PropertiesPlaceholderConfigurer and abstract beans or anything else we might need: -->
    <!--
    6. 配置 ShiroFilter.
    6.1 id 必须和 web.xml 文件中配置的 DelegatingFilterProxy 的 <filter-name> 一致.
                      若不一致, 则会抛出: NoSuchBeanDefinitionException. 因为 Shiro 会来 IOC 容器中查找和 <filter-name> 名字对应的 filter bean.
    -->
    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="securityManager" ref="securityManager"/>
        <property name="loginUrl" value="/login.jsp"/>
        <property name="successUrl" value="/list.jsp"/>
        <property name="unauthorizedUrl" value="/unauthorized.jsp"/>

        <property name="filterChainDefinitionMap" ref="filterChainDefinitionMap"></property>

        <!--
            配置哪些页面需要受保护.
            以及访问这些页面需要的权限.
            1). anon 可以被匿名访问
            2). authc 必须认证(即登录)后才可能访问的页面.
            3). logout 登出.
            4). roles 角色过滤器
            5).没有配置或配置了匿名可以直接被访问到,不能被访问到的会被重定向到loginUrl页面
        -->

        <!--
            匹配模式:?:匹配一个字符,/admin?
            Ant 路径通配符支持 ?、 *、 **,注意通配符匹配不包括目录分隔符“/”:
            – ?:匹配一个字符, 如 /admin? 将匹配 /admin1,但不匹配 /admin 或 /admin/;
            – *:匹配零个或多个字符串, 如 /admin 将匹配 /admin、/admin123,但不匹配 /admin/1;
            – **:匹配路径中的零个或多个路径, 如 /admin/** 将匹配 /admin/a 或 /admin/a/b
            URL 权限采取第一次匹配优先的方式

        <property name="filterChainDefinitions">
            <value>
                /login.jsp = anon
                /user.jsp = anon
                /shiro/login = anon
                /shiro/logout = logout
                /user.jsp = roles[user]
                /admin.jsp = roles[admin]
                /** = authc
            </value>
        </property>
        -->
    </bean>

    <!-- 配置一个 bean, 该 bean 实际上是一个 Map. 通过实例工厂方法的方式 -->
    <bean id="filterChainDefinitionMap"
        factory-bean="filterChainDefinitionMapBuilder" factory-method="buildFilterChainDefinitionMap"></bean>

    <bean id="filterChainDefinitionMapBuilder"
        class="gold.factory.FilterChainDefinitionMapBuilder"></bean>

最新文章

  1. BPM配置故事之案例5-必填与水印文本
  2. 手机游戏渠道SDK接入工具项目分享(一)缘起
  3. Linux服务器管理: 日志管理(二)
  4. 通过 Chrome Workspace 调试本地项目(修改样式时及时保存)
  5. mac上mysql乱码问题解决
  6. 第8条:覆盖equals时遵守通用约定
  7. C++ trivial和non-trivial构造函数及POD类型(转)
  8. @RenderSection
  9. Struts2运行机制(MVC)的分析:
  10. 解决WP7的32位图像渐变色色阶问题
  11. jmeter之JDBC Request各种数据库配置
  12. Java入门(七):方法
  13. html 引入页面公共部分(header、footer)
  14. [TensorFlow笔记乱锅炖] tf.multinomial(logits, num_samples)使用方法
  15. jqGrid 列内容超过一定长度省略表示
  16. 使用PowerMockito 对静态类进行mock
  17. C#程序集系列11,全局程序集缓存
  18. Eclipse操作Servlet入门案例,创建类无法实现Servlet接口和继承HttpServlet类
  19. Mysql(一) 基本操作
  20. [Pytorch]PyTorch Dataloader自定义数据读取

热门文章

  1. flask os.environ 的作用
  2. 【Mac + Python + Selenium】之PyCharm配置Selenium自动化
  3. 加速I/O的基本规则
  4. Linux USB 鼠标输入驱动具体解释
  5. @RequestMapping 注解
  6. OpenvSwitch自动化重新编译和安装
  7. 【BZOJ2208】[Jsoi2010]连通数 DFS
  8. java的double类型如何精确到一位小数?
  9. python拓展库whl下载网址集合:
  10. delphi -----获取计算IP