public static OAuthBearerValidationResult validateClaimForExistenceAndType(OAuthBearerUnsecuredJws jwt,
            boolean required, String claimName, Class<?>... allowedTypes) {
        Object rawClaim = Objects.requireNonNull(jwt).rawClaim(Objects.requireNonNull(claimName));
        if (rawClaim == null)
            return required
                    ? OAuthBearerValidationResult.newFailure(String.format("Required claim missing: %s", claimName))
                    : OAuthBearerValidationResult.newSuccess();
        for (Class<?> allowedType : allowedTypes) {
            if (allowedType != null && allowedType.isAssignableFrom(rawClaim.getClass()))
                return OAuthBearerValidationResult.newSuccess();
        }
        return OAuthBearerValidationResult.newFailure(String.format("The %s claim had the incorrect type: %s",
                claimName, rawClaim.getClass().getSimpleName()));
    }
Validate the given claim for existence and type. It can be required to exist
in the given claims, and if it exists it must be one of the types indicated

@param jwt
           the mandatory JWT to which the validation will be applied
@param required
           true if the claim is required to exist
@param claimName
           the required claim name identifying the claim to be checked
@param allowedTypes
           one or more of {@code String.class}, {@code Number.class}, and
           {@code List.class} identifying the type(s) that the claim value is
           allowed to be if it exists
@return the result of the validation
clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/unsecured/OAuthBearerValidationUtils.java