5

如何从 TagLib 中验证“至少授予了一个角色”?

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

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

我正在使用Spring Security Core 插件

提前致谢!

4

2 回答 2

5

在您的 taglib 中使用以下代码:

class MyTagLib {

  def myTag = { attrs, body ->
      if (SpringSecurityUtils.ifAnyGranted("ROLE_ADMIN,ROLE_SUPERVISOR")) {
      // do your stuff...
      }
  }
}
于 2010-10-06T13:23:48.287 回答
0

在您的 taglib 中使用以下代码:

class MyTagLib {
  def springSecurityService // injected by Spring

  def myTag = { attrs, body ->
      def loggedIn = springSecurityService.loggedIn
  }
}
于 2010-10-06T09:07:22.690 回答