Jsp 相当于不推荐使用的<;第二节:授权>;如果未授予属性

Jsp 相当于不推荐使用的<;第二节:授权>;如果未授予属性,jsp,spring-security,jsp-tags,Jsp,Spring Security,Jsp Tags,如果用户没有特定的角色,我想防止图像具有链接。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"/><

如果用户没有特定的角色,我想防止图像具有链接。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>

但是,ifnotgrated和ifallgrated现在已被弃用,取而代之的是access表达式。我可以看出,IFAllGrassed可以通过以下方式复制:

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


但是如何使用访问方法复制ifnotgrant呢?任何帮助都将不胜感激。

可以使用
否定SpEL表达式操作员:

<sec:authorize access="!hasRole('ROLE_ACCOUNTS')">...</sec:authorize> 
。。。
另请参见:


如果您有许多文件需要更新,我建议使用常规express进行搜索和替换

发现


access=“isfullyaauthenticated()”而不是hasRole('ROLE_ACCOUNTS')”@Ritesh感谢
isfullyaauthenticated()
对于其他页面可能非常有用。但是,此处的页面访问仅对登录用户可用<代码>没有角色('ROLE\u ACCOUNTS')
成功了。
<sec:authorize\s+ifAnyGranted="([^"]+)"
<sec:authorize access="hasAnyRole('$1')"
<sec:authorize\s+ifNotGranted="([^"]+)"
<sec:authorize access="!hasAnyRole('$1')"