如何获得使用Spring Security插件当前用户的角色? [英] How to get current user role with spring security plugin?

查看:536
本文介绍了如何获得使用Spring Security插件当前用户的角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的Grails应用程序中的弹簧安全的核心插件。我需要知道当前用户控制器中的动作角色。我该如何找回呢?

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?

推荐答案

您可以注入 springSecurityService 到控制器:

DEF springSecurityService

,然后在你的行动,请拨打:

and then in your action, call:

DEF角色= springSecurityService.getPrincipal()。getAuthorities()

查看文档<一个href=\"http://grails-plugins.github.io/grails-spring-security-core/docs/manual/guide/index.html\">here.

这篇关于如何获得使用Spring Security插件当前用户的角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆