Skip to content

Commit

Permalink
Fixes duplicated stop of timer
Browse files Browse the repository at this point in the history
Signed-off-by: Klem Yannic (INST/ECS1) <Yannic.Klem@bosch-si.com>
  • Loading branch information
Yannic92 committed Jul 10, 2018
1 parent ceab120 commit 7d914a1
Showing 1 changed file with 6 additions and 9 deletions.
Expand Up @@ -107,10 +107,10 @@ public Route authenticate(final String correlationId, final Function<Authorizati
DirectivesLoggingUtils.enhanceLogWithCorrelationId(correlationId,
() -> {
final PublicKey publicKey = publicKeyOpt
.orElseThrow(() -> buildJwtUnauthorizedException(correlationId,
timer));
.orElseThrow(
() -> buildJwtUnauthorizedException(correlationId));

validateToken(jwt, publicKey, correlationId, timer);
validateToken(jwt, publicKey, correlationId);

final List<AuthorizationSubject> authSubjects =
authorizationSubjectsProvider
Expand Down Expand Up @@ -155,22 +155,19 @@ private static DittoRuntimeException buildMissingJwtException(final String corre
}

private void validateToken(final JsonWebToken authorizationToken, final PublicKey publicKey,
final String correlationId, final StartedTimer timer) {
final String correlationId) {
final DefaultJwtParser defaultJwtParser = new DefaultJwtParser();

try {
defaultJwtParser.setSigningKey(publicKey).parse(authorizationToken.getToken());
} catch (final ExpiredJwtException | MalformedJwtException | SignatureException | IllegalArgumentException e) {
LOGGER.info("Got Exception '{}' during parsing JWT: {}", e.getClass().getSimpleName(), e.getMessage(),
e);
throw buildJwtUnauthorizedException(correlationId, timer);
throw buildJwtUnauthorizedException(correlationId);
}
}

private static DittoRuntimeException buildJwtUnauthorizedException(final String correlationId,
final StartedTimer timer) {
timer.tag(TracingTags.AUTH_SUCCESS, false)
.stop();
private static DittoRuntimeException buildJwtUnauthorizedException(final String correlationId) {

return GatewayAuthenticationFailedException.newBuilder("The JWT could not be verified")
.description("Check if your token is not expired and set the token accordingly.")
Expand Down

0 comments on commit 7d914a1

Please sign in to comment.