TokenDecoder { public DecodedJWT validateAndDecodeToken(String token) throws DynamicLogLevelException { try { DecodedJWT jwt = verifier.verify(token); Date exp = jwt.getExpiresAt(); Date iat = jwt.getIssuedAt(); Date now = new Date(); if (exp != null && iat != null && now.after(iat) && now.before(exp)) { return jwt; } else { throw new DynamicLogLevelException("Token provided to dynamically change the log-level on thread-level is outdated"); } } catch (JWTVerificationException e) { throw new DynamicLogLevelException("Token could not be verified"); } } TokenDecoder(RSAPublicKey key); DecodedJWT validateAndDecodeToken(String token);  }
@Test public void testTokenContent() throws Exception { TokenDecoder tokenDecoder = new TokenDecoder((RSAPublicKey) validKeyPair.getPublic()); DecodedJWT jwt = tokenDecoder.validateAndDecodeToken(token); assertEquals(jwt.getClaim("level").asString(), "TRACE"); }
@Test(expected = DynamicLogLevelException.class) public void testInvalidPublicKey() throws Exception { TokenDecoder tokenDecoder = new TokenDecoder((RSAPublicKey) invalidKeyPair.getPublic()); tokenDecoder.validateAndDecodeToken(token); }