带有分析功能的 Grails 菜单

发布于 2024-10-09 08:36:34 字数 104 浏览 0 评论 0原文

有几个 grails 菜单插件,例如导航插件。我需要仅向用户显示他可以根据其用户配置文件访问的那些菜单项。实现这一目标的最简单方法是什么?有没有可以与某些 grails 安全插件集成的菜单插件?

There are several grails menu plugins, for example the Navigation plugin. I need to show to user only those menu items that he can access according to his user profile. What is the easiest way to accomplish this? Is there a menu plugin that can integrate with some of grails security plugins?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听不够的曲调 2024-10-16 08:36:34

导航插件有一个使用isVisible有条件隐藏菜单项的示例。如果您使用 Spring Security 插件,那么您可以将其与 SpringSecurityUtils 或注入的 SpringSecurityService bean:

def springSecurityService
// ...
static navigation = [
    [group:'userOptions', action:'login', order: 0, isVisible: { SpringSecurityUtils.ifAllGranted('ROLE_ADMIN') }],
    [action:'logout', order: 99, isVisible: { springSecurityService.isLoggedIn() }]
]

或者,Spring security 附带 一些标签 仅当用户/尚未登录,具有什么角色等,因此您可以像这样手动滚动菜单项:

<sec:ifAllGranted roles="ROLE_ADMIN">
  // Render <g:link../> to an admin page here.
</sec:ifAllGranted>

The navigation plugin has an example of using isVisible to conditionally hide menu items. If you're using the Spring Security plugin, then you could combine this with methods on the SpringSecurityUtils or on the injected SpringSecurityService bean:

def springSecurityService
// ...
static navigation = [
    [group:'userOptions', action:'login', order: 0, isVisible: { SpringSecurityUtils.ifAllGranted('ROLE_ADMIN') }],
    [action:'logout', order: 99, isVisible: { springSecurityService.isLoggedIn() }]
]

Alternatively, Spring security comes with some tags that will render the tag body only if the user is/is not logged in, with what roles, etc., so you could just hand roll your menu items like this:

<sec:ifAllGranted roles="ROLE_ADMIN">
  // Render <g:link../> to an admin page here.
</sec:ifAllGranted>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文