简体   繁体   English

Grails 注销另一个登录用户

[英]Grails logout another logged in user

I have grails application and installed spring security core plugin.我有 grails 应用程序并安装了 spring 安全核心插件。 I want to logout another logged in user.我想注销另一个登录用户。 I am able to get all logged in users list using sessionFactory.我能够使用 sessionFactory 获取所有登录的用户列表。

Help needed.需要帮助。

Please give me detailed explanation.请给我详细的解释。

I followed this thread but, I am not able to logout by just simply invalidating session.我关注了这个线程,但是我无法通过简单地使会话无效来注销。

Invalidation should work.失效应该有效。 This code is 100% working on grails 2.3.5, spring-security-core:2.0.0此代码 100% 适用于 grails 2.3.5, spring-security-core:2.0.0

    def sessions = ContextListener.instance().getSessions()
    def sessionToInvalidate = sessions.find{it.id == someId}
    sessionToInvalidate.invalidate()

Update: ContextListener is not standart class.更新: ContextListener 不是标准类。 However, it's easy to implement.但是,它很容易实现。 You can see how it's implemented in App info grails plugin here你可以在这里看到它是如何在App info grails 插件中实现的

@Taras and @Burt Thanks @Taras 和 @Burt 谢谢

I followed as both of you suggested in this answer.我按照你们两个在这个答案中的建议进行了操作。 Working fine.工作正常。

But invalidate mothod doesn't invalidate session and another user keeps on using application.但是无效方法不会使会话无效并且另一个用户继续使用应用程序。 I don't know why this weird behavior.我不知道为什么会有这种奇怪的行为。

So I used sessionToInvalidate.setMaxInactiveInterval(1) .所以我使用sessionToInvalidate.setMaxInactiveInterval(1) And this works as I expected.这符合我的预期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM