mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 15:49:19 +08:00
feat(auth): Token 负载增加 companyRole 字段
1. TokenPayload/AccessTokenPayload 增加 companyRole 字段 2. JwtUtils 生成和解析 Token 时包含 companyRole 3. UserServiceImpl 登录时从 org_company_member 获取 companyRole 写入 Token 4. CurrentUserContext 增加 getCurrentCompanyRole() 方法从 Token 获取 5. RoleAspect/PermissionAspect 改用 Token 中的 companyRole 直接判断权限
This commit is contained in:
+5
-12
@@ -63,18 +63,11 @@ public class PermissionAspect {
|
||||
case "user":
|
||||
// 普通用户检查公司成员角色
|
||||
if (annotation.allowCompany()) {
|
||||
try {
|
||||
String memberRole = currentUserContext.getCurrentMemberRole();
|
||||
if ("owner".equals(memberRole)) {
|
||||
hasPermission = true;
|
||||
log.debug("权限验证 - 用户是公司拥有者,视为公司管理员");
|
||||
} else {
|
||||
hasPermission = annotation.allowUser() &&
|
||||
permissionCheckService.hasPermissionByPosition(positionId, annotation.value(), companyId);
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
// 无法获取公司成员角色,降为普通用户权限
|
||||
log.debug("无法获取公司成员角色: {}", e.getMessage());
|
||||
String companyRole = currentUserContext.getCurrentCompanyRole();
|
||||
if ("owner".equals(companyRole)) {
|
||||
hasPermission = true;
|
||||
log.debug("权限验证 - 用户是公司拥有者,视为公司管理员");
|
||||
} else {
|
||||
hasPermission = annotation.allowUser() &&
|
||||
permissionCheckService.hasPermissionByPosition(positionId, annotation.value(), companyId);
|
||||
}
|
||||
|
||||
+5
-11
@@ -58,17 +58,11 @@ public class RoleAspect {
|
||||
case "user":
|
||||
// 普通用户检查公司成员角色,如果是 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());
|
||||
String companyRole = currentUserContext.getCurrentCompanyRole();
|
||||
if ("owner".equals(companyRole)) {
|
||||
hasPermission = true;
|
||||
log.debug("角色权限验证 - 用户是公司拥有者,视为公司管理员");
|
||||
} else {
|
||||
hasPermission = annotation.allowUser();
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user