Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verify ifAnyGranted from a TagLib

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!

like image 772
tgarrey Avatar asked Oct 06 '10 08:10

tgarrey


1 Answers

Use the following code in your taglib:

class MyTagLib {

  def myTag = { attrs, body ->
      if (SpringSecurityUtils.ifAnyGranted("ROLE_ADMIN,ROLE_SUPERVISOR")) {
      // do your stuff...
      }
  }
}
like image 75
Aaron Saunders Avatar answered Nov 03 '22 19:11

Aaron Saunders