@Test(expected = JwtAuthenticationException.class) public void whenValidateTokenCalledWithExpiredTokenThenExpectFailure() { ReflectionTestUtils.setField(jwtUtils, "allowedClockSkewInSecs", 0L); ReflectionTestUtils.setField(jwtUtils, "expirationInSecs", 0L); final String token = createTokenWithLastPasswordResetYesterday(); jwtUtils.validateTokenAndGetClaims(token); }
public Claims validateTokenAndGetClaims(String token) { try { final Claims claims = getClaimsFromToken(token); final Date created = getIssuedAtDateFromTokenClaims(claims); final Date lastPasswordResetDate = getLastPasswordResetDateFromTokenClaims(claims); if (!isCreatedAfterLastPasswordReset(created, lastPasswordResetDate)) { final String errorMsg = "Invalid token! Created date claim is before last password reset date." + " Created date: " + created + " Password reset date: " + lastPasswordResetDate; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg); } return claims; } catch (Exception e) { final String errorMsg = "Invalid token! Details: " + e.getMessage(); LOG.error(errorMsg, e); throw new JwtAuthenticationException(errorMsg, e); } }
JwtUtils { public Claims validateTokenAndGetClaims(String token) { try { final Claims claims = getClaimsFromToken(token); final Date created = getIssuedAtDateFromTokenClaims(claims); final Date lastPasswordResetDate = getLastPasswordResetDateFromTokenClaims(claims); if (!isCreatedAfterLastPasswordReset(created, lastPasswordResetDate)) { final String errorMsg = "Invalid token! Created date claim is before last password reset date." + " Created date: " + created + " Password reset date: " + lastPasswordResetDate; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg); } return claims; } catch (Exception e) { final String errorMsg = "Invalid token! Details: " + e.getMessage(); LOG.error(errorMsg, e); throw new JwtAuthenticationException(errorMsg, e); } } }
JwtUtils { public Claims validateTokenAndGetClaims(String token) { try { final Claims claims = getClaimsFromToken(token); final Date created = getIssuedAtDateFromTokenClaims(claims); final Date lastPasswordResetDate = getLastPasswordResetDateFromTokenClaims(claims); if (!isCreatedAfterLastPasswordReset(created, lastPasswordResetDate)) { final String errorMsg = "Invalid token! Created date claim is before last password reset date." + " Created date: " + created + " Password reset date: " + lastPasswordResetDate; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg); } return claims; } catch (Exception e) { final String errorMsg = "Invalid token! Details: " + e.getMessage(); LOG.error(errorMsg, e); throw new JwtAuthenticationException(errorMsg, e); } }  }
JwtUtils { public Claims validateTokenAndGetClaims(String token) { try { final Claims claims = getClaimsFromToken(token); final Date created = getIssuedAtDateFromTokenClaims(claims); final Date lastPasswordResetDate = getLastPasswordResetDateFromTokenClaims(claims); if (!isCreatedAfterLastPasswordReset(created, lastPasswordResetDate)) { final String errorMsg = "Invalid token! Created date claim is before last password reset date." + " Created date: " + created + " Password reset date: " + lastPasswordResetDate; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg); } return claims; } catch (Exception e) { final String errorMsg = "Invalid token! Details: " + e.getMessage(); LOG.error(errorMsg, e); throw new JwtAuthenticationException(errorMsg, e); } }  Claims validateTokenAndGetClaims(String token); String createToken(JwtUser userDetails); boolean canTokenBeRefreshed(Claims claims, Date lastPasswordReset); String refreshToken(String token); String getUsernameFromTokenClaims(Claims claims); List<GrantedAuthority> getRolesFromTokenClaims(Claims claims); }
JwtUtils { public Claims validateTokenAndGetClaims(String token) { try { final Claims claims = getClaimsFromToken(token); final Date created = getIssuedAtDateFromTokenClaims(claims); final Date lastPasswordResetDate = getLastPasswordResetDateFromTokenClaims(claims); if (!isCreatedAfterLastPasswordReset(created, lastPasswordResetDate)) { final String errorMsg = "Invalid token! Created date claim is before last password reset date." + " Created date: " + created + " Password reset date: " + lastPasswordResetDate; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg); } return claims; } catch (Exception e) { final String errorMsg = "Invalid token! Details: " + e.getMessage(); LOG.error(errorMsg, e); throw new JwtAuthenticationException(errorMsg, e); } }  Claims validateTokenAndGetClaims(String token); String createToken(JwtUser userDetails); boolean canTokenBeRefreshed(Claims claims, Date lastPasswordReset); String refreshToken(String token); String getUsernameFromTokenClaims(Claims claims); List<GrantedAuthority> getRolesFromTokenClaims(Claims claims);  }