55import io .jsonwebtoken .Jws ;
66import io .jsonwebtoken .Jwts ;
77import io .jsonwebtoken .MalformedJwtException ;
8- import io .jsonwebtoken .SignatureAlgorithm ;
98import io .jsonwebtoken .UnsupportedJwtException ;
109import io .jsonwebtoken .security .Keys ;
1110import 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