mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 13:09:19 +08:00
fix: 修复权限相关问题
This commit is contained in:
+13
-20
@@ -16,11 +16,10 @@ import java.lang.reflect.Method;
|
||||
/**
|
||||
* 权限验证切面
|
||||
* 用于拦截带有@RequirePermission注解的方法并进行权限验证
|
||||
*
|
||||
* 权限判定逻辑:
|
||||
* - super 角色:直接放行(拥有所有权限)
|
||||
* - company 角色:检查公司是否有该权限(同 user 逻辑,但只做公司级校验)
|
||||
* - user 角色:从 org_position_permission 表查询岗位拥有的权限码进行判定,同时需要公司有该权限
|
||||
* - super:按 allowSuper 放行
|
||||
* - user + owner:仅校验平台分配给公司的权限(org_company_permission),不校验岗位
|
||||
* - user + member:公司权限 + 岗位权限双校验
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@@ -47,11 +46,12 @@ public class PermissionAspect {
|
||||
|
||||
// 获取当前用户信息
|
||||
String role = currentUserContext.getCurrentUserPayload().getRole();
|
||||
String companyRole = currentUserContext.getCurrentUserPayload().getCompanyRole();
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
Long positionId = currentUserContext.getCurrentUserPayload().getPositionId();
|
||||
|
||||
log.debug("权限验证 - 用户角色: {}, 公司ID: {}, 岗位ID: {}, 权限码: {}",
|
||||
role, companyId, positionId, annotation.value());
|
||||
log.debug("权限验证 - 用户角色: {}, 公司角色: {}, 公司ID: {}, 岗位ID: {}, 权限码: {}",
|
||||
role, companyRole, companyId, positionId, annotation.value());
|
||||
|
||||
// 检查角色是否为空
|
||||
if (role == null) {
|
||||
@@ -66,24 +66,17 @@ public class PermissionAspect {
|
||||
// 超级管理员拥有所有权限
|
||||
hasPermission = annotation.allowSuper();
|
||||
break;
|
||||
case "company":
|
||||
// 公司管理员角色,检查公司是否有该权限
|
||||
// company 角色实际上是 member 中的 owner,有公司级权限
|
||||
// 走 user 逻辑,使用 positionId
|
||||
if (positionId != null) {
|
||||
case "user":
|
||||
// owner:拥有平台分配给该公司的全部权限(不含岗位细分)
|
||||
if ("owner".equalsIgnoreCase(companyRole)) {
|
||||
hasPermission = permissionCheckService.hasCompanyAssignedPermission(
|
||||
companyId, annotation.value());
|
||||
} else {
|
||||
// member 走公司+岗位双校验
|
||||
hasPermission = permissionCheckService.hasPermissionByPosition(
|
||||
positionId, annotation.value(), companyId);
|
||||
} else {
|
||||
// 如果没有职位,至少检查公司是否有权限
|
||||
hasPermission = false;
|
||||
}
|
||||
break;
|
||||
case "user":
|
||||
// 普通用户从 org_position_permission 表查询权限码进行判定
|
||||
// 同时需要公司有该权限(两级校验)
|
||||
hasPermission = permissionCheckService.hasPermissionByPosition(
|
||||
positionId, annotation.value(), companyId);
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException("未知的用户角色: " + role);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user