You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.6 KiB
66 lines
1.6 KiB
package com.ruoyi.framework.security.service; |
|
|
|
import java.util.HashSet; |
|
import java.util.Set; |
|
import org.springframework.beans.factory.annotation.Autowired; |
|
import org.springframework.stereotype.Component; |
|
import com.ruoyi.project.system.domain.SysUser; |
|
import com.ruoyi.project.system.service.ISysMenuService; |
|
import com.ruoyi.project.system.service.ISysRoleService; |
|
|
|
/** |
|
* 用户权限处理 |
|
* |
|
* @author ruoyi |
|
*/ |
|
@Component |
|
public class SysPermissionService |
|
{ |
|
@Autowired |
|
private ISysRoleService roleService; |
|
|
|
@Autowired |
|
private ISysMenuService menuService; |
|
|
|
/** |
|
* 获取角色数据权限 |
|
* |
|
* @param user 用户信息 |
|
* @return 角色权限信息 |
|
*/ |
|
public Set<String> getRolePermission(SysUser user) |
|
{ |
|
Set<String> roles = new HashSet<String>(); |
|
// 管理员拥有所有权限 |
|
if (user.isAdmin()) |
|
{ |
|
roles.add("admin"); |
|
} |
|
else |
|
{ |
|
roles.addAll(roleService.selectRolePermissionByUserId(user.getUserId())); |
|
} |
|
return roles; |
|
} |
|
|
|
/** |
|
* 获取菜单数据权限 |
|
* |
|
* @param user 用户信息 |
|
* @return 菜单权限信息 |
|
*/ |
|
public Set<String> getMenuPermission(SysUser user) |
|
{ |
|
Set<String> roles = new HashSet<String>(); |
|
// 管理员拥有所有权限 |
|
if (user.isAdmin()) |
|
{ |
|
roles.add("*:*:*"); |
|
} |
|
else |
|
{ |
|
roles.addAll(menuService.selectMenuPermsByUserId(user.getUserId())); |
|
} |
|
return roles; |
|
} |
|
}
|
|
|