Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Sage520 opened this issue Nov 20, 2020 · 6 comments
Open

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

Sage520 opened this issue Nov 20, 2020 · 6 comments

Comments

@Sage520
Copy link

Sage520 commented Nov 20, 2020

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

环境:
jdk8
windows 10
springboot 2.2.6

@alexxiyang
Copy link
Owner

可否附上配置文件?

@kitzhou
Copy link

kitzhou commented Dec 20, 2020

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

@Sage520
Copy link
Author

Sage520 commented Dec 21, 2020

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

我也是jwt的

@Sage520
Copy link
Author

Sage520 commented Dec 24, 2020

可否附上配置文件?

@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
Copy link

kitzhou commented Dec 25, 2020

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

@Sage520
Copy link
Author

Sage520 commented Dec 25, 2020

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants