fix(workspace): return 403 instead of 500 for cross-workspace access

This commit is contained in:
matevip 2026-05-19 20:06:50 +08:00
parent 0a57cb3358
commit 651d53050e
6 changed files with 7 additions and 7 deletions

View File

@ -139,7 +139,7 @@ public class AgentBindingController {
} }
long requestedWs = headerWorkspaceId != null ? headerWorkspaceId : 1L; long requestedWs = headerWorkspaceId != null ? headerWorkspaceId : 1L;
if (agent.getWorkspaceId() != null && !agent.getWorkspaceId().equals(requestedWs)) { if (agent.getWorkspaceId() != null && !agent.getWorkspaceId().equals(requestedWs)) {
throw new MateClawException("err.common.wrong_workspace", "资源不属于当前工作区"); throw new MateClawException("err.common.wrong_workspace", 403, "资源不属于当前工作区");
} }
} }
} }

View File

@ -270,7 +270,7 @@ public class AgentController {
private void verifyResourceWorkspace(Long resourceWorkspaceId, Long headerWorkspaceId) { private void verifyResourceWorkspace(Long resourceWorkspaceId, Long headerWorkspaceId) {
long requestedWs = headerWorkspaceId != null ? headerWorkspaceId : 1L; long requestedWs = headerWorkspaceId != null ? headerWorkspaceId : 1L;
if (resourceWorkspaceId != null && !resourceWorkspaceId.equals(requestedWs)) { if (resourceWorkspaceId != null && !resourceWorkspaceId.equals(requestedWs)) {
throw new MateClawException("err.common.wrong_workspace", "资源不属于当前工作区"); throw new MateClawException("err.common.wrong_workspace", 403, "资源不属于当前工作区");
} }
} }

View File

@ -236,7 +236,7 @@ public class ChannelController {
private void verifyResourceWorkspace(Long resourceWorkspaceId, Long headerWorkspaceId) { private void verifyResourceWorkspace(Long resourceWorkspaceId, Long headerWorkspaceId) {
long requestedWs = headerWorkspaceId != null ? headerWorkspaceId : 1L; long requestedWs = headerWorkspaceId != null ? headerWorkspaceId : 1L;
if (resourceWorkspaceId != null && !resourceWorkspaceId.equals(requestedWs)) { if (resourceWorkspaceId != null && !resourceWorkspaceId.equals(requestedWs)) {
throw new MateClawException("err.common.wrong_workspace", "资源不属于当前工作区"); throw new MateClawException("err.common.wrong_workspace", 403, "资源不属于当前工作区");
} }
} }
} }

View File

@ -62,7 +62,7 @@ public class DashboardController {
if (job != null && job.getWorkspaceId() != null) { if (job != null && job.getWorkspaceId() != null) {
long wsId = workspaceId != null ? workspaceId : 1L; long wsId = workspaceId != null ? workspaceId : 1L;
if (!job.getWorkspaceId().equals(wsId)) { if (!job.getWorkspaceId().equals(wsId)) {
throw new MateClawException("err.common.wrong_workspace", "资源不属于当前工作区"); throw new MateClawException("err.common.wrong_workspace", 403, "资源不属于当前工作区");
} }
} }
return R.ok(cronJobRunService.listByJobId(cronJobId, Math.min(limit, 100))); return R.ok(cronJobRunService.listByJobId(cronJobId, Math.min(limit, 100)));

View File

@ -622,7 +622,7 @@ public class WikiController {
} }
long wsId = headerWorkspaceId != null ? headerWorkspaceId : 1L; long wsId = headerWorkspaceId != null ? headerWorkspaceId : 1L;
if (kb.getWorkspaceId() != null && !kb.getWorkspaceId().equals(wsId)) { if (kb.getWorkspaceId() != null && !kb.getWorkspaceId().equals(wsId)) {
throw new MateClawException("err.common.wrong_workspace", "资源不属于当前工作区"); throw new MateClawException("err.common.wrong_workspace", 403, "资源不属于当前工作区");
} }
} }
} }

View File

@ -263,14 +263,14 @@ public class WikiTransformationController {
} }
long wsId = workspaceId != null ? workspaceId : 1L; long wsId = workspaceId != null ? workspaceId : 1L;
if (kb.getWorkspaceId() != null && !kb.getWorkspaceId().equals(wsId)) { if (kb.getWorkspaceId() != null && !kb.getWorkspaceId().equals(wsId)) {
throw new MateClawException("err.common.wrong_workspace", "Resource does not belong to current workspace"); throw new MateClawException("err.common.wrong_workspace", 403, "Resource does not belong to current workspace");
} }
} }
private void verifyTemplateWorkspace(WikiTransformationEntity t, Long workspaceId) { private void verifyTemplateWorkspace(WikiTransformationEntity t, Long workspaceId) {
long wsId = workspaceId != null ? workspaceId : 1L; long wsId = workspaceId != null ? workspaceId : 1L;
if (t.getWorkspaceId() != null && !t.getWorkspaceId().equals(wsId)) { if (t.getWorkspaceId() != null && !t.getWorkspaceId().equals(wsId)) {
throw new MateClawException("err.common.wrong_workspace", "Resource does not belong to current workspace"); throw new MateClawException("err.common.wrong_workspace", 403, "Resource does not belong to current workspace");
} }
} }
} }