控制流程图
背景
- 授权的时候每次都去查询数据库,对于频繁访问的接口,性能和响应速度比较慢,所以使用缓存
添加依赖
<!-- shiro+redis缓存插件 -->
<dependency> <groupId>org.crazycake</groupId> <artifactId>shiro-redis</artifactId> <version>3.1.0</version> </dependency>
配置
由控制图可以看出,所有组件都是由securityManager管理的,所以必须将CacheManager配置到SecurityManager中
原有问题
解决:在自定义CustomRealm中修改
- doGetAuthorizationInfo 方法
原有String username = (String)principals.getPrimaryPrincipal();
User user = userService.findAllUserInfoByUsername(username);
改为:
- doGetAuthenticationInfo方法
原有return new SimpleAuthenticationInfo(username, user.getPassword(), this.getClass().getName());
改为:
完成!!!