@Test public void isTokenValid() { String random = UUID.randomUUID().toString(); assertFalse(jwtTool.isTokenValid(random, jwtTool.getAccessTokenKey())); boolean valid = jwtTool.isTokenValid("eyJhbGciOiJIUzI1NiJ9" + ".eyJzdWIiOiJ0ZXN0QGdtYWlsLmNvbSIsImF1dGhvcml0aWVzIjpbIlJPTEVfVVNFUi" + "JdLCJpYXQiOjE1NzU4MzY5NjUsImV4cCI6MTU3NTgzNzg2NX0" + ".1kVcts6LCzUov-j0zMQqRXqIxeChUUv2gsw_zoLXtc8", jwtTool.getAccessTokenKey()); assertFalse(valid); }
public boolean isTokenValid(String token, String tokenKey) { boolean isValid = false; try { Jwts.parser().setSigningKey(tokenKey).parseClaimsJws(token); isValid = true; } catch (Exception e) { log.info("Given token is not valid: " + e.getMessage()); } return isValid; }
JwtTool { public boolean isTokenValid(String token, String tokenKey) { boolean isValid = false; try { Jwts.parser().setSigningKey(tokenKey).parseClaimsJws(token); isValid = true; } catch (Exception e) { log.info("Given token is not valid: " + e.getMessage()); } return isValid; } }
JwtTool { public boolean isTokenValid(String token, String tokenKey) { boolean isValid = false; try { Jwts.parser().setSigningKey(tokenKey).parseClaimsJws(token); isValid = true; } catch (Exception e) { log.info("Given token is not valid: " + e.getMessage()); } return isValid; } @Autowired  JwtTool(@Value("${accessTokenValidTimeInMinutes}") Integer accessTokenValidTimeInMinutes,
                   @Value("${refreshTokenValidTimeInMinutes}") Integer refreshTokenValidTimeInMinutes,
                   @Value("${tokenKey}") String accessTokenKey); }
JwtTool { public boolean isTokenValid(String token, String tokenKey) { boolean isValid = false; try { Jwts.parser().setSigningKey(tokenKey).parseClaimsJws(token); isValid = true; } catch (Exception e) { log.info("Given token is not valid: " + e.getMessage()); } return isValid; } @Autowired  JwtTool(@Value("${accessTokenValidTimeInMinutes}") Integer accessTokenValidTimeInMinutes,
                   @Value("${refreshTokenValidTimeInMinutes}") Integer refreshTokenValidTimeInMinutes,
                   @Value("${tokenKey}") String accessTokenKey); String createAccessToken(String email, ROLE role); String createRefreshToken(User user); String getEmailOutOfAccessToken(String token); boolean isTokenValid(String token, String tokenKey); String getAccessTokenKey(); String getTokenFromHttpServletRequest(HttpServletRequest servletRequest); String generateTokenKey(); }
JwtTool { public boolean isTokenValid(String token, String tokenKey) { boolean isValid = false; try { Jwts.parser().setSigningKey(tokenKey).parseClaimsJws(token); isValid = true; } catch (Exception e) { log.info("Given token is not valid: " + e.getMessage()); } return isValid; } @Autowired  JwtTool(@Value("${accessTokenValidTimeInMinutes}") Integer accessTokenValidTimeInMinutes,
                   @Value("${refreshTokenValidTimeInMinutes}") Integer refreshTokenValidTimeInMinutes,
                   @Value("${tokenKey}") String accessTokenKey); String createAccessToken(String email, ROLE role); String createRefreshToken(User user); String getEmailOutOfAccessToken(String token); boolean isTokenValid(String token, String tokenKey); String getAccessTokenKey(); String getTokenFromHttpServletRequest(HttpServletRequest servletRequest); String generateTokenKey();  }