zoukankan      html  css  js  c++  java
  • shiro配置

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
    
        <context:component-scan base-package="com.atguigu.shiro"></context:component-scan>
    
        <!-- 配置 CacheManager 实例: 管理 Shiro 相关缓存操作的 -->
        <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
            <property name="cacheManagerConfigFile" value="classpath:ehcache-shiro.xml"/>
        </bean>
        
        <!-- 配置 Realm 实例: 实际上的认证和授权都是由 Realm 实例来完成的! -->
        <bean id="myRealm"
            class="com.atguigu.shiro.realm.MyRealm"></bean>
    
        <!-- 配置 SecurityManager 实例. SecurityManager 是 Shiro 最核心的组件 -->
        <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
            <property name="cacheManager" ref="cacheManager"/>
            <property name="realm" ref="myRealm"/>
        </bean>
        
        <!-- 该 bean 后置处理器会自动的调用 Shiro 中 bean 的 init 和 destroy 方法. -->
        <bean id="lifecycleBeanPostProcessor" 
            class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
        
        <!-- 使 shiro 的注解起作用的 bean. 需要在配置 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>
        
        <!-- 
            配置 ShiroFilter: 实际上配置哪些页面需要被拦截, 以及访问这些页面所需要具备的权限 
            id 属性值必须和 web.xml 文件中配置的 filter 的 filter-name 值一致
        -->
        <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="/unauthorize.jsp"/>
            <!-- 配置需要被拦截的资源, 以及访问这些资源需要的权限 -->
            <property name="filterChainDefinitions">
                <value>
                    <!-- 注意: URL 权限采取第一次匹配优先的方式 -->
                    
                    <!-- anon: 表示匿名的, 即任何人都可以访问 -->
                    /login.jsp = anon
                    /login = anon
                    /logout = logout
                    
                    <!-- 设置访问具体资源的权限 -->
                    /admin.jsp = roles[admin]
                    /user.jsp = roles[user]
                    
                    <!-- authc 表示必须经过认证之后才可以访问的页面 -->
                    /** = authc
                </value>
            </property>
        </bean>
    
    </beans>
  • 相关阅读:
    vb代码控制 Excel锁定单元格
    SendMessage
    vb 中Treeview控件的一些问题!
    NGWS runtime C# 开始学习 第一天 (2006.6.7)
    DTS Transform Data Task的使用
    GetTickCount
    ASP.NET 2.0 中Login控件的使用
    core dump解析(2)
    tcp滑动窗口机制
    linux 查看文件夹大小 du命令
  • 原文地址:https://www.cnblogs.com/lonely-buffoon/p/5678328.html
Copyright © 2011-2022 走看看