How to get current user role with spring security plugin?

laxmi picture laxmi · Jun 24, 2011 · Viewed 22.9k times · Source

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?

Answer

Mike Sickler picture Mike Sickler · Jun 24, 2011

You can inject springSecurityService into your controller:

def springSecurityService

and then in your action, call:

def roles = springSecurityService.getPrincipal().getAuthorities()

See the docs here.