Apache-Shiro CacheManager Redis integration to improve performance

A control flowchart


background

  • When every authorized to query the database for the interface, performance and responsiveness frequently accessed more slowly, so use caching

Add dependent

<!-- shiro+redis缓存插件 -->

<dependency>   <groupId>org.crazycake</groupId> <artifactId>shiro-redis</artifactId> <version>3.1.0</version> </dependency>

 Configuration

As can be seen from the control map, all of the components are managed by the securityManager, it must be configured into SecurityManager in CacheManager

The original issue

Solution: Modify the custom in CustomRealm

  • doGetAuthorizationInfo 方法
原有String username = (String)principals.getPrimaryPrincipal();
User user = userService.findAllUserInfoByUsername(username);
改为:

  • doGetAuthenticationInfo方法

原有return new SimpleAuthenticationInfo(username, user.getPassword(), this.getClass().getName());

Read:

 

Source Address: https://github.com/woxbwo/is-rbac-shiro-service/tree/master/src/main/java/com/is/shiro/service/config

carry out! ! !

Guess you like

Origin www.cnblogs.com/woxbwo/p/11421696.html