zoukankan      html  css  js  c++  java
  • shiro安全框架和spring整合

    上干货.........

    整合spring的配置文件

    <?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:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!-- filter-name这个名字的值来自于web.xml中filter的名字 -->
    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
    <property name="securityManager" ref="securityManager"/>
    <!--登录页面 如果没有登录 访问项目的方法或页面 直接跳转到这个页面 -->
    <property name="loginUrl" value="/login.jsp"></property>
    <!--登录后 在访问没有经过授权的方法或页面时 直接跳转到这个页面 -->
    <property name="unauthorizedUrl" value="/unauthorized.jsp"></property>
    <property name="filterChainDefinitions">
    <!-- /**代表下面的多级目录也过滤 过滤器链 -->
    <value>
    /login.jsp = anon
    /css/** = anon
    /img/** = anon
    /plugins/** = anon
    /make/** = anon
    /favicon.ico= anon
    /login.do = anon
    /** = authc
    </value>
    </property>
    </bean>

    <!-- 引用自定义的realm
    <bean id="saasRealm" class="cn.itcast.realm.SaasRealm"/>
    -->
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
    <!-- <property name="realm" ref="saasRealm"/>-->
    </bean>
    <!-- 安全管理器 -->
    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
    <property name="securityManager" ref="securityManager"/>
    </bean>

    <!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->
    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

    <!-- 生成代理,通过代理进行控制 -->
    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
    depends-on="lifecycleBeanPostProcessor">
    <property name="proxyTargetClass" value="true"/>
    </bean>

    <aop:aspectj-autoproxy proxy-target-class="true"/>
    </beans>

    注意的事项

    shiro的过滤器是有配置顺序的,

    /login.do = anon 不拦截

    /company/list.do = perms["企业管理"] 需要有对应的权限来访问

    /** = authc 只要登录了就可以进行访问

    shiro的优化

    shiro的缓存优化

  • 相关阅读:
    Cooperate with Myself
    A brief introduction of myself
    计算1+11+111+1111+........
    Jav实现F(n)=F(n-1)+F(n-2)+.....+F(1)+1
    查找二维数组中是否有符合的目标值
    排序算法
    时间复杂度
    Java代码实现单例模式
    查找一个字符串中重复出现字符的个数
    null,“”,empty的区别
  • 原文地址:https://www.cnblogs.com/niCong/p/13527891.html
Copyright © 2011-2022 走看看