TokenProvider { public boolean validateToken(String authToken) { try { Jwts.parser().setSigningKey(secretKey).parseClaimsJws(authToken); return true; } catch (SignatureException e) { log.info("Invalid JWT signature."); log.trace("Invalid JWT signature trace: {}", e); } catch (MalformedJwtException e) { log.info("Invalid JWT token."); log.trace("Invalid JWT token trace: {}", e); } catch (ExpiredJwtException e) { log.info("Expired JWT token."); log.trace("Expired JWT token trace: {}", e); } catch (UnsupportedJwtException e) { log.info("Unsupported JWT token."); log.trace("Unsupported JWT token trace: {}", e); } catch (IllegalArgumentException e) { log.info("JWT token compact of handler are invalid."); log.trace("JWT token compact of handler are invalid trace: {}", e); } return false; } TokenProvider(JHipsterProperties jHipsterProperties); @PostConstruct void init(); String createToken(Authentication authentication, Boolean rememberMe); Authentication getAuthentication(String token); boolean validateToken(String authToken);  }
@Test public void testReturnFalseWhenJWThasInvalidSignature() { boolean isTokenValid = tokenProvider.validateToken(createTokenWithDifferentSignature()); assertThat(isTokenValid).isEqualTo(false); }
@Test public void testReturnFalseWhenJWTisUnsupported() { Date expirationDate = new Date(new Date().getTime() + ONE_MINUTE); Authentication authentication = createAuthentication(); String unsupportedToken = createUnsupportedToken(); boolean isTokenValid = tokenProvider.validateToken(unsupportedToken); assertThat(isTokenValid).isEqualTo(false); }
@Test public void testReturnFalseWhenJWTisInvalid() { boolean isTokenValid = tokenProvider.validateToken(""); assertThat(isTokenValid).isEqualTo(false); }