mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-19 01:48:47 +08:00
feat(权限管理): 修复 sa-token 查询指定用户角色权限时 返回当前登录人角色权限的bug
- 在通用角色服务 RoleService 接口中添加 selectRoleKeysByUserId 方法,用于查询用户角色权限 - 完善 SaPermissionImpl 类中的 getRoleList 方法的查询逻辑 - 在 SysRoleServiceImpl 类中实现 selectRoleKeysByUserId 方法,返回用户角色权限映射
This commit is contained in:
parent
2b89c3f8d0
commit
36f5c30c92
@ -1,10 +1,18 @@
|
|||||||
package org.dromara.common.core.service;
|
package org.dromara.common.core.service;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用 角色服务
|
* 通用 角色服务
|
||||||
*
|
*
|
||||||
* @author AprilWind
|
* @author AprilWind
|
||||||
*/
|
*/
|
||||||
public interface RoleService {
|
public interface RoleService {
|
||||||
|
/**
|
||||||
|
* 根据用户ID查询角色权限
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return 角色权限 roleKey:roleName
|
||||||
|
*/
|
||||||
|
Map<String, String> selectRoleKeysByUserId(Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,14 @@ package org.dromara.common.satoken.core.service;
|
|||||||
import cn.dev33.satoken.stp.StpInterface;
|
import cn.dev33.satoken.stp.StpInterface;
|
||||||
import org.dromara.common.core.domain.model.LoginUser;
|
import org.dromara.common.core.domain.model.LoginUser;
|
||||||
import org.dromara.common.core.enums.UserType;
|
import org.dromara.common.core.enums.UserType;
|
||||||
|
import org.dromara.common.core.service.RoleService;
|
||||||
|
import org.dromara.common.core.utils.SpringUtils;
|
||||||
import org.dromara.common.satoken.utils.LoginHelper;
|
import org.dromara.common.satoken.utils.LoginHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sa-token 权限管理实现类
|
* sa-token 权限管理实现类
|
||||||
@ -36,6 +40,25 @@ public class SaPermissionImpl implements StpInterface {
|
|||||||
@Override
|
@Override
|
||||||
public List<String> getRoleList(Object loginId, String loginType) {
|
public List<String> getRoleList(Object loginId, String loginType) {
|
||||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||||
|
|
||||||
|
if (loginId != null) {
|
||||||
|
// 查询指定用户权限
|
||||||
|
if (loginId instanceof Long) {
|
||||||
|
Long selectUserId = (Long) loginId;
|
||||||
|
Long userId = null;
|
||||||
|
if (loginUser != null) {
|
||||||
|
userId = loginUser.getUserId();
|
||||||
|
}
|
||||||
|
if (!selectUserId.equals(userId)) {
|
||||||
|
// 查询的不是当前登录用户 那么查询数据库指定用户的权限
|
||||||
|
RoleService roleService = SpringUtils.getBean("sysRoleServiceImpl");
|
||||||
|
Map<String, String> roleKeysByUserId = roleService.selectRoleKeysByUserId(selectUserId);
|
||||||
|
Set<String> roleKeySet = roleKeysByUserId.keySet();
|
||||||
|
return new ArrayList<>(roleKeySet);
|
||||||
|
} // else 查询的是当前登录用户 走原来的逻辑
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UserType userType = UserType.getUserType(loginUser.getUserType());
|
UserType userType = UserType.getUserType(loginUser.getUserType());
|
||||||
if (userType == UserType.SYS_USER) {
|
if (userType == UserType.SYS_USER) {
|
||||||
return new ArrayList<>(loginUser.getRolePermission());
|
return new ArrayList<>(loginUser.getRolePermission());
|
||||||
|
|||||||
@ -40,6 +40,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色 业务层处理
|
* 角色 业务层处理
|
||||||
@ -97,6 +98,18 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
|
|||||||
return baseMapper.selectRolesByUserId(userId);
|
return baseMapper.selectRolesByUserId(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户ID查询角色权限
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return 角色权限 roleKey:roleName
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<String, String> selectRoleKeysByUserId(Long userId) {
|
||||||
|
List<SysRoleVo> sysRoleVos = baseMapper.selectRolesByUserId(userId);
|
||||||
|
return sysRoleVos.stream().collect(Collectors.toMap(SysRoleVo::getRoleKey, SysRoleVo::getRoleName));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户ID查询角色列表(包含被授权状态)
|
* 根据用户ID查询角色列表(包含被授权状态)
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user