mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-07-01 02:34:27 +08:00
修改权限获取方式
This commit is contained in:
@@ -20,6 +20,7 @@ package org.hswebframework.web.authorization;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -37,6 +38,21 @@ import java.util.Optional;
|
||||
*/
|
||||
public interface Authentication extends Serializable {
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户权限信息
|
||||
* <pre>
|
||||
*
|
||||
* Authentication auth= Authentication.current().get();
|
||||
* //如果权限信息不存在将抛出{@link NoSuchElementException}建议使用下面的方式获取
|
||||
* Authentication auth=Authentication.current().orElse(null);
|
||||
* //或者
|
||||
* Authentication auth=Authentication.current().orElseThrow(AuthorizeException::new);
|
||||
* </pre>
|
||||
*
|
||||
* @return 返回Optional对象进行操作
|
||||
* @see Optional
|
||||
* @see AuthenticationHolder
|
||||
*/
|
||||
static Optional<Authentication> current() {
|
||||
return Optional.ofNullable(AuthenticationHolder.get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user