¶Spring整合shiro
¶引言
shiro在Spring中最大的作用是授权
¶shiro主要功能
¶授权功能
- 代码式授权
需要在自己的realm中写入授权代码 - 注解式授权
需要在spring-mvc.xml中配置注解授权支持
并且在controller中设置注解 - jsp页面授权
需要在jsp页面中导入shiro的授权标签库 
¶缓存功能
- 解决问题
我们在项目中每一次授权都要去查询数据库,这样的话数据库的压力就会相当的大 - 解决方法
shiro提供了cache缓存机制,这样会将第一次授权查询数据库所得的数据缓存,以便以后授权使用 - 需求
导入ehcache依赖,配置ehcache.xml文件,配置bean-shiro.xml文件 
¶session管理功能(没啥用)
¶rememberMe功能
- 解决问题
我们输入用户信息登录后,不会记住我们的用户信息,这样我们在段时间后登录就需要重新输入数据 - 解决方法
shiro提供了rememberMe功能,使得用户信息能够保存一定时间 - 需求
配置bean-shiro.xml文件,编写测试页面 
¶使用maven管理
- 配置pom文件,导入包
 
1  | <?xml version="1.0" encoding="UTF-8"?>  | 
¶resources资源文件配置
- bean-shiro.xml配置(配置shiro过滤器)
 
1  | <beans xmlns="http://www.springframework.org/schema/beans"  | 
- spring-mvc.xml配置(配置springmvc)
 
1  | <beans xmlns="http://www.springframework.org/schema/beans"  | 
- ehcache.xml(配置缓存)
 
1  | <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  | 
¶webapp配置
- web.xml配置(项目配置)
 
1  | <!DOCTYPE web-app PUBLIC  | 
¶java源文件
¶com.myShiro.controller包
- UserController
 
1  | package com.myShiro.controller;  | 
- IndexController
 
1  | package com.myShiro.controller;  | 
¶com.myShiro.pojo包
- User
 
1  | package com.myShiro.pojo;  | 
¶com.myShiro.realm包
- MyRealm
 
1  | package com.myShiro.realm;  | 
¶com.myShiro.filter
- MyFormAuthenticationFilter(表单验证过滤器)
 
1  | package com.myShiro.filter;  | 
¶测试
- 测试登录
 
1  | 
- 测试过滤器授权
 
1  | 
- 测试注解授权
 
1  | 


