5

I want to display the info about the user logged in like his details etc given during sign up ...how to do it ?? As iam new to grails plz help! iam using Spring security plugin

ruheen
  • 51
  • 1
  • 1
  • 2
  • What do you think about using the search field above? See [this question](http://stackoverflow.com/questions/775053) for further information. – aiolos Apr 24 '12 at 08:15

3 Answers3

14

Well you can use the springSecurityService to get some user information in a controller:

    class MyController {
      def springSecurityService

      def myAction() {
        def principal = springSecurityService.principal
        String username = principal.username
        ...
      }
     }

Or in a gsp

    <sec:loggedInUserInfo field="username" />

It is a pretty general question.

Kelly
  • 3,709
  • 4
  • 20
  • 31
  • I know this is an old post but... I found it and it lead me to google and find this: http://grails-plugins.github.io/grails-spring-security-core/docs/manual/guide/helperClasses.html#securityTagLib – buzzsawddog Apr 14 '14 at 17:21
11

Define (in a controller, or service where you need user id):

SpringSecurityService springSecurityService

and try:

springSecurityService.currentUser.id //loads user from db, and returns its id

or:

springSecurityService.principal.id //if you need just id
Igor Artamonov
  • 35,450
  • 10
  • 82
  • 113
1

add this @the top of your service or controller class

def securityService

this returns the cuureent user id.

securityService.currentUser.id 
abdul
  • 1,531
  • 1
  • 14
  • 29