redis-shiro 手动踢出

   @Autowired
    SessionDAO sessionDAO;

    public void kickout(Long userId) {
        RedisSessionDAO redisSessionDAO = (RedisSessionDAO) sessionDAO;
        for (Session obj : sessionDAO.getActiveSessions()) {
            for (Object key : obj.getAttributeKeys()) {
                if (obj.getAttribute(key) instanceof SimplePrincipalCollection) {
                    SimplePrincipalCollection simplePrincipalCollection = (SimplePrincipalCollection) obj.getAttribute(key);
                    List asList = simplePrincipalCollection.asList();
                    for (int i = 0; i < asList.size(); i++) {
                        if (asList.get(i) instanceof ShiroUser) {
                            if (((ShiroUser) asList.get(i)).getId().equals(userId)) {
                                obj.setTimeout(0);
                                redisSessionDAO.update(obj);
                            }
                        }
                    }
                }
            }
        }
    }
设置扫描过期的间隔
sessionManager.setSessionValidationInterval(1000);

你可能感兴趣的:(spring)