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
Asked
Active
Viewed 1.5k times
3 Answers
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
-
1Fully qualified class name is `grails.plugin.springsecurity.SpringSecurityService` – Brice Roncace Apr 06 '14 at 23:25
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