手动注销另一个用户在Grails中 [英] Manually logout another user in grails

查看:122
本文介绍了手动注销另一个用户在Grails中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要以编程方式注销用户,而不是当前用户。我能够使其会话过期,但这不会强制该特定用户的注销。所以我的问题是,我如何强制注销用户的下一个请求?这是我现在的代码:

  sessionRegistry.getAllPrincipals()。each {
principal = it
sessionRegistry .getAllSessions(it,false).each {
if(principal.username == userSec.username){
it.expireNow()
}
}
}

我在我的resources.groovy中有这个:

  sessionRegistry(SessionRegistryImpl)
sessionAuthenticationStrategy(ConcurrentSessionControlStrategy,sessionRegistry){
maximumSessions = -1
}
concurrentSessionFilter(ConcurrentSessionFilter){
sessionRegistry = sessionRegistry
expiredUrl ='/ login / concurrentSession'
}


解决方案

使用会话机制是不可能的。您必须使用存储介质来保存用户。这个媒介可以是一个in-RAM单例,像 ConcurrentHashMap 实例或者一个DB,这取决于你的集群体系结构。



然后,在每次调用 springSecurityService.currentUser 时(例如在Spring Security核心插件中),您必须检查 sessionRegistry 包含该用户,如果不包含,则会话或用户无效。

In my application I need to programmatically logout a user, not the current one. I was able to expire its session but this does not force a logout for that specific user. So my question is, how can I force a logout on the user's next request? This is my code now:

sessionRegistry.getAllPrincipals().each {
   principal = it
   sessionRegistry.getAllSessions(it, false).each {
       if (principal.username == userSec.username) {
           it.expireNow()
       }
   }
}

I have this in my resources.groovy:

sessionRegistry(SessionRegistryImpl)
    sessionAuthenticationStrategy(ConcurrentSessionControlStrategy, sessionRegistry) {
        maximumSessions = -1
    }
    concurrentSessionFilter(ConcurrentSessionFilter){
        sessionRegistry = sessionRegistry
        expiredUrl = '/login/concurrentSession'
    }

解决方案

Using the session mechanismus it is not possible. You have to use a storage medium where you can keep the users. This medium can be either an in-RAM singleton, like ConcurrentHashMap instance, or a DB, depending on your clustering architecture.

Then upon each call to springSecurityService.currentUser (e.g. in Spring Security core plugin), you have to check if the sessionRegistry contains that user, and if not, invalidate the session or the user

这篇关于手动注销另一个用户在Grails中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆