public interface Authentication extends Serializable
AuthenticationHolder,
AuthenticationManager| 限定符和类型 | 方法和说明 |
|---|---|
static Optional<Authentication> |
current()
获取当前登录的用户权限信息
Authentication auth= Authentication.current().get();
//如果权限信息不存在将抛出
NoSuchElementException建议使用下面的方式获取
Authentication auth=Authentication.current().orElse(null);
//或者
Authentication auth=Authentication.current().orElseThrow(UnAuthorizedException::new);
|
<T extends Serializable> |
getAttribute(String name)
根据属性名获取属性值,返回一个
Optional对象。 |
Map<String,Serializable> |
getAttributes()
获取全部属性,此属性为通过
this#setAttribute(String, Serializable)或this#setAttributes(Map)设置的属性。 |
default Optional<Permission> |
getPermission(String id)
根据权限id获取权限信息,权限不存在则返回null
|
List<Permission> |
getPermissions() |
default Optional<Role> |
getRole(String id)
根据id获取角色,角色不存在则返回null
|
List<Role> |
getRoles() |
User |
getUser() |
default boolean |
hasPermission(String permissionId,
String... actions)
判断是否持有某权限以及对权限的可操作事件
|
default boolean |
hasRole(String roleId) |
<T extends Serializable> |
removeAttributes(String name)
删除属性,并返回被删除的值
|
void |
setAttribute(String name,
Serializable object)
设置一个属性值,如果属性名称已经存在,则将其覆盖。
|
void |
setAttributes(Map<String,Serializable> attributes)
设置多个属性值,参数为map类型,key为属性名称,value为属性值
|
static Optional<Authentication> current()
Authentication auth= Authentication.current().get();
//如果权限信息不存在将抛出NoSuchElementException建议使用下面的方式获取
Authentication auth=Authentication.current().orElse(null);
//或者
Authentication auth=Authentication.current().orElseThrow(UnAuthorizedException::new);
Optional,
AuthenticationHolderUser getUser()
List<Permission> getPermissions()
default Optional<Permission> getPermission(String id)
id - 权限iddefault boolean hasPermission(String permissionId, String... actions)
permissionId - 权限id Permission.getId()actions - 可操作事件 Permission.getActions() 如果为空,则不判断action,只判断permissionIddefault boolean hasRole(String roleId)
roleId - 角色id Role.getId()<T extends Serializable> Optional<T> getAttribute(String name)
Optional对象。T - 属性值类型name - 属性名void setAttribute(String name, Serializable object)
Serializable接口name - 属性名称object - 属性值AuthenticationManager.sync(Authentication)void setAttributes(Map<String,Serializable> attributes)
attributes - 属性值mapAuthenticationManager.sync(Authentication)<T extends Serializable> T removeAttributes(String name)
T - 被删除的值类型name - 属性名AuthenticationManager.sync(Authentication)Map<String,Serializable> getAttributes()
this#setAttribute(String, Serializable)或this#setAttributes(Map)设置的属性。Copyright © 2016–2020. All rights reserved.