Skip to content

Commit c79f477

Browse files
author
Ivan Franchin
committed
Upgrade io.jsonwebtoken dependencies to 0.12.3
1 parent 5d422a3 commit c79f477

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

order-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<properties>
1818
<java.version>17</java.version>
19-
<jjwt.version>0.11.5</jjwt.version>
19+
<jjwt.version>0.12.3</jjwt.version>
2020
<springdoc-openapi.version>2.3.0</springdoc-openapi.version>
2121
</properties>
2222

order-api/src/main/java/com/ivanfranchin/orderapi/security/TokenProvider.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import io.jsonwebtoken.Jws;
66
import io.jsonwebtoken.Jwts;
77
import io.jsonwebtoken.MalformedJwtException;
8-
import io.jsonwebtoken.SignatureAlgorithm;
98
import io.jsonwebtoken.UnsupportedJwtException;
109
import io.jsonwebtoken.security.Keys;
1110
import io.jsonwebtoken.security.SignatureException;
@@ -43,14 +42,16 @@ public String generate(Authentication authentication) {
4342
byte[] signingKey = jwtSecret.getBytes();
4443

4544
return Jwts.builder()
46-
.setHeaderParam("typ", TOKEN_TYPE)
47-
.signWith(Keys.hmacShaKeyFor(signingKey), SignatureAlgorithm.HS512)
48-
.setExpiration(Date.from(ZonedDateTime.now().plusMinutes(jwtExpirationMinutes).toInstant()))
49-
.setIssuedAt(Date.from(ZonedDateTime.now().toInstant()))
50-
.setId(UUID.randomUUID().toString())
51-
.setIssuer(TOKEN_ISSUER)
52-
.setAudience(TOKEN_AUDIENCE)
53-
.setSubject(user.getUsername())
45+
.header().add("typ", TOKEN_TYPE)
46+
.and()
47+
.signWith(Keys.hmacShaKeyFor(signingKey), Jwts.SIG.HS512)
48+
.expiration(Date.from(ZonedDateTime.now().plusMinutes(jwtExpirationMinutes).toInstant()))
49+
.issuedAt(Date.from(ZonedDateTime.now().toInstant()))
50+
.id(UUID.randomUUID().toString())
51+
.issuer(TOKEN_ISSUER)
52+
.audience().add(TOKEN_AUDIENCE)
53+
.and()
54+
.subject(user.getUsername())
5455
.claim("rol", roles)
5556
.claim("name", user.getName())
5657
.claim("preferred_username", user.getUsername())
@@ -62,10 +63,10 @@ public Optional<Jws<Claims>> validateTokenAndGetJws(String token) {
6263
try {
6364
byte[] signingKey = jwtSecret.getBytes();
6465

65-
Jws<Claims> jws = Jwts.parserBuilder()
66-
.setSigningKey(signingKey)
66+
Jws<Claims> jws = Jwts.parser()
67+
.verifyWith(Keys.hmacShaKeyFor(signingKey))
6768
.build()
68-
.parseClaimsJws(token);
69+
.parseSignedClaims(token);
6970

7071
return Optional.of(jws);
7172
} catch (ExpiredJwtException exception) {

0 commit comments

Comments
 (0)