Spring Boot 2.1.5.RELEASE Spring Security 版本:5.1.5-RELEASE Spring Security 官方文档
· GrantedAuthority·
给用户授予最高级别权限,如:角色 或 作用域。GrantedAuthority
通过 Authentication.getAuthorities()
方法获取。Authentication.getAuthorities()
方法返回 GrantedAuthority
集合,使用 Collection 存放。毫无疑问, GrantedAuthority
存放的是授予委托人的权限。
这些权限通常是 “角色” ,如 ROLE_ADMINISTRATOR
或者 ROLE_HR_SUPERVISOR
。这些角色之后将配置到 web 授权、方法授权和对象授权。 当出些这些角色配置时,Spring Security 其他部分能够识别这些权限信息。当基于用户名密码的认证 GrantedAuthority
授权通常由 UserDetailsService
加载。
通常 GrantedAuthority
是应用程序范围的权限, GrantedAuthority
不是特定于给定的域对象。因此,通常会不给一个指定编号的 Employee 对象授予权限,因为如果存在多个 Employee ,上千万个 Employee ,内存直接被卡爆,或者权限权限无限延长。所以在使用 Spring Security 处理权限功能时,应该圈定范围内的域对象的权限。