<commit_before>package com.mercateo.spring.security.jwt.verifier;

import java.util.Optional;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@AllArgsConstructor
@Slf4j
public class WrappedJWTVerifier {

    public static final String WRAPPED_TOKEN_KEY = "jwt";

    private final Optional<JWTVerifier> verifier;

    public void verifyIfPresent(String tokenString) {
        if (!verifier.isPresent()) {
            return;
        }

        DecodedJWT token = JWT.decode(tokenString);

        while (true) {
            if (token.getAlgorithm() != null) {
                verifyIfPresent(token);
            }

            final Claim wrappedTokenClaim = token.getClaim(WRAPPED_TOKEN_KEY);
            if (wrappedTokenClaim.isNull()) {
                break;
            } else {
                token = JWT.decode(wrappedTokenClaim.asString());
            }
        }
    }

    private void verifyIfPresent(DecodedJWT token) {
        verifier.ifPresent(verifier -> {
            log.info("verify token");
            verifier.verify(token.getToken());
        });
    }
}<commit_msg>clean up log output<commit_after>package com.mercateo.spring.security.jwt.verifier;

import java.util.Optional;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class WrappedJWTVerifier {

    public static final String WRAPPED_TOKEN_KEY = "jwt";

    private final Optional<JWTVerifier> verifier;

    public WrappedJWTVerifier(Optional<JWTVerifier> verifier) {
        this.verifier = verifier;

        log.info("use verifier {}", verifier);
    }

    public void verifyIfPresent(String tokenString) {
        if (!verifier.isPresent()) {
            return;
        }

        DecodedJWT token = JWT.decode(tokenString);

        while (true) {
            if (token.getAlgorithm() != null) {
                verifyIfPresent(token);
            }

            final Claim wrappedTokenClaim = token.getClaim(WRAPPED_TOKEN_KEY);
            if (wrappedTokenClaim.isNull()) {
                break;
            } else {
                token = JWT.decode(wrappedTokenClaim.asString());
            }
        }
    }

    private void verifyIfPresent(DecodedJWT token) {
        verifier.ifPresent(verifier -> {
            log.debug("verify token with id {}", token.getId());
            verifier.verify(token.getToken());
        });
    }
}
{'fraction_non_alphanumeric': 0.1054421768707483, 'fraction_numerical': 0.005291005291005291, 'mean_word_length': 2.3548795944233207, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7153798', 'n_tokens_mistral': 838, 'n_tokens_neox': 813, 'n_words': 141}