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的缓存优化
最新文章
- ABP模块化
- ASP.NET MVC图片上传
- IOS-01零碎知识总结
- c++相关的类型推导
- C语言sizeof
- History(历史)命令用法15例
- 我和小美的撸码日记(3)之一句话搞定MVC表单页数据绑定与提交
- Python 使用Pillow模块生成验证码
- linux 获取CPU个数
- Junit4测试报错
- Jmeter 后置处理器JSON Extractor 提取json的多个值
- 原生JS制作简易Tabs组件
- Python-数据类型1
- [ZJOI2007]矩阵游戏【bzoj1059/洛谷1129】/ [HEOI2016/TJOI2016]游戏
- 【BZOJ3997】【TJOI2015】组合数学 Dilworth定理 DP
- 从零开始一起学习SLAM | 点云平滑法线估计
- js对当前时间的相关操作
- SRAM、DRAM、SDRAM、DDR、DDR2、DDR3
- 用Qemu搭建x86_64学习环境
- webdriver鼠标上下滑动