alexxiyang / shiro-redis

shiro only provide the support of ehcache and concurrentHashMap. Here is an implement of redis cache can be used by shiro. Hope it will help you!
MIT License
1.17k stars 446 forks source link

登陆之后token验证不走redis缓存 #138

Open Sage520 opened 4 years ago

Sage520 commented 4 years ago

redis中有会话数据,但每次访问api,都会重新查数据库不走redis,并且查完又加了一条redis缓存,导致redis中同一个用户有很多相同会话,但查询的时候又不用 1 2

环境: jdk8 windows 10 springboot 2.2.6

alexxiyang commented 3 years ago

可否附上配置文件?

kitzhou commented 3 years ago

类似的问题,我是于jwt配合使用的,是哪个类的方法封装了redis权限校验的部分?一直没有跟到具体代码

Sage520 commented 3 years ago

类似的问题,我是于jwt配合使用的,是这些类的方法封装了redis权限校验的部分?一直没有跟到具体代码

我也是jwt的

Sage520 commented 3 years ago

可否附上配置文件?

@Bean
public SessionManager sessionManager(RedisSessionDAO redisSessionDAO) {
    DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();

    // inject redisSessionDAO
    sessionManager.setSessionDAO(redisSessionDAO);

    // other stuff...
    return sessionManager;
}

@Bean
public SessionsSecurityManager securityManager(AccountRealm accountRealm, SessionManager sessionManager,RedisCacheManager redisCacheManager) {
    DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(accountRealm);

    // 注入realm
    securityManager.setRealm(accountRealm);

    // inject sessionManager
    securityManager.setSessionManager(sessionManager);

    // inject redisCacheManager
    securityManager.setCacheManager(redisCacheManager);

    // other stuff...

    return securityManager;
}

@Bean
public ShiroFilterChainDefinition shiroFilterChainDefinition() {
    DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition();
    Map<String, String> filterMap = new LinkedHashMap<>();
    filterMap.put("/druid/**","anon");
    filterMap.put("/**", "jwt"); // 主要通过注解方式校验权限
    chainDefinition.addPathDefinitions(filterMap);
    return chainDefinition;
}

@Bean("shiroFilterFactoryBean")
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager,
                                                     ShiroFilterChainDefinition shiroFilterChainDefinition) {
    ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
    shiroFilter.setSecurityManager(securityManager);
    Map<String, Filter> filters = new HashMap<>();
    filters.put("jwt", jwtFilter);
    shiroFilter.setFilters(filters);
    Map<String, String> filterMap = shiroFilterChainDefinition.getFilterChainMap();
    shiroFilter.setFilterChainDefinitionMap(filterMap);
    return shiroFilter;
}
kitzhou commented 3 years ago

我的那个是参考最新样例,只自定义了shiroFilterFactoryBean,注入jwtfilter

Sage520 commented 3 years ago

我的那个是参考最新样例,只自定义了shiroFilterFactoryBean,注入jwtfilter

我折腾了几天没弄好,最后只好选择把它的那个session关了,自己写了个redis缓存的功能