for checking multiple Roles?-6ren"> for checking multiple Roles?-我想使用 Spring Security JSP 标签库根据角色有条件地显示一些内容。但是在 Spring Security 3.1.x 中只检查一个角色。 我可以使用,但 ifAllGranted -6ren">
gpt4 book ai didi

java - 如何使用 for checking multiple Roles?

转载 作者:IT老高 更新时间:2023-10-28 13:03:54 28 4
gpt4 key购买 nike

我想使用 Spring Security JSP 标签库根据角色有条件地显示一些内容。但是在 Spring Security 3.1.x 中只检查一个角色。

我可以使用,但 ifAllGranted 已弃用。

有什么帮助吗?

最佳答案

spring security中有一个特殊的安全表达式:

hasAnyRole(list of roles) - true if the user has been granted any of the roles specified (given as a comma-separated list of strings).

我从未使用过它,但我认为它正是您想要的。

示例用法:

<security:authorize access="hasAnyRole('ADMIN', 'DEVELOPER')">
...
</security:authorize>

这里是 link to the reference documentation其中描述了标准的 Spring 安全表达式。另外,这里是 discussion我在其中描述了如何根据需要创建自定义表达式。

关于java - 如何使用 <sec :authorize access ="hasRole(' ROLES)"> for checking multiple Roles?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11469211/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com