在上一节的项目中
增加改进
<dependency>
<groupId>org.crazycake</groupId>
<artifactId>shiro-redis</artifactId>
<version>2.4.2.1-RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.46</version>
</dependency>
shiroConfig中
public RedisManager redisManager(){
RedisManager redisManager = new RedisManager();
redisManager.setHost("localhost");
redisManager.setPort(6379);
//缓存过期时间
redisManager.setExpire(1800);
redisManager.setTimeout(0);
//redisManager.setPassword();
return redisManager;
}
@Bean
public RedisCacheManager cacheManager(){
//使用的是org.crazycake包下的rediscachemanager
RedisCacheManager redisCacheManager = new RedisCacheManager();
redisCacheManager.setRedisManager(redisManager());
return redisCacheManager;
}
@Bean
public RedisSessionDAO redisSessionDAO(){
RedisSessionDAO redisSessionDAO = new RedisSessionDAO();
redisSessionDAO.setRedisManager(redisManager());
return redisSessionDAO;
}
@Bean
public DefaultWebSessionManager sessionManager(){
DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
sessionManager.setSessionDAO(redisSessionDAO());
return sessionManager;
}
@Bean(name = "securityManager")
public SecurityManager securityManager(){
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(getRealm());
securityManager.setCacheManager(cacheManager());
securityManager.setSessionManager(sessionManager());
return securityManager;
}
启动redis服务测试
登陆后能在redis库中看到新增的shirosession字段
默认情况下登陆时附带的Remember me值为false
手动设置为true后,打开浏览器登陆后
能在cookie中看到多出了一个rememberMe字段
实际上并没有发挥效果,需要更改其他的配置
具体下面这篇博客讲的很清楚