Skip to content

Commit

Permalink
Merge pull request #167 from quarkiverse/fix/exception-failures
Browse files Browse the repository at this point in the history
Replace calls to abortWith to thrown exceptions to allow exception mapping to occur for authentication failures
  • Loading branch information
kdubb authored Sep 28, 2024
2 parents 16e4ba2 + 13f8cd3 commit a378b56
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.quarkiverse.zanzibar.jaxrs;

import static jakarta.ws.rs.core.Response.Status.FORBIDDEN;
import static jakarta.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;

import java.time.Duration;
import java.util.Optional;

import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ForbiddenException;
import jakarta.ws.rs.InternalServerErrorException;

import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.server.spi.ResteasyReactiveContainerRequestContext;
Expand All @@ -33,7 +31,7 @@ public void filter(ResteasyReactiveContainerRequestContext context) {
var checkOpt = prepare(context);

if (checkOpt.isEmpty()) {
context.abortWith(Response.status(FORBIDDEN).build());
context.resume(new ForbiddenException());
return;
}

Expand All @@ -54,17 +52,16 @@ public void filter(ResteasyReactiveContainerRequestContext context) {

if (!allowed) {

context.abortWith(Response.status(FORBIDDEN).build());
}
context.resume(new ForbiddenException());
} else {

context.resume();
context.resume();
}

}, (x) -> {
log.error("Authorization check failed", x);

context.abortWith(Response.status(INTERNAL_SERVER_ERROR).build());

context.resume();
context.resume(new InternalServerErrorException(x));
});
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package io.quarkiverse.zanzibar.jaxrs;

import static jakarta.ws.rs.core.Response.Status.FORBIDDEN;
import static jakarta.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;

import java.time.Duration;
import java.util.Optional;

import jakarta.ws.rs.ForbiddenException;
import jakarta.ws.rs.InternalServerErrorException;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ContainerRequestFilter;
import jakarta.ws.rs.core.Response;

import org.jboss.logging.Logger;

Expand All @@ -32,8 +30,7 @@ public void filter(ContainerRequestContext context) {
var checkOpt = prepare(context);

if (checkOpt.isEmpty()) {
context.abortWith(Response.status(FORBIDDEN).build());
return;
throw new ForbiddenException();
}
var check = checkOpt.get();

Expand All @@ -47,15 +44,14 @@ public void filter(ContainerRequestContext context) {
log.debugf("Authorization %s", allowed ? "allowed" : "disallowed");

if (!allowed) {
context.abortWith(Response.status(FORBIDDEN).build());
throw new ForbiddenException();
}

} catch (Throwable x) {

log.error("Authorization check failed", x);

context.abortWith(Response.status(INTERNAL_SERVER_ERROR).build());

throw new InternalServerErrorException(x);
}
}
}

0 comments on commit a378b56

Please sign in to comment.