views:

39

answers:

3

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?

A: 

I don't think you can, at least not immediately. You should register an HttpSessionListener and fill a HashMap (in the ServletContext) with all the sessions, when they are registered (and remove them, when they expire)

Bozho
+1  A: 

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
}
Aaron Saunders
+4  A: 

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
@Burt Excellent Plugin, that I never knew about... will definitely investigate today
Aaron Saunders
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?
werner5471
Are you already using one of the dynamicController, googleVisualization, or jquery plugins?
Burt Beckwith
I installed all of them for your plug-in, however I'm only using the jquery plug-in in my project.
werner5471

related questions