1package dev.rafex.ether.jwt.internal;
3import java.time.Instant;
31import com.fasterxml.jackson.databind.JsonNode;
33import dev.rafex.ether.jwt.JwtConfig;
34import dev.rafex.ether.jwt.TokenClaims;
35import dev.rafex.ether.jwt.TokenType;
36import dev.rafex.ether.jwt.VerificationCode;
45public final class TokenValidator {
47 private TokenValidator() {
61 final Instant now,
final String tokenTypeRaw) {
63 if (
config.requireSubject() && isBlank(claims.subject())) {
67 if (
config.validateExpiration()) {
68 if (claims.expiresAt() ==
null) {
71 if (now.isAfter(claims.expiresAt().plus(
config.clockSkew()))) {
74 }
else if (
config.requireExpiration() && claims.expiresAt() ==
null) {
78 if (
config.validateNotBefore() && claims.notBefore() !=
null) {
79 if (now.plus(
config.clockSkew()).isBefore(claims.notBefore())) {
84 final String expectedIssuer =
config.expectedIssuer();
85 if (expectedIssuer !=
null && !expectedIssuer.equals(claims.issuer())) {
89 if (!
config.expectedAudience().isEmpty()) {
90 boolean matches =
false;
91 for (
final String value : claims.audience()) {
92 if (
config.expectedAudience().contains(value)) {
102 if (tokenTypeRaw !=
null && claims.tokenType() ==
null) {
106 if (claims.tokenType() ==
TokenType.
APP &&
config.requireClientIdForAppTokens() && isBlank(claims.clientId())) {
113 private static boolean isBlank(
final String value) {
114 return value ==
null || value.isBlank();
Configures JWT signing and verification behavior.
Normalized claims extracted from a JWT token.
static VerificationCode validate(final TokenClaims claims, final JsonNode payload, final JwtConfig config, final Instant now, final String tokenTypeRaw)
Valida las reclamaciones (claims) del token según la configuración.
Supported business token types.
Stable verification error/success codes.
Typed configuration entry points and composition APIs for Ether applications.