Search code examples
grailsgrails-plugintaglib

Using Grails taglibs inside GSPs


Please note: Even though I'm using the Grails-Shiro plugin here, this is a pure Grails taglib question, so should be answerable by anybody who is familiar with Grails taglibs and GSPs, regardless of their experience with this particular plugin.


Grails 2.4.5 here. I'd like to use some tags inside my GSP to determine if the authenticated user has a permission (string) with a value of 'app_admin'. Something like:

<g:if test="${authenticated_user_has_permission('app_admin')}">
    <!-- A bunch of HTML here, but only for admins! -->
</g:if>

This Grails-Shiro plugin defines a hasPermission tag that I think I could use, but not sure how. My attempt at:

<g:if test="${shiro.hasPermission('app_admin')}">
    <!-- A bunch of HTML here, but only for admins! -->
</g:if>

...failed miserably. Any ideas how I could use this plugin-provided tag as part of my permission check?


Solution

  • never used shiro, but common sense tells me to use something like:

    <shiro:hasPermission permission="app_admin">
      ....
    </shiro:hasPermission>
    

    you can not use <g:if> here, as shiro tags do not return anything