WangHan
2024-09-12 d5855a4926926698b740bc6c7ba489de47adb68b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package tech.powerjob.server.auth.service.permission;
 
import tech.powerjob.server.auth.Permission;
import tech.powerjob.server.auth.Role;
import tech.powerjob.server.auth.RoleScope;
 
import java.util.List;
import java.util.Map;
import java.util.Set;
 
/**
 * PowerJob 鉴权服务
 *
 * @author tjq
 * @since 2024/2/11
 */
public interface PowerJobPermissionService {
 
 
    /**
     * 判断用户是否有访问权限
     * @param userId userId
     * @param roleScope 权限范围
     * @param target 权限目标ID
     * @param permission 要求的权限
     * @return 是否有权限
     */
    boolean hasPermission(Long userId, RoleScope roleScope, Long target, Permission permission);
 
    /**
     * 授予用户角色
     * @param roleScope 权限范围
     * @param target 权限目标
     * @param userId 用户ID
     * @param role 角色
     * @param extra 其他
     */
    void grantRole(RoleScope roleScope, Long target, Long userId, Role role, String extra);
 
    /**
     * 回收用户角色
     * @param roleScope 权限范围
     * @param target 权限目标
     * @param userId 用户ID
     * @param role 角色
     */
    void retrieveRole(RoleScope roleScope, Long target, Long userId, Role role);
 
    /**
     * 获取有相关权限的用户
     * @param roleScope 角色范围
     * @param target 目标
     * @return 角色对应的用户列表,user 可能重复,需要用 SET 去重(save APP/namespace 等场景,创建人自动被授权成为 ADMIN,如果用户在面板将自己添加到管理员,就会存在2套授权机制2次授权出现重复)
     */
    Map<Role, Set<Long>> fetchUserWithPermissions(RoleScope roleScope, Long target);
 
    /**
     * 获取用户有权限的目标
     * @param roleScope 角色范围
     * @param userId 用户ID
     * @return result
     */
    Map<Role, List<Long>> fetchUserHadPermissionTargets(RoleScope roleScope, Long userId);
}