Skip to content

Commit

Permalink
Update JWT use for 0.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Oct 10, 2023
1 parent 29170ed commit 79dd96d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/java/nl/dtls/fairdatapoint/service/jwt/JwtService.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class JwtService {
protected void init() {
secretKey = Base64.getEncoder().encodeToString(secretKey.getBytes());
key = new SecretKeySpec(secretKey.getBytes(), SignatureAlgorithm.HS256.getJcaName());
parser = Jwts.parserBuilder().setSigningKey(key).build();
parser = Jwts.parser().setSigningKey(key).build();
}

public String createToken(AuthDTO authDTO) {
Expand All @@ -94,27 +94,27 @@ public Authentication getAuthentication(String token) {
}

public String getUserUuid(String token) {
return parser.parseClaimsJws(token).getBody().getSubject();
return parser.parseClaimsJws(token).getPayload().getSubject();
}

public boolean validateToken(String token) {
try {
final Jws<Claims> claims = parser.parseClaimsJws(token);
return !claims.getBody().getExpiration().before(new Date());
return !claims.getPayload().getExpiration().before(new Date());
}
catch (JwtException | IllegalArgumentException exception) {
throw new UnauthorizedException("Expired or invalid JWT token");
}
}

private String buildToken(User user) {
final Claims claims = Jwts.claims().setSubject(user.getUuid());
final Claims claims = Jwts.claims().subject(user.getUuid()).build();
final Date now = new Date();
final Date validity = new Date(now.getTime() + (expiration * DAY_MS));
return Jwts.builder()
.setClaims(claims)
.setIssuedAt(now)
.setExpiration(validity)
.claims(claims)
.issuedAt(now)
.expiration(validity)
.signWith(key)
.compact();
}
Expand Down

0 comments on commit 79dd96d

Please sign in to comment.