4. shiro-整合redis

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;
    }
posted @ 2020-05-06 15:14  CyberPelican  阅读(702)  评论(0编辑  收藏  举报