Skip to content

Commit 312a0ce

Browse files
authored
fix(amber): return 403 instead of 401 when a user lacks access to an execution (apache#9325)
### What changes were proposed in this PR? `validateUserCanAccessExecutions` now throws `ForbiddenException` (403) instead of a 401. The frontend reads any 401 on an authenticated request as an expired session, so a read-only user who bookmarked, renamed or deleted an execution was logged out. With a 403 they stay logged in. Bookmark puts its icon back on a refusal. Rename and delete have no error handler, so they fail without a message; that is left out of this PR to keep it small. ### Any related issues, documentation, discussions? Closes apache#9324. ### How was this PR tested? Added a read-only bookmark case to `WorkflowExecutionsResourceSpec`, and the refusal cases now assert 403. Ran `sbt "WorkflowExecutionService/testOnly *UserQuotaResourceSpec *WorkflowExecutionsResourceSpec"`: 84 of 85 pass. The other one, the per-user warehouse case of `retrieveWorkflowRuntimeStatistics`, fails the same way locally on unmodified `main`. Putting the 401 back fails the four cases this PR touches. Not clicked through in a running instance. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (claude-opus-5-5)
1 parent 0549ece commit 312a0ce

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResource.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ object WorkflowExecutionsResource {
8989
): Unit = {
9090
eids.distinct.foreach { eid =>
9191
if (!userCanAccessExecution(uid, eid, requireWrite)) {
92-
throw new WebApplicationException(Response.Status.UNAUTHORIZED)
92+
throw new ForbiddenException("No sufficient access privilege.")
9393
}
9494
}
9595
}

‎amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/quota/UserQuotaResourceSpec.scala‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,10 @@ class UserQuotaResourceSpec extends AnyFlatSpec with BeforeAndAfterAll with Mock
378378
otherUser.setName("otherUser")
379379
otherUser.setEmail("otherUser-" + UUID.randomUUID().toString.substring(0, 8) + "@example.com")
380380

381-
intercept[WebApplicationException] {
381+
val refused = intercept[WebApplicationException] {
382382
resource.deleteCollection(execution.getEid, new SessionUser(otherUser))
383383
}
384+
assert(refused.getResponse.getStatus == 403)
384385

385386
assert(workflowExecutionsDao.fetchOneByEid(execution.getEid) != null)
386387
}

‎amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResourceSpec.scala‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ class WorkflowExecutionsResourceSpec
699699
requireWrite = true
700700
)
701701

702-
intercept[WebApplicationException] {
702+
intercept[ForbiddenException] {
703703
WorkflowExecutionsResource.validateUserCanAccessExecutions(
704704
otherUserUid,
705705
Seq(eid),
@@ -1309,14 +1309,26 @@ class WorkflowExecutionsResourceSpec
13091309

13101310
"setExecutionAreBookmarked" should "reject a user without access" in {
13111311
val exec = insertExecution()
1312-
assertThrows[WebApplicationException](
1312+
assertThrows[ForbiddenException](
13131313
resource.setExecutionAreBookmarked(
13141314
ExecutionGroupBookmarkRequest(testWorkflowWid, Array(exec.getEid), isBookmarked = false),
13151315
session(userWithoutAccess())
13161316
)
13171317
)
13181318
}
13191319

1320+
it should "refuse a read-only user with 403, since the frontend logs out on 401" in {
1321+
grantReadAccess()
1322+
val exec = insertExecution()
1323+
assertThrows[ForbiddenException](
1324+
resource.setExecutionAreBookmarked(
1325+
ExecutionGroupBookmarkRequest(testWorkflowWid, Array(exec.getEid), isBookmarked = false),
1326+
session(testUser)
1327+
)
1328+
)
1329+
assert(workflowExecutionsDao.fetchOneByEid(exec.getEid).getBookmarked == false)
1330+
}
1331+
13201332
it should "bookmark executions that are currently un-bookmarked" in {
13211333
grantWriteAccess()
13221334
val exec = insertExecution() // bookmarked = false

0 commit comments

Comments
 (0)