Q:

getting Principal during Grails Spring Security authentication

I'm wrapping up an implementation of Spring Security in Grails.  This is my first implementation on Spring Security- previously I used Acegi.
Here's the problem I'm having.  In Acegi, I was able to retrieve the authenticated user in the onInteractiveAuthenticationSuccessEvent() callback by accessing the SecurityContextHolder, getting the user principle, and then getting the 'live' User from the database.  In Spring Security, the SecurityContextHolder does not seem to be available- when I try to access it, I get low level Grails complaints about no such method on such and such object.
So, my questions:

How can I access SecurityContextHolder from onInteractiveAuthenticationSuccessEvent
Or is there a better way of getting the authenticated principle?

Thanks,
Dan

A:

You may need to update the import - it changed from Spring Security 2 to 3 - it's now org.springframework.security.core.context.SecurityContextHolder but the methods haven't changed.
But it's cleaner to use springSecurityService, which is accessible from the event callback using the appCtx variable:
onInteractiveAuthenticationSuccessEvent = { e, appCtx ->
   def principal = appCtx.springSecurityService.principal
   def user = User.get(principal.id)
}

