开发者

Verify ifAnyGranted from a TagLib

开发者 https://www.devze.com 2023-01-19 08:33 出处:网络
How I can verify that开发者_开发百科 \"at least one of the roles is granted\" from a TagLib? So, I want to use something like:

How I can verify that开发者_开发百科 "at least one of the roles is granted" from a TagLib?

So, I want to use something like:

<sec:ifAnyGranted roles="ROLE_ADMIN,ROLE_SUPERVISOR">
but in the groovy file of my TagLib.

I am using Spring Security Core plugin.

Thanks in advance!


Use the following code in your taglib:

class MyTagLib {

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


Use the following code in your taglib:

class MyTagLib {
  def springSecurityService // injected by Spring

  def myTag = { attrs, body ->
      def loggedIn = springSecurityService.loggedIn
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消