mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-05-22 17:07:12 +08:00
优化同时存在角色和权限控制的逻辑
This commit is contained in:
@@ -201,7 +201,10 @@ public class DefaultAuthorizingHandler implements AuthorizingHandler {
|
||||
Function<Predicate<Role>, Boolean> func = logicalIsOr
|
||||
? authentication.getRoles().stream()::anyMatch
|
||||
: authentication.getRoles().stream()::allMatch;
|
||||
access = func.apply(role -> rolesDef.contains(role.getId()));
|
||||
|
||||
access = logicalIsOr
|
||||
? access || func.apply(role -> rolesDef.contains(role.getId()))
|
||||
: access && func.apply(role -> rolesDef.contains(role.getId()));
|
||||
}
|
||||
//控制用户
|
||||
if (!usersDef.isEmpty()) {
|
||||
@@ -211,7 +214,10 @@ public class DefaultAuthorizingHandler implements AuthorizingHandler {
|
||||
Function<Predicate<String>, Boolean> func = logicalIsOr
|
||||
? usersDef.stream()::anyMatch
|
||||
: usersDef.stream()::allMatch;
|
||||
access = func.apply(authentication.getUser().getUsername()::equals);
|
||||
access = logicalIsOr
|
||||
? access || func.apply(authentication.getUser().getUsername()::equals)
|
||||
: access && func.apply(authentication.getUser().getUsername()::equals);
|
||||
|
||||
}
|
||||
if (!access) {
|
||||
throw new AccessDenyException(definition.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user