从TagLib验证ifAnyGranted

tga*_*rey 5 grails taglib spring-security

我如何从TagLib验证"至少有一个角色被授予"?

所以,我想使用类似的东西:

<sec:ifAnyGranted roles="ROLE_ADMIN,ROLE_SUPERVISOR">
但是在我的TagLib的groovy文件中.

我正在使用Spring Security Core插件.

提前致谢!

Aar*_*ers 5

在taglib中使用以下代码:

class MyTagLib {

  def myTag = { attrs, body ->
      if (SpringSecurityUtils.ifAnyGranted("ROLE_ADMIN,ROLE_SUPERVISOR")) {
      // do your stuff...
      }
  }
}
Run Code Online (Sandbox Code Playgroud)