/** * Validate that the expiration time of the JWT token has not been violated. * If it has then throw an AuthenticationException. Override this method in * subclasses in order to customize the expiration validation behavior. * * @param jwtToken the token that contains the expiration date to validate * @return valid true if the token has not expired; false otherwise */ protected boolean validateExpiration(SignedJWT jwtToken) { boolean valid = false; try { Date expires = jwtToken.getJWTClaimsSet().getExpirationTime(); if (expires == null || new Date().before(expires)) { LOG.debug("JWT token expiration date has been " + "successfully validated"); valid = true; } else { LOG.warn("JWT expiration date validation failed."); } } catch (ParseException pe) { LOG.warn("JWT expiration date validation failed.", pe); } return valid; } }
/** * Validate that the expiration time of the JWT token has not been violated. * If it has then throw an AuthenticationException. Override this method in * subclasses in order to customize the expiration validation behavior. * * @param jwtToken the token that contains the expiration date to validate * @return valid true if the token has not expired; false otherwise */ protected boolean validateExpiration(SignedJWT jwtToken) { boolean valid = false; try { Date expires = jwtToken.getJWTClaimsSet().getExpirationTime(); if (expires == null || new Date().before(expires)) { LOG.debug("JWT token expiration date has been " + "successfully validated"); valid = true; } else { LOG.warn("JWT expiration date validation failed."); } } catch (ParseException pe) { LOG.warn("JWT expiration date validation failed.", pe); } return valid; } }
private boolean verifySignature(String jwt) { try { SignedJWT signedJWT = SignedJWT.parse(jwt); if (new Date().before(signedJWT.getJWTClaimsSet().getExpirationTime())) { JWSVerifier verifier = new RSASSAVerifier((RSAPublicKey) getPublicKey(KEYSTORE, KEYSTORE_PASSWORD, ALIAS)); return signedJWT.verify(verifier); } else { log.info("Token has expired"); } } catch (ParseException | IOException | KeyStoreException | CertificateException | NoSuchAlgorithmException | UnrecoverableKeyException | JOSEException e) { log.error("Error occurred while JWT signature verification. JWT=" + jwt, e); } return false; }
private boolean verifySignature(String jwt) { try { SignedJWT signedJWT = SignedJWT.parse(jwt); if (new Date().before(signedJWT.getJWTClaimsSet().getExpirationTime())) { JWSVerifier verifier = new RSASSAVerifier((RSAPublicKey) getPublicKey(KEYSTORE, KEYSTORE_PASSWORD, ALIAS)); return signedJWT.verify(verifier); } else { log.info("Token has expired"); } } catch (ParseException | IOException | KeyStoreException | CertificateException | NoSuchAlgorithmException | UnrecoverableKeyException | JOSEException e) { log.error("Error occurred while JWT signature verification. JWT=" + jwt, e); } return false; }
private boolean verifySignature(String jwt) { try { SignedJWT signedJWT = SignedJWT.parse(jwt); if (new Date().before(signedJWT.getJWTClaimsSet().getExpirationTime())) { JWSVerifier verifier = new RSASSAVerifier((RSAPublicKey) getPublicKey(KEYSTORE, KEYSTORE_PASSWORD, ALIAS)); return signedJWT.verify(verifier); } else { log.info("Token has expired"); } } catch (ParseException | IOException | KeyStoreException | CertificateException | NoSuchAlgorithmException | UnrecoverableKeyException | JOSEException e) { log.error("Error occurred while JWT signature verification", e); } return false; }
final long expirationTime = jwtClaimsSet.getExpirationTime().getTime(); if (currentTime > (expirationTime + expTolerance.getTime(MILLISECONDS))) { throw new TokenExpiredException("Token expired", profile.getName(), new Date(), new Date(expirationTime), expTolerance);
final long expirationTime = claims.getExpirationTime().getTime(); if (now.getTime() > expirationTime) { throw new ValidationResponseException(OAuth2Validator.ValidationResponse.EXPIRES_FAILED);
private ValidateTokenResponse convert(final ReadOnlyJWTClaimsSet claimsSet) { final ValidateTokenResponse validateTokenResponse = new ValidateTokenResponse(); validateTokenResponse.setActive(true); if (claimsSet.getAudience() != null) { validateTokenResponse.setAud(Join.join(" ", claimsSet.getAudience())); } validateTokenResponse.setExp(claimsSet.getExpirationTime().getTime()); validateTokenResponse.setIat(claimsSet.getIssueTime().getTime()); validateTokenResponse.setIss(claimsSet.getIssuer()); validateTokenResponse.setJti(claimsSet.getJWTID()); validateTokenResponse.setNbf(claimsSet.getNotBeforeTime().getTime()); try { if (claimsSet.getStringListClaim("scope") != null) { validateTokenResponse.setScope(Join.join(" ", claimsSet.getStringListClaim("scope"))); } } catch (final ParseException e) { // ignore } return validateTokenResponse; } }