diff --git a/pom.xml b/pom.xml
index 1f2027c..9d5e7a8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
1.5.5.Final
8.0.1.Final
3.0.2
- 0.11.5
+ 0.12.3
4.23.0
2.0.2
1.4.0
@@ -73,7 +73,7 @@
spring-boot-starter-test
test
-
+
org.springframework.boot
spring-boot-starter-mail
diff --git a/src/main/java/com/example/tasklist/web/security/JwtTokenProvider.java b/src/main/java/com/example/tasklist/web/security/JwtTokenProvider.java
index d3de889..af68a4f 100644
--- a/src/main/java/com/example/tasklist/web/security/JwtTokenProvider.java
+++ b/src/main/java/com/example/tasklist/web/security/JwtTokenProvider.java
@@ -18,7 +18,7 @@
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;
-import java.security.Key;
+import javax.crypto.SecretKey;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Date;
@@ -34,7 +34,7 @@ public class JwtTokenProvider {
private final UserDetailsService userDetailsService;
private final UserService userService;
- private Key key;
+ private SecretKey key;
@PostConstruct
public void init() {
@@ -44,14 +44,16 @@ public void init() {
public String createAccessToken(final Long userId,
final String username,
final Set roles) {
- Claims claims = Jwts.claims().setSubject(username);
- claims.put("id", userId);
- claims.put("roles", resolveRoles(roles));
+ Claims claims = Jwts.claims()
+ .subject(username)
+ .add("id", userId)
+ .add("roles", resolveRoles(roles))
+ .build();
Instant validity = Instant.now()
.plus(jwtProperties.getAccess(), ChronoUnit.HOURS);
return Jwts.builder()
- .setClaims(claims)
- .setExpiration(Date.from(validity))
+ .claims(claims)
+ .expiration(Date.from(validity))
.signWith(key)
.compact();
}
@@ -63,13 +65,15 @@ private List resolveRoles(final Set roles) {
}
public String createRefreshToken(final Long userId, final String username) {
- Claims claims = Jwts.claims().setSubject(username);
- claims.put("id", userId);
+ Claims claims = Jwts.claims()
+ .subject(username)
+ .add("id", userId)
+ .build();
Instant validity = Instant.now()
.plus(jwtProperties.getRefresh(), ChronoUnit.DAYS);
return Jwts.builder()
- .setClaims(claims)
- .setExpiration(Date.from(validity))
+ .claims(claims)
+ .expiration(Date.from(validity))
.signWith(key)
.compact();
}
@@ -94,31 +98,30 @@ public JwtResponse refreshUserTokens(final String refreshToken) {
public boolean validateToken(final String token) {
Jws claims = Jwts
- .parserBuilder()
- .setSigningKey(key)
+ .parser()
+ .verifyWith(key)
.build()
- .parseClaimsJws(token);
- return !claims.getBody().getExpiration().before(new Date());
+ .parseSignedClaims(token);
+ return claims.getPayload().getExpiration().after(new Date());
}
private String getId(final String token) {
return Jwts
- .parserBuilder()
- .setSigningKey(key)
+ .parser()
+ .verifyWith(key)
.build()
- .parseClaimsJws(token)
- .getBody()
- .get("id")
- .toString();
+ .parseSignedClaims(token)
+ .getPayload()
+ .get("id", String.class);
}
private String getUsername(final String token) {
return Jwts
- .parserBuilder()
- .setSigningKey(key)
+ .parser()
+ .verifyWith(key)
.build()
- .parseClaimsJws(token)
- .getBody()
+ .parseSignedClaims(token)
+ .getPayload()
.getSubject();
}