|
|
@@ -10,6 +10,8 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
@@ -23,8 +25,6 @@ public class JwtTokenUtil implements Serializable {
|
|
|
static final String CLAIM_KEY_USERNAME = "sub";
|
|
|
static final String CLAIM_KEY_CREATED = "iat";
|
|
|
|
|
|
- @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "It's okay here")
|
|
|
- private Clock clock = DefaultClock.INSTANCE;
|
|
|
private JwtConfig jwtConfig;
|
|
|
|
|
|
public JwtTokenUtil(JwtConfig jwtConfig) {
|
|
|
@@ -57,7 +57,7 @@ public class JwtTokenUtil implements Serializable {
|
|
|
|
|
|
private Boolean isTokenExpired(String token) {
|
|
|
final Date expiration = getExpirationDateFromToken(token);
|
|
|
- return expiration.before(clock.now());
|
|
|
+ return expiration.before(Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant()));
|
|
|
}
|
|
|
|
|
|
private Boolean isCreatedBeforeLastPasswordReset(Date created, Date lastPasswordReset) {
|
|
|
@@ -75,7 +75,7 @@ public class JwtTokenUtil implements Serializable {
|
|
|
}
|
|
|
|
|
|
private String doGenerateToken(Map<String, Object> claims, String subject) {
|
|
|
- final Date createdDate = clock.now();
|
|
|
+ final Date createdDate = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());
|
|
|
final Date expirationDate = calculateExpirationDate(createdDate);
|
|
|
|
|
|
return Jwts.builder()
|
|
|
@@ -94,7 +94,7 @@ public class JwtTokenUtil implements Serializable {
|
|
|
}
|
|
|
|
|
|
public String refreshToken(String token) {
|
|
|
- final Date createdDate = clock.now();
|
|
|
+ final Date createdDate = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());
|
|
|
final Date expirationDate = calculateExpirationDate(createdDate);
|
|
|
|
|
|
final Claims claims = getAllClaimsFromToken(token);
|
|
|
@@ -122,4 +122,5 @@ public class JwtTokenUtil implements Serializable {
|
|
|
private Date calculateExpirationDate(Date createdDate) {
|
|
|
return new Date(createdDate.getTime() + jwtConfig.getExpiration() * 1000);
|
|
|
}
|
|
|
+
|
|
|
}
|