Skip to content

Commit

Permalink
Merge pull request quarkusio#20723 from stuartwdouglas/19835
Browse files Browse the repository at this point in the history
Prevent 'response already written' exception
  • Loading branch information
gsmet authored Oct 13, 2021
2 parents ff609cf + 1924766 commit d320c33
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import org.jboss.logging.Logger;

import io.quarkus.runtime.BlockingOperationControl;
import io.quarkus.runtime.ExecutorRecorder;
import io.quarkus.security.AuthenticationFailedException;
import io.quarkus.security.identity.IdentityProviderManager;
import io.quarkus.security.identity.SecurityIdentity;
import io.quarkus.security.spi.runtime.AuthorizationController;
Expand All @@ -26,6 +29,8 @@
@Singleton
public class HttpAuthorizer {

private static final Logger log = Logger.getLogger(HttpAuthorizer.class);

@Inject
HttpAuthenticator httpAuthenticator;

Expand Down Expand Up @@ -88,7 +93,6 @@ public void run() {
/**
* Checks that the request is allowed to proceed. If it is then {@link RoutingContext#next()} will
* be invoked, if not appropriate action will be taken to either report the failure or attempt authentication.
*
*/
public void checkPermission(RoutingContext routingContext) {
if (!controller.isAuthorizationEnabled()) {
Expand Down Expand Up @@ -137,7 +141,12 @@ public void accept(HttpSecurityPolicy.CheckResult checkResult) {
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) {
routingContext.fail(throwable);
if (!routingContext.response().ended()) {
routingContext.fail(throwable);
} else if (!(throwable instanceof AuthenticationFailedException)) {
//don't log auth failure
log.error("Exception occurred during authorization", throwable);
}
}
});
}
Expand Down

0 comments on commit d320c33

Please sign in to comment.