控制流程圖
背景
- 授權的時候每次都去查詢數據庫,對於頻繁訪問的接口,性能和響應速度比較慢,所以使用緩存
添加依賴
<!-- 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());
改為:
完成!!!