Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access User object in grails controller

I'm using spring security, and I need to get the User domain object in a controller.

If I call SpringSecurityService.getPrincipal(), I get back an object of type org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser. However, what I'm looking for is the User domain object I've defined in my Config.groovy like so:

grails.plugins.springsecurity.userLookup.userDomainClassName = 'project.auth.User'

How can I best get at the User domain object?

like image 640
ataylor Avatar asked Sep 28 '10 22:09

ataylor


1 Answers

Load the user instance using the cached id in the GrailsUser instance:

def user = User.get(SpringSecurityService.principal.id)
like image 128
Burt Beckwith Avatar answered Oct 21 '22 14:10

Burt Beckwith