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)
已过时。
|
Map<String,Serializable> |
getAttributes()
已过时。
|
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)
已过时。
|
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()@Deprecated <T extends Serializable> Optional<T> getAttribute(String name)
Optional对象。T - 属性值类型name - 属性名@Deprecated void setAttribute(String name, Serializable object)
Serializable接口name - 属性名称object - 属性值AuthenticationManager.sync(Authentication)@Deprecated void setAttributes(Map<String,Serializable> attributes)
attributes - 属性值mapAuthenticationManager.sync(Authentication)@Deprecated <T extends Serializable> T removeAttributes(String name)
T - 被删除的值类型name - 属性名AuthenticationManager.sync(Authentication)@Deprecated Map<String,Serializable> getAttributes()
this#setAttribute(String, Serializable)或this#setAttributes(Map)设置的属性。Copyright © 2018. All rights reserved.