Skip to content

Commit

Permalink
Merge pull request #1487 from lprimak/jaxrs-response-flipped
Browse files Browse the repository at this point in the history
[#1383] bugfix(jax-rs): unauthenticated vs. authorized HTTP response codes we…
  • Loading branch information
lprimak committed May 21, 2024
2 parents 9531508 + 1b2d26f commit 7f7743d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void testGetUsersUnauthenticated() {
final Response usersResponse = usersTarget.request(MediaType.APPLICATION_JSON_TYPE)
.buildGet()
.invoke();
assertEquals(Status.FORBIDDEN.getStatusCode(), usersResponse.getStatus());
assertEquals(Status.UNAUTHORIZED.getStatusCode(), usersResponse.getStatus());
}

@SuppressWarnings({"checkstyle:MagicNumber"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public Response toResponse(UnauthenticatedException exception) {
LOG.debug("unauthenticated.", exception);
}

return Response.status(Status.FORBIDDEN).build();
return Response.status(Status.UNAUTHORIZED).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public class UnauthorizedExceptionExceptionMapper implements ExceptionMapper<Una
public Response toResponse(UnauthorizedException exception) {

if (LOG.isDebugEnabled()) {
LOG.debug("unauthenticated.", exception);
LOG.debug("unauthorized.", exception);
}

return Response.status(Status.UNAUTHORIZED).build();
return Response.status(Status.FORBIDDEN).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class UnauthorizedExceptionExceptionMapperTest {

@Test
void testUnauthorizedException() {
doTest(new UnauthorizedException("expected test exception."), Response.Status.UNAUTHORIZED, new UnauthorizedExceptionExceptionMapper())
doTest(new HostUnauthorizedException("expected test exception."), Response.Status.UNAUTHORIZED, new UnauthorizedExceptionExceptionMapper())
doTest(new UnauthenticatedException("expected test exception."), Response.Status.FORBIDDEN, new UnauthenticatedExceptionExceptionMapper())
doTest(new UnauthorizedException("expected test exception."), Response.Status.FORBIDDEN, new UnauthorizedExceptionExceptionMapper())
doTest(new HostUnauthorizedException("expected test exception."), Response.Status.FORBIDDEN, new UnauthorizedExceptionExceptionMapper())
doTest(new UnauthenticatedException("expected test exception."), Response.Status.UNAUTHORIZED, new UnauthenticatedExceptionExceptionMapper())
}

private static void doTest(AuthorizationException exception, Response.StatusType expectedStatus, ExceptionMapper<? extends Throwable> exceptionMapper) {
Expand Down

0 comments on commit 7f7743d

Please sign in to comment.