Skip to content

Jwt#getNotBefore throws IllegalArgumentException when Date type #5192

Closed
@jzheaux

Description

@jzheaux

Summary

Nimbus coerces JWT temporal fields, that is exp, iat, and nbf, into java.util.Date.

NimbusJwtDecoderJwkSupport then takes the underlying Map<String, Object> from Nimbus and copies it into a Jwt.

Jwt, inheriting from ClaimsAccessor, anticipates this field to be a Long:

default Instant getClaimAsInstant(String claim) {
	if (!this.containsClaim(claim)) {
		return null;
	}

	try {
		return Instant.ofEpochMilli(Long.valueOf(this.getClaimAsString(claim)));
	} catch (NumberFormatException ex) {
		throw new IllegalArgumentException("Unable to convert claim '" + claim + "' to Instant: " + ex.getMessage(), ex);
	}
}

Thus, when a Jwt is created from a Nimbus-parsed JWT, calling this method results in an IllegalArgumentException.

Actual Behavior

NimbusJwtDecoderJwkSupport decoder = // ... instance
Jwt jwt = decoder.decode(token);
jwt.getNotBefore() <== throws IllegalArgumentException

Expected Behavior

It would not throw said exception

Version

5.1.0.M1

Metadata

Metadata

Assignees

Labels

in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions