Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent to the deprecated <sec:authorize> ifNotGranted attribute

I would like to prevent an image having a link if a user does NOT have a certain role. e.g.

<sec:authorize ifNotGranted="ROLE_ACCOUNTS" ><img src="someimage.jpg"/></sec:authorize>
<sec:authorize ifAllGranted="ROLE_ACCOUNTS" ><a href="somelink.htm"><img src="someimage.jpg"/></a></sec:authorize>

However ifNotGranted and ifAllGranted are now deprecated in favour of the access expression. I can see that ifAllGranted can be replicated with:

<sec:authorize access="hasRole('ROLE_ACCOUNTS')"><a href="somelink.htm"><img src="someimage.jpg"/></a></sec:authorize>

But how can ifNotGranted be replicated using the access method? Any help would be greatfully appreciated.

like image 787
arontoms Avatar asked Jun 08 '12 17:06

arontoms


1 Answers

SpEL expression can be negated with ! operator:

<sec:authorize access="!hasRole('ROLE_ACCOUNTS')">...</sec:authorize> 

See also:

  • 6. Spring Language (SpEL)
like image 114
axtavt Avatar answered Sep 28 '22 05:09

axtavt