I am newbie in Grails. I am using Spring Security Grails plugin for Authentication purpose. I want to get current user in my view gsp file.
I am trying like this ..
Another way would be to create a Filter and put the User in the request scope as part of the filter, like this:
class SetCurrentUserFilters {
def springSecurityService
def filters = {
all(controller: '*', action: '*') {
before = {
if (springSecurityService.isLoggedIn()){
request.setAttribute("current_user", springSecurityService.currentUser);
}
}
after = { Map model ->
}
afterView = { Exception e ->
}
}
}
}
Then your GSP just needs to look for the 'current_user' attribute, like this:
...