Grails与SpringSecurity,检查当前用户是否可以访问控制器/操作 [英] Grails with SpringSecurity, check if the current user can access controller / action
问题描述
我目前正在为我的应用程序开发一个菜单,它应该只能显示当前用户可以访问的控制器(在数据库中定义的requestmap)。
如何检查当前用户是否可以访问特定的控制器和操作?
检查视图中的角色:
Spring安全插件提供了ifAllGranted,ifAnyGranted,ifNoneGranted等标签来检查角色。例如,要查看登录用户的Admin Role:
< sec:ifLoggedIn>
< sec:ifAllGranted roles =ROLE_ADMIN>
管理资源
< / sec:ifAllGranted>
< / sec:ifLoggedIn>
(在grails-2.2.2和springSecurityCorePlugin-1.2.7.3中测试过)
I'm currently developing a menu for my application that should be able to display only the controllers that the current user can access (requestmap defined in the database).
How can I check if the current user has access to a specific controller and action?
To check roles in view : Spring security plugin provides ifAllGranted, ifAnyGranted, ifNoneGranted etc., tags to check roles
For example, to check Admin Role of logged in User :
<sec:ifLoggedIn>
<sec:ifAllGranted roles="ROLE_ADMIN">
Admin resource
</sec:ifAllGranted>
</sec:ifLoggedIn>
(tested in grails-2.2.2 and springSecurityCorePlugin-1.2.7.3)
这篇关于Grails与SpringSecurity,检查当前用户是否可以访问控制器/操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!