Skip to content

Commit

Permalink
bugfix(jax-rs): unauthenticated vs. authorized HTTP response codes we…
Browse files Browse the repository at this point in the history
…re flipped - fixed
  • Loading branch information
lprimak committed May 20, 2024
1 parent 9531508 commit 1b2d26f
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 1b2d26f

Please sign in to comment.