How to get current user role with spring security plugin?

前端 未结 6 1929
一个人的身影
一个人的身影 2020-12-29 05:21

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?

6条回答
  •  独厮守ぢ
    2020-12-29 05:50

    You can inject springSecurityService into your controller:

    def springSecurityService

    and then in your action, call:

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

    See the docs here.

提交回复
热议问题