shiro kick out user

Posted zouhao510

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shiro kick out user相关的知识,希望对你有一定的参考价值。

You shouldn‘t try to recreate the session and then operate it, you should get the session via the security manager, using the thread the user was logged into, like so:

SecurityUtils.getSubject().logout();

If you somehow want to call logout from a different thread, you can use the SessionDAO interface, but you need to do extra configuration to have shiro use a SessionDAO as described here:

http://shiro.apache.org/session-management.html#SessionManagement-SessionStorage

When you have configured it correctly you can do stuff like:

    DefaultSecurityManager securityManager = (DefaultSecurityManager) SecurityUtils.getSecurityManager();
    DefaultSessionManager sessionManager = (DefaultSessionManager) securityManager.getSessionManager();
    Collection<Session> activeSessions = sessionManager.getSessionDAO().getActiveSessions();
    for (Session session: activeSessions){
        if (sessionId.equals(session.getId()){
            session.stop();
        }
    }

以上是关于shiro kick out user的主要内容,如果未能解决你的问题,请参考以下文章

Shiro框架--bug调试之(密码错误)

shiro实现不使用密码加密器进行登录

shiro登录认证过程讲解

Bot 没有 KICK/BAN 命令的权限

如何为不和谐服务器制作“!踢”命令消息?

discord python bot kick 命令