Springboot Security hasRole不起作用

Springboot Security hasRole不起作用,第1张

Springboot Security hasRole不起作用

你必须命名前缀你的权威

ROLE_
来使用
isUserInRole
,看到Spring
Security的参考

HttpServletRequest.isUserInRole(String)将确定是否

SecurityContextHolder.getContext().getAuthentication().getAuthorities()
包含
GrantedAuthority
具有传递给的角色
isUserInRole(String)
。通常,用户不应将“
ROLE_”前缀传递给此方法,因为它是自动添加的。例如,如果要确定当前用户是否具有权限“ ROLE_ADMIN”,则可以使用以下命令:

boolean isAdmin = httpServletRequest.isUserInRole("ADMIN");

hasRole
(也
hasAnyRole
)相同,请参见Spring Security
Reference

返回

true
当前委托人是否具有指定角色。默认情况下,如果提供的角色不是以“
ROLE_”开头,则会添加该角色。可以通过修改
defaultRolePrefix
on来自定义
DefaultWebSecurityexpressionHandler



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4879904.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-11
下一篇2022-11-11

发表评论

登录后才能评论

评论列表(0条)

    保存