Reputation: 293
Since Spring Security Core Plugin is not currently working for Grails 3, I am trying to use Spring boot as indicated here for authorization. Please give some hint how to display current user's name in gsp. Is there any way to use Spring Security's tags in the gsp files. Thanks
Upvotes: 2
Views: 1359
Reputation: 5976
A tag library has access to the session
and can be used to display the current username.
In the GSP, put:
<g:username />
Then create a TagLib such as:
grails-app/taglib/SecurityTagLib.groovy
class SecurityTagLib {
def username = {
def token = session.SPRING_SECURITY_CONTEXT?.getAuthentication()
out << token?.getPrincipal()?.getUsername()
}
}
Upvotes: 3
Reputation: 589
I implemented stripped down versions of the SpringSecurityService
and SecurityTagLib
within my application, based on the latest Grails 2 plugin. Its a source based plugin, you can simply copy the required tags.
Upvotes: 0