I am using the spring-security-core plugin in my grails app. I need to know the current user\'s role in a controller action. How can I retrieve that?
From a controller you can use two methods the plugin adds to the metaclass, getPrincipal and isLoggedIn:
getPrincipal
isLoggedIn
def myAction = { if (loggedIn) { // will be a List of String def roleNames = principal.authorities*.authority } }
If the action is secured you can skip the loggedIn/isLoggedIn() check.
loggedIn
isLoggedIn()