mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 02:39:19 +08:00
fix(auth): RoleAspect 支持公司拥有者权限
公司拥有者的 sys_user.role 为 user,但 org_company_member.role 为 owner 修改 RoleAspect,当 sys_user.role 为 user 时额外检查公司成员角色 如果用户是公司拥有者( owner ),则视为公司管理员( allowCompany )
This commit is contained in:
+29
-12
@@ -38,20 +38,20 @@ public class RoleAspect {
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
|
||||
// 获取当前用户角色
|
||||
String role = currentUserContext.getCurrentUserPayload().getRole();
|
||||
// 获取当前用户系统角色
|
||||
String sysRole = currentUserContext.getCurrentUserPayload().getRole();
|
||||
|
||||
log.debug("角色权限验证 - 用户角色: {}, 注解配置: {}", role, annotation.description());
|
||||
log.debug("角色权限验证 - 用户系统角色: {}, 注解配置: {}", sysRole, annotation.description());
|
||||
|
||||
// 检查角色是否为空
|
||||
if (role == null) {
|
||||
// 检查系统角色是否为空
|
||||
if (sysRole == null) {
|
||||
throw new BusinessException("用户角色信息缺失");
|
||||
}
|
||||
|
||||
// 根据角色进行权限验证
|
||||
// 根据系统角色进行权限验证
|
||||
boolean hasPermission = false;
|
||||
|
||||
switch (role) {
|
||||
switch (sysRole) {
|
||||
case "super":
|
||||
hasPermission = annotation.allowSuper();
|
||||
break;
|
||||
@@ -59,23 +59,40 @@ public class RoleAspect {
|
||||
hasPermission = annotation.allowCompany();
|
||||
break;
|
||||
case "user":
|
||||
hasPermission = annotation.allowUser();
|
||||
// 普通用户检查公司成员角色,如果是 owner 则视为公司管理员
|
||||
if (annotation.allowCompany()) {
|
||||
try {
|
||||
String memberRole = currentUserContext.getCurrentMemberRole();
|
||||
if ("owner".equals(memberRole)) {
|
||||
hasPermission = true;
|
||||
log.debug("角色权限验证 - 用户是公司拥有者,视为公司管理员");
|
||||
} else {
|
||||
hasPermission = annotation.allowUser();
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
// 无法获取公司成员角色,降为普通用户权限
|
||||
log.debug("无法获取公司成员角色: {}", e.getMessage());
|
||||
hasPermission = annotation.allowUser();
|
||||
}
|
||||
} else {
|
||||
hasPermission = annotation.allowUser();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException("未知的用户角色: " + role);
|
||||
throw new BusinessException("未知的用户角色: " + sysRole);
|
||||
}
|
||||
|
||||
// 检查是否在允许的角色列表中
|
||||
if (annotation.value().length > 0) {
|
||||
hasPermission = hasPermission && Arrays.asList(annotation.value()).contains(role);
|
||||
hasPermission = hasPermission && Arrays.asList(annotation.value()).contains(sysRole);
|
||||
}
|
||||
|
||||
if (!hasPermission) {
|
||||
log.warn("角色权限验证失败 - 用户角色: {}, 描述: {}", role, annotation.description());
|
||||
log.warn("角色权限验证失败 - 用户系统角色: {}, 描述: {}", sysRole, annotation.description());
|
||||
throw new BusinessException("权限不足: " + annotation.description());
|
||||
}
|
||||
|
||||
log.debug("角色权限验证通过 - 用户角色: {}", role);
|
||||
log.debug("角色权限验证通过 - 用户系统角色: {}", sysRole);
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
/tmp/ecom-target
|
||||
Reference in New Issue
Block a user