The Claims interface in the jjwt library (io.jsonwebtoken.Claims) is a map-like view of a JWT payload. It gives you typed access to registered claims such as exp (expiration), iat, sub, iss and aud. For expiration, claims.getExpiration() returns a java.util.Date, and the parser itself rejects an expired token by throwing ExpiredJwtException.
You normally do not compare dates by hand. You let the parser verify the signature and the exp claim together, and you read the Claims object only when you need the values, for example to show the remaining lifetime or to decide on a refresh.
A JWT has three Base64URL parts: header, payload and signature. The payload is a JSON object, and Claims is its Java representation. It extends Map<String, Object>, so every custom claim is available too, and it adds typed getters for the registered claims defined in RFC 7519.
| Claim | Getter | Meaning |
|---|---|---|
iss | getIssuer() | Who issued the token |
sub | getSubject() | Who the token is about, usually a user id |
aud | getAudience() | Intended recipients (a set in jjwt 0.12) |
exp | getExpiration() | Moment after which the token must be rejected |
nbf | getNotBefore() | Moment before which the token must be rejected |
iat | getIssuedAt() | When the token was created |
jti | getId() | Unique token id, useful for revocation lists |
The exp value is stored in the token as NumericDate: seconds since the Unix epoch, not milliseconds. jjwt converts it to a Date for you.
The code below uses the current jjwt API (0.12.x). The older Jwts.parser().setSigningKey(...).parseClaimsJws(...).getBody() chain is deprecated in 0.12 and was removed from the public API in later releases, so new code should use verifyWith, parseSignedClaims and getPayload.
parse verifies the signature first, then checks exp and nbf against the current time. If the token is expired, jjwt throws ExpiredJwtException. Its getClaims() method still exposes the payload, which is useful for logging who the expired token belonged to. Any other problem (bad signature, malformed token) raises another JwtException subclass.
Calling claims.getExpiration().before(new Date()) after parsing works only if the parser did not already throw. That makes the manual check redundant for validation. The only reason to read getExpiration() yourself is to compute something from it, such as the remaining lifetime or whether the token is close enough to expiry to refresh.
Two details trip people up:
Claims object, so an if (expired) branch after a successful parse never runs.exp claim never expires. If your policy requires expiry, check that claims.getExpiration() is not null, or require the claim in the parser.In a Spring Security application you typically validate the token in a OncePerRequestFilter and translate the failure into a 401 response.
The client reacts to the 401 by using its refresh token to get a new access token, or by sending the user back to the login page.
Servers rarely agree on the exact time. If an issuer and a verifier differ by a few seconds, a fresh token can look expired. jjwt lets you allow a small tolerance on the parser:
Keep the tolerance small. A typical setup uses short-lived access tokens (5 to 15 minutes) and a separate, revocable refresh token, because a stolen JWT stays valid until exp and cannot be recalled without extra server-side state.
It is part of jjwt (io.jsonwebtoken.Claims). Spring Security's own resource server support uses a different type, org.springframework.security.oauth2.jwt.Jwt, whose getExpiresAt() returns an Instant.
Yes. Both jjwt and Spring Security validate exp and nbf while parsing, so an expired token never reaches your business code.
With jjwt, catch ExpiredJwtException and call getClaims(). Use this only for logging or for a controlled refresh flow, never to authorise a request.
No. The JWT specification uses seconds since the epoch. jjwt handles the conversion when you pass a Date.
Claims is the typed view of a JWT payload, and getExpiration() exposes the exp claim as a Date. With jjwt 0.12 you build a parser with verifyWith, call parseSignedClaims, and let ExpiredJwtException signal expiry. Handle that exception in a filter, return 401, allow only a small clock skew, and keep access tokens short-lived.