使用 Spring Security,我们使用 hasAuthority 有条件地执行代码或有条件地在 jsp 中显示部分页面。
例如:
@PreAuthorize("hasAuthority('ROLE_TELLER')")
public Account post(Account account, double amount);
}
或者(在jsp中)
<sec:authorize access="hasAuthority('TAG_SAVE')">
.... content to display / evaluate
</sec:authorize>
我想知道当您想要在没有权限的情况下显示/执行某些内容时如何处理这种情况。
可能是这样的
doesNotHaveAuthority('TAG_SAVE')
我很确定,这不是一个突然的用例。 有人以任何方式处理这个问题吗?
最佳答案
居然发现这个可以用EL。 所以使用 !标志作品。
所以我的工作是这样的:
<sec:authorize access="!hasAuthority('TAG_SAVE')">
.... content to display / evaluate when the Authority is not present
</sec:authorize>
关于spring-security - 在Spring Security中如何处理NOT hasAuthority,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38021502/