Jan
Jan

Reputation: 3401

Grails & spring security getting the id of the current logged in user

This is a sample code for the getCurrentUser() method in Spring Security service.

class SomeController {
    def springSecurityService

    def someAction() {
    def user = springSecurityService.currentUser
   }
}

How do you get the id of the logged in user and use it in this <g:link action="show" controller="User" id="">Show Profile</g:link>

Upvotes: 0

Views: 173

Answers (2)

Burt Beckwith
Burt Beckwith

Reputation: 75671

In general it's available in the "principal", which is an instance of GrailsUser, so the most efficient way is springSecurityService.principal.id

Upvotes: 3

lukelazarovic
lukelazarovic

Reputation: 1500

In controller:

springSecurityService.currentUser.id

Upvotes: 1

Related Questions