Grails menu with profiling
There are several grails menu plugins, for e开发者_StackOverflow中文版xample 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?
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>
精彩评论