Jwt { public Object getClaim(String name) throws JwtExpiredException, JwtNotBeforeException { validateTimestampClaims(); try { return payload.get(name); } catch (JSONException ex) { return null; } } Jwt(JSONObject header, JSONObject payload, Clock clock, Duration clockSkew); String getIssuer(); String getSubject(); List<String> getAudiences(); String getJwtId(); Instant getExpiration(); Instant getNotBefore(); Instant getIssuedAt(); Object getClaim(String name); String getType(); String getContentType(); String getAlgorithm(); String getKeyId();  }
@Test public void expiredToken_shouldThrow() throws Exception { JSONObject payload = new JSONObject(); Instant instant = Instant.now().minus(Duration.ofMinutes(1)); payload.put(JwtNames.CLAIM_EXPIRATION, instant.getEpochSecond()); Jwt expiredToken = new Jwt(new JSONObject(), payload, Clock.systemUTC(), Duration.ZERO); assertThrows(JwtExpiredException.class, expiredToken::getIssuer); assertThrows(JwtExpiredException.class, expiredToken::getSubject); assertThrows(JwtExpiredException.class, expiredToken::getAudiences); assertThrows(JwtExpiredException.class, expiredToken::getJwtId); assertThrows(JwtExpiredException.class, () -> expiredToken.getClaim("blah")); assertThrows(JwtExpiredException.class, expiredToken::getAlgorithm); assertThrows(JwtExpiredException.class, expiredToken::getType); assertThrows(JwtExpiredException.class, expiredToken::getContentType); assertThrows(JwtExpiredException.class, expiredToken::getKeyId); }
@Test public void notBeforeToken_shouldThrow() throws Exception { JSONObject payload = new JSONObject(); Instant instant = Instant.now().plus(Duration.ofMinutes(1)); payload.put(JwtNames.CLAIM_NOT_BEFORE, instant.getEpochSecond()); Jwt notBeforeToken = new Jwt(new JSONObject(), payload, Clock.systemUTC(), Duration.ZERO); assertThrows(JwtNotBeforeException.class, notBeforeToken::getIssuer); assertThrows(JwtNotBeforeException.class, notBeforeToken::getSubject); assertThrows(JwtNotBeforeException.class, notBeforeToken::getAudiences); assertThrows(JwtNotBeforeException.class, notBeforeToken::getJwtId); assertThrows(JwtNotBeforeException.class, () -> notBeforeToken.getClaim("blah")); assertThrows(JwtNotBeforeException.class, notBeforeToken::getAlgorithm); assertThrows(JwtNotBeforeException.class, notBeforeToken::getType); assertThrows(JwtNotBeforeException.class, notBeforeToken::getContentType); assertThrows(JwtNotBeforeException.class, notBeforeToken::getKeyId); }