Templates 了解renderEditor.template中登录的用户的任何方法
我的问题是:在renderditor.template中是否有任何方法可以知道用户登录了什么以及他拥有什么角色Templates 了解renderEditor.template中登录的用户的任何方法,templates,grails,groovy,spring-security,Templates,Grails,Groovy,Spring Security,我的问题是:在renderditor.template中是否有任何方法可以知道用户登录了什么以及他拥有什么角色 我想做的是:在我的应用程序中,当登录用户是管理员(“角色\管理员”)时,我想更改一些字段-普通用户将有一个选项,默认情况下为选中的是html选择标记,当管理员用户将登录时,将显示所有用户的列表 我使用的是SpringSecurity插件+Grails2.1.1 我已经尝试过的: 添加Spring安全服务(def springSecurityService),但它始终为空 尝试传递布尔参
我想做的是:在我的应用程序中,当登录用户是管理员(“角色\管理员”)时,我想更改一些字段-普通用户将有一个选项,默认情况下为选中的是html选择标记,当管理员用户将登录时,将显示所有用户的列表
我使用的是SpringSecurity插件+Grails2.1.1 我已经尝试过的:
def springSecurityService
),但它始终为空私有RenderManyTone(域类,属性){
if(物业协会){
def sb=新的StringBuilder()
sb有一个带有spring security的taglib
在我的应用程序中,我是这样使用它的:
<ul>
<sec:access expression="hasRole('ROLE_ADMIN')">
<li><a href="#newFeedModal" role="button">Add New Feed</a></li>
</sec:access>
</ul>
通常的GSP模板引擎无法呈现renderditor.template
模板。它是使用标准的SimpleTemplateEngine
呈现的,只需几个简单的绑定。但是,此模板的输出随后会使用GSP模板引擎呈现。这相当混乱,但您可以使用renderditor.templateate
输出GSP代码。例如:
<% if (property.type == Boolean || property.type == boolean)
out << renderBooleanEditor(domainClass, property)
else ...
else if (property.type == String && domainInstance == 'specialField') {
out << '''<g:if test="${org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils.ifAllGranted('ROLE_ADMIN')}">'''
out << renderStringEditor(domainClass, property)
out << '''</g:if>'''
out << '''<g:else>'''
out << renderStringSelectEditor(domainClass, property)
out << '''</g:else>'''
}
...
<% if (property.type == Boolean || property.type == boolean)
out << renderBooleanEditor(domainClass, property)
else ...
else if (property.type == String && domainInstance == 'specialField') {
out << '''<g:if test="${org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils.ifAllGranted('ROLE_ADMIN')}">'''
out << renderStringEditor(domainClass, property)
out << '''</g:if>'''
out << '''<g:else>'''
out << renderStringSelectEditor(domainClass, property)
out << '''</g:else>'''
}
...