markmywords
markmywords

Reputation: 663

Grails: How to get information about the currently logged in user?

I am actually feeling a bit dumb for asking this but I tried for half a day now and can't find a way to get information on the currently logged in user in my controllers as well as my views.

I tried several suggestions I found on the web like "authenticateService" etc.

Now, it is possible that I have a misconception about the basics of Grails there. I come from other frameworks where a task like this is a matter of {{ request.user }} and I am done with it.

My exact need is to be able to access the ID of the currently logged in user in order to serve a custom navigation.

Thx in advance for your help.

Upvotes: 2

Views: 2912

Answers (2)

chelder
chelder

Reputation: 3897

Nowadays, I think the way to do it is:

def user = getAuthenticatedUser()

Upvotes: 2

hvgotcodes
hvgotcodes

Reputation: 120308

def user = springSecurityService.currentUser

always good to try the docs:

http://burtbeckwith.github.com/grails-spring-security-core/docs/manual/index.html

In gsps, there is a specific tag, which we use like

<sec:loggedInUserInfo field='firstName'/>

again, its in the docs posted above.

Upvotes: 4

Related Questions