本文介绍了等效于已弃用的< sec:authorize> ifNotGranted属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果用户没有特定角色,我想防止图像具有链接.例如
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>
但是现在不赞成使用ifNotGranted和ifAllGranted来支持访问表达式.我可以看到ifAllGranted可以复制为:
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>
但是如何使用访问方法复制ifNotGranted?任何帮助将不胜感激.
But how can ifNotGranted be replicated using the access method? Any help would be greatfully appreciated.
推荐答案
可以使用!
运算符来否定SpEL表达式:
SpEL expression can be negated with !
operator:
<sec:authorize access="!hasRole('ROLE_ACCOUNTS')">...</sec:authorize>
另请参见:
这篇关于等效于已弃用的< sec:authorize> ifNotGranted属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!