@Test public void generateToken() { User user = new User(); user.setEmail("a@celess.cn"); String s = jwtUtil.generateToken(user, true); System.out.println(s); assertNotNull(s); }
public String generateToken(User user, boolean isRemember) { Map<String, Object> claims = new HashMap<>(16); claims.put(CLAIM_KEY_USERNAME, user.getEmail()); return Jwts.builder() .setClaims(claims) .setExpiration(new Date(Instant.now().toEpochMilli() + (isRemember ? EXPIRATION_LONG_TIME : EXPIRATION_SHORT_TIME))) .signWith(SignatureAlgorithm.HS512, SECRET) .compact(); }
JwtUtil { public String generateToken(User user, boolean isRemember) { Map<String, Object> claims = new HashMap<>(16); claims.put(CLAIM_KEY_USERNAME, user.getEmail()); return Jwts.builder() .setClaims(claims) .setExpiration(new Date(Instant.now().toEpochMilli() + (isRemember ? EXPIRATION_LONG_TIME : EXPIRATION_SHORT_TIME))) .signWith(SignatureAlgorithm.HS512, SECRET) .compact(); } }
JwtUtil { public String generateToken(User user, boolean isRemember) { Map<String, Object> claims = new HashMap<>(16); claims.put(CLAIM_KEY_USERNAME, user.getEmail()); return Jwts.builder() .setClaims(claims) .setExpiration(new Date(Instant.now().toEpochMilli() + (isRemember ? EXPIRATION_LONG_TIME : EXPIRATION_SHORT_TIME))) .signWith(SignatureAlgorithm.HS512, SECRET) .compact(); }  }
JwtUtil { public String generateToken(User user, boolean isRemember) { Map<String, Object> claims = new HashMap<>(16); claims.put(CLAIM_KEY_USERNAME, user.getEmail()); return Jwts.builder() .setClaims(claims) .setExpiration(new Date(Instant.now().toEpochMilli() + (isRemember ? EXPIRATION_LONG_TIME : EXPIRATION_SHORT_TIME))) .signWith(SignatureAlgorithm.HS512, SECRET) .compact(); }  String generateToken(User user, boolean isRemember); Boolean validateToken(String token, User user); Boolean isTokenExpired(String token); String getUsernameFromToken(String token); Date getExpirationDateFromToken(String token); }
JwtUtil { public String generateToken(User user, boolean isRemember) { Map<String, Object> claims = new HashMap<>(16); claims.put(CLAIM_KEY_USERNAME, user.getEmail()); return Jwts.builder() .setClaims(claims) .setExpiration(new Date(Instant.now().toEpochMilli() + (isRemember ? EXPIRATION_LONG_TIME : EXPIRATION_SHORT_TIME))) .signWith(SignatureAlgorithm.HS512, SECRET) .compact(); }  String generateToken(User user, boolean isRemember); Boolean validateToken(String token, User user); Boolean isTokenExpired(String token); String getUsernameFromToken(String token); Date getExpirationDateFromToken(String token); static final long EXPIRATION_LONG_TIME; static final long EXPIRATION_SHORT_TIME; }