How to get current user role with spring security plugin?

前端 未结 6 1887
一个人的身影
一个人的身影 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:57

    If you simply need to check to see if a user is in a specific role then use SpringSecurityUtils.ifAllGranted which takes a single String as an argument which contains a comma-delimited list of roles. It will return true if the current user belongs to all of them. SpringSecurityUtils also has methods like ifAnyGranted, ifNotGranted, etc, so it should work for whatever it is you are trying to accomplish.

提交回复
热议问题