gpt4 book ai didi

java - 为什么默认的Spring Security策略是AffirmativeBased?

转载 作者:行者123 更新时间:2023-11-30 08:38:04 24 4
gpt4 key购买 nike

来自spring security docs对于 AccessDecisionManager:

The default strategy is to use an AffirmativeBased AccessDecisionManager with a RoleVoter and an AuthenticatedVoter.

AffirmativeBased选民:

grants access if any AccessDecisionVoter returns an affirmative response

根据文档,RoleVoter 将根据经过身份验证的对象是否具有正确的 ROLE_ 权限进行投票,而 AuthenticatedVoter 将根据对象是否经过身份验证进行投票。

我的困惑是,AuthenticatedVoter 对象对什么进行投票?在我的应用程序中,我只希望具有 ROLE_USER 的人访问资源。但是我还在我的 AbstractAuthenticationToken 实现上设置了 setAuthenticated(true)。

通过阅读文档,AffirmativeBased 策略只需要经过身份验证即可访问资源,并且不会为 ROLE 要求而烦恼。是否有实际检查的不同“已验证”值?

我知道 UnanimousBased 策略,但似乎我还没有理解经过身份验证的测试,否则默认实现中会有很大的安全漏洞。

最佳答案

配置授权时,您提供配置属性,例如 hasRole('admin')。在投票过程中,选民将检查是否支持,否则将弃权。在 AuthenticatedVoter 的情况下,如果访问配置为 Role,它将放弃投票。查看 vote method 的源代码.

关于java - 为什么默认的Spring Security策略是AffirmativeBased?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36759726/

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