我的grails应用程序中有一些 Controller :
LoginController
LogoutController
SearchableController
cirnele.SearchAllController
com.ten.cirnelle.domain.CustomerController
com.ten.cirnelle.domain.ProjectController
com.ten.cirnelle.domain.PurchaseOrderController
com.ten.cirnelle.domain.QuotationController
com.ten.cirnelle.domain.ResourceController
在Config.groovy中,我提供了一种配置:
cirnelleControllerExclusions =['Login','Search','Searchable','Resource']
从main.gsp,我正在使用:-
<g:each var="c" in="${grailsApplication.controllerClasses.sort { it.fullName } }">
<g:if test="${grailsApplication.config.cirnelleControllerExclusions.contains(c.naturalName.split()[0]) == false}">
<li class="controller"><g:link controller="${c.logicalPropertyName}">${c.naturalName.split()[0]}</g:link></li>
</g:if>
</g:each>
此代码用于在每个 View 页面的顶部提供类似于菜单的结构,并且不包括4个cotrollers,我在Config.groovy中指定要在 View 页面中显示为链接。
但是我有许多角色不同的用户
ROLE_PM
ROLE_SALES/BDM
ROLE_TEAMMEMBER
ROLE_ADMIN
我的要求是,如果具有管理员角色的用户登录,那么他可以将所有 Controller 视为链接(4除外),但是如果具有PM角色的用户登录,则他不能查看CustomerController链接和QuotationCotroller链接。
所以我该如何自定义main.gsp以根据用户角色显示菜单链接。
谢谢
最佳答案
尝试使用spring security plugin。有一些标签可用于执行您想要的操作。
<sec:ifNotLoggedIn>
<g:link controller="login" action="auth">Login</g:link>
</sec:ifNotLoggedIn>
<sec:ifAllGranted roles="ROLE_USER">
<g:link class="create" controller="post" action="timeline">My Timeline</g:link>
</sec:ifAllGranted>
关于grails - 在gsp中定制链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9188824/