grails - 在gsp中定制链接

标签 grails groovy

我的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/

相关文章:

grails - ipRestrictions在Grails 3.3.10中不起作用?

spring-test、groovy 库和限定符标签不兼容

java - 获取两个 arrayList 之间的差异,但以大写形式比较它们

java - Groovy Spock 与 java 测试类

ajax - 在Grails中应用服务器端Javascript验证

java - 使用 Gradle 构建 uberjar

grails - Grails-如何查询列表

hibernate - Grails:乐观锁定,StaleObjectStateException与Spring Security session 中的域,更新计数器

grails - 如何在 resources.groovy 中使用抽象父 bean 创建 bean?

java - 电子邮件发送 Python 到 Java 转换