class JwtAuthenticationProvider extends TimeMeasuringAuthenticationProvider<AuthenticationResult> {

    @SuppressWarnings("ConstantConditions")
    private CompletableFuture<AuthenticationResult> getAuthenticationResult(final JsonWebToken jwt,
            final DittoHeaders dittoHeaders) {

        return jwtValidator.validate(jwt)
                .thenApply(validationResult -> {
                    if (!validationResult.isValid()) {
                        final Throwable reasonForInvalidity = validationResult.getReasonForInvalidity();
                        LOGGER.withCorrelationId(dittoHeaders).debug("The JWT is invalid.", reasonForInvalidity);
                        throw buildJwtUnauthorizedException(dittoHeaders, reasonForInvalidity);
                    }

                    final AuthenticationResult authenticationResult = tryToGetAuthenticationResult(jwt, dittoHeaders);
                    LOGGER.withCorrelationId(dittoHeaders).info("Completed JWT authentication successfully.");
                    return authenticationResult;
                });
    }

    private  JwtAuthenticationProvider(final JwtAuthenticationResultProvider jwtAuthenticationResultProvider,
            final JwtValidator jwtValidator);

}