In grails, how do I get a reference to all current sessions?

一曲冷凌霜 提交于 2020-01-30 04:41:39

问题


I'd like to list all current sessions in an Admin Controller in grails. What's the easiest way to get a reference to e.g. a Collection of sessions from the controller?


回答1:


This is a feature (disabled by default but easily enabled by setting grails.plugins.appinfo.useContextListener = true in Config.groovy) of the App-Info plugin: http://grails.org/plugin/app-info




回答2:


there is a "groovy" way to do this without a SessionListener, there are events generated that closures can be assigned to. You can capture successful sessions, in a map/list, and remove sessions from after logout or

Registering Callback Closures

rails.plugins.springsecurity.useSecurityEventListener = true
grails.plugins.springsecurity.onInteractiveAuthenticationSuccessEvent = { e, appCtx ->
   // handle InteractiveAuthenticationSuccessEvent
}

grails.plugins.springsecurity.onAbstractAuthenticationFailureEvent = { e, appCtx ->
   // handle AbstractAuthenticationFailureEvent
}

grails.plugins.springsecurity.onAuthenticationSuccessEvent = { e, appCtx ->
   // handle AuthenticationSuccessEvent
}

grails.plugins.springsecurity.onAuthenticationSwitchUserEvent = { e, appCtx ->
   // handle AuthenticationSwitchUserEvent
}

grails.plugins.springsecurity.onAuthorizationEvent = { e, appCtx ->
   // handle AuthorizationEvent
}


来源:https://stackoverflow.com/questions/3683231/in-grails-how-do-i-get-a-reference-to-all-current-sessions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!