Skip to content

Commit

Permalink
bugfix in JwtAuthenticationDirective: extract the cause from Completi…
Browse files Browse the repository at this point in the history
…onException, otherwise GatewayAuthenticationFailedException will not be detected and handled as expected

Signed-off-by: Daniel Fesenmeyer <daniel.fesenmeyer@bosch-si.com>
  • Loading branch information
danielFesenmeyer committed May 2, 2018
1 parent b0f76bb commit fd8599d
Showing 1 changed file with 8 additions and 4 deletions.
Expand Up @@ -20,6 +20,7 @@
import java.security.PublicKey;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletionException;
import java.util.function.Function;
import java.util.function.Supplier;

Expand Down Expand Up @@ -128,18 +129,21 @@ public Route authenticate(final String correlationId, final Function<Authorizati
return authContext;
})
).exceptionally(t -> {
if (t instanceof GatewayAuthenticationFailedException) {
final Throwable rootCause =
(t instanceof CompletionException) ? t.getCause() : t;
if (rootCause instanceof GatewayAuthenticationFailedException) {
traceContext.rename(TRACE_FILTER_AUTH_JWT_FAIL);
traceContext.finish();

final DittoRuntimeException e = (DittoRuntimeException) t;
final DittoRuntimeException e = (DittoRuntimeException) rootCause;
LOGGER.debug("JWT authentication failed.", e);
throw e;
} else {
traceContext.finish();

LOGGER.warn("Unexpected error during JWT authentication.", t);
throw buildAuthenticationProviderUnavailableException(correlationId, t);
LOGGER.warn("Unexpected error during JWT authentication.", rootCause);
throw buildAuthenticationProviderUnavailableException(correlationId,
rootCause);
}
}),
inner);
Expand Down

0 comments on commit fd8599d

Please sign in to comment.