ataylor
ataylor

Reputation: 66069

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?

Upvotes: 5

Views: 3090

Answers (1)

Burt Beckwith
Burt Beckwith

Reputation: 75671

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

def user = User.get(SpringSecurityService.principal.id)

Upvotes: 8

Related Questions