Skip to content

Latest commit

 

History

History
50 lines (42 loc) · 1.28 KB

4. shiro-整合redis.md

File metadata and controls

50 lines (42 loc) · 1.28 KB

4. shiro-整合redis

#添加依赖

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

#再shiro权限认证的基础上, 修改shiroConf, 添加

    /**
     * redis 缓冲策略对应 RedisCacheConfiguration
     */
    private RedisCacheManager redisCacheManager(){
        RedisCacheManager redisCacheManager = new RedisCacheManager();
        redisCacheManager.setRedisManager(redisManager());
        //600s
        redisCacheManager.setExpire(600);
        return redisCacheManager;
    }

    /**
     * redis管理器, 只会存用户储权限认证的sql (即doGetAuthorizationInfo()方法调用的sql)
     */
    private RedisManager redisManager(){
        return new RedisManager();
    }

修改

    @Bean
    public DefaultWebSecurityManager securityManager(Realm userRealm) {
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        //关联realm
        securityManager.setRealm(userRealm);
        //设置cookie管理器
        securityManager.setRememberMeManager(cookieRememberMeManager());
        //shiro关联redis
        securityManager.setCacheManager(redisCacheManager());
        return securityManager;
    }