提交 | 用户 | 时间
|
e57a89
|
1 |
package com.jcdm.framework.web.service; |
懒 |
2 |
|
|
3 |
import java.util.HashSet; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Set; |
|
6 |
import org.springframework.beans.factory.annotation.Autowired; |
|
7 |
import org.springframework.stereotype.Component; |
|
8 |
import org.springframework.util.CollectionUtils; |
|
9 |
import com.jcdm.common.core.domain.entity.SysRole; |
|
10 |
import com.jcdm.common.core.domain.entity.SysUser; |
|
11 |
import com.jcdm.system.service.ISysMenuService; |
|
12 |
import com.jcdm.system.service.ISysRoleService; |
|
13 |
|
|
14 |
/** |
|
15 |
* 用户权限处理 |
|
16 |
* |
|
17 |
* @author jc |
|
18 |
*/ |
|
19 |
@Component |
|
20 |
public class SysPermissionService |
|
21 |
{ |
|
22 |
@Autowired |
|
23 |
private ISysRoleService roleService; |
|
24 |
|
|
25 |
@Autowired |
|
26 |
private ISysMenuService menuService; |
|
27 |
|
|
28 |
/** |
|
29 |
* 获取角色数据权限 |
|
30 |
* |
|
31 |
* @param user 用户信息 |
|
32 |
* @return 角色权限信息 |
|
33 |
*/ |
|
34 |
public Set<String> getRolePermission(SysUser user) |
|
35 |
{ |
|
36 |
Set<String> roles = new HashSet<String>(); |
|
37 |
// 管理员拥有所有权限 |
|
38 |
if (user.isAdmin()) |
|
39 |
{ |
|
40 |
roles.add("admin"); |
|
41 |
} |
|
42 |
else |
|
43 |
{ |
|
44 |
roles.addAll(roleService.selectRolePermissionByUserId(user.getUserId())); |
|
45 |
} |
|
46 |
return roles; |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* 获取菜单数据权限 |
|
51 |
* |
|
52 |
* @param user 用户信息 |
|
53 |
* @return 菜单权限信息 |
|
54 |
*/ |
|
55 |
public Set<String> getMenuPermission(SysUser user) |
|
56 |
{ |
|
57 |
Set<String> perms = new HashSet<String>(); |
|
58 |
// 管理员拥有所有权限 |
|
59 |
if (user.isAdmin()) |
|
60 |
{ |
|
61 |
perms.add("*:*:*"); |
|
62 |
} |
|
63 |
else |
|
64 |
{ |
|
65 |
List<SysRole> roles = user.getRoles(); |
|
66 |
if (!CollectionUtils.isEmpty(roles)) |
|
67 |
{ |
|
68 |
// 多角色设置permissions属性,以便数据权限匹配权限 |
|
69 |
for (SysRole role : roles) |
|
70 |
{ |
|
71 |
Set<String> rolePerms = menuService.selectMenuPermsByRoleId(role.getRoleId()); |
|
72 |
role.setPermissions(rolePerms); |
|
73 |
perms.addAll(rolePerms); |
|
74 |
} |
|
75 |
} |
|
76 |
else |
|
77 |
{ |
|
78 |
perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId())); |
|
79 |
} |
|
80 |
} |
|
81 |
return perms; |
|
82 |
} |
|
83 |
} |