✨ #863 权限扩展 pms.hasPermission('A','B') 支持多个权限标识判断
This commit is contained in:
1 parent
8f9ba8cb35
commit
cbef9c8ec6
1 file changed
+8
-8
+8
-8
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.component;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
@@ -37,13 +37,13 @@ import java.util.Collection;
|
||||
@Component("pms")
|
||||
public class PermissionService {
|
||||
/**
|
||||
* 判断接口是否有xxx:xxx权限
|
||||
* 判断接口是否有任意xxx,xxx权限
|
||||
*
|
||||
* @param permission 权限
|
||||
* @param permissions 权限
|
||||
* @return {boolean}
|
||||
*/
|
||||
public boolean hasPermission(String permission) {
|
||||
if (StrUtil.isBlank(permission)) {
|
||||
public boolean hasPermission(String... permissions) {
|
||||
if (ArrayUtil.isEmpty(permissions)) {
|
||||
return false;
|
||||
}
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
@@ -52,8 +52,8 @@ public class PermissionService {
|
||||
}
|
||||
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
|
||||
return authorities.stream()
|
||||
.map(GrantedAuthority::getAuthority)
|
||||
.filter(StringUtils::hasText)
|
||||
.anyMatch(x -> PatternMatchUtils.simpleMatch(permission, x));
|
||||
.map(GrantedAuthority::getAuthority)
|
||||
.filter(StringUtils::hasText)
|
||||
.anyMatch(x -> PatternMatchUtils.simpleMatch(permissions, x));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user