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?
Asked
Active
Viewed 3,213 times
2 Answers
10
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

Burt Beckwith
- 75,342
- 5
- 143
- 156
-
@Burt Excellent Plugin, that I never knew about... will definitely investigate today – Aaron Saunders Sep 10 '10 at 13:59
-
Looks very promising! However I'm getting the following error when trying to run after install: "Error: The following plugins failed to load due to missing dependencies: [appInfo] - Plugin: appInfo, Dependencies: [dynamicController, googleVisualization, jquery]" I found some discussions on that but none solved my problem. The stated plugins are all installed and listed in application.xml, I deleted .ivy2 and re-installed but I still get the error... using STS 2.3.3.M2 with grails 1.3.4. Can you point me in some direction? – Jörg Brenninkmeyer Sep 15 '10 at 07:26
-
Are you already using one of the dynamicController, googleVisualization, or jquery plugins? – Burt Beckwith Sep 15 '10 at 14:35
-
I installed all of them for your plug-in, however I'm only using the jquery plug-in in my project. – Jörg Brenninkmeyer Sep 17 '10 at 06:29
-
I reinstalled everything on Linux and got it working now. The plug-in is cool, but no sessions are listed in Info / Sessions, even when I log on with another user in another browser. What could be the reason for this? I'm using shiro security if it matters. I did NOT set grails.plugins.appinfo.useContextListener = false. – Jörg Brenninkmeyer Nov 11 '10 at 10:10
-
It's false by default - you need to set it to true. – Burt Beckwith Nov 11 '10 at 17:08
-
Great, now it works - I thought I'd read the opposite somewhere... ;-) Thank you for the great plug-in! Now I can also use your grails.plugins.appinfo.ScopesInfoService to show the number of users "online" via scopesInfoService.getSessionsInfo().size() – Jörg Brenninkmeyer Nov 25 '10 at 11:49
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
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
}

Aaron Saunders
- 33,180
- 5
- 60
- 80