-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump io.jsonwebtoken:jjwt from 0.9.1 to 0.12.3
- Loading branch information
Showing
6 changed files
with
52 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,30 +7,37 @@ | |
*/ | ||
package org.roda.core.common; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.crypto.SecretKey; | ||
|
||
import org.roda.core.RodaCoreFactory; | ||
import org.roda.core.data.exceptions.AuthenticationDeniedException; | ||
|
||
import io.jsonwebtoken.Claims; | ||
import io.jsonwebtoken.Jwts; | ||
import io.jsonwebtoken.SignatureAlgorithm; | ||
import io.jsonwebtoken.security.Keys; | ||
|
||
/** | ||
* @author Gabriel Barros <[email protected]> | ||
*/ | ||
public class JwtUtils { | ||
|
||
private JwtUtils() { | ||
// empty constructor | ||
} | ||
|
||
public static String generateToken(String subject, Date expirationDate) { | ||
return generateToken(subject, expirationDate, new HashMap<>()); | ||
} | ||
|
||
public static String generateToken(String subject, Date expirationDate, Map<String, Object> claims) { | ||
return Jwts.builder().signWith(SignatureAlgorithm.HS256, RodaCoreFactory.getApiSecretKey()) | ||
.setIssuedAt(new Date(System.currentTimeMillis())).setSubject(subject).setExpiration(expirationDate) | ||
.addClaims(claims).compact(); | ||
SecretKey secretKey = Keys.hmacShaKeyFor(RodaCoreFactory.getApiSecretKey().getBytes(StandardCharsets.UTF_8)); | ||
return Jwts.builder().signWith(secretKey, Jwts.SIG.HS256).issuedAt(new Date(System.currentTimeMillis())) | ||
.subject(subject).expiration(expirationDate).claims(claims).compact(); | ||
} | ||
|
||
public static String regenerateToken(String token) throws AuthenticationDeniedException { | ||
|
@@ -43,7 +50,8 @@ public static String regenerateToken(String token) throws AuthenticationDeniedEx | |
|
||
private static Claims getClaimsFromToken(String token) throws AuthenticationDeniedException { | ||
try { | ||
return Jwts.parser().setSigningKey(RodaCoreFactory.getApiSecretKey()).parseClaimsJws(token).getBody(); | ||
SecretKey secretKey = Keys.hmacShaKeyFor(RodaCoreFactory.getApiSecretKey().getBytes(StandardCharsets.UTF_8)); | ||
return Jwts.parser().verifyWith(secretKey).build().parseSignedClaims(token).getPayload(); | ||
} catch (Exception e) { | ||
throw new AuthenticationDeniedException("invalid token"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,10 @@ | |
*/ | ||
package org.roda.wui.api.controllers; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Date; | ||
|
||
import io.jsonwebtoken.security.Keys; | ||
import org.roda.core.RodaCoreFactory; | ||
import org.roda.core.common.JwtUtils; | ||
import org.roda.core.data.common.RodaConstants; | ||
|
@@ -32,6 +34,8 @@ | |
import io.jsonwebtoken.JwtException; | ||
import io.jsonwebtoken.Jwts; | ||
|
||
import javax.crypto.SecretKey; | ||
|
||
/** | ||
* @author Gabriel Barros <[email protected]> | ||
*/ | ||
|
@@ -230,8 +234,8 @@ public static AccessToken authenticate(AccessKey accessKey) | |
|
||
Claims claims; | ||
try { | ||
claims = Jwts.parser().setSigningKey(RodaCoreFactory.getApiSecretKey()).parseClaimsJws(accessKey.getKey()) | ||
.getBody(); | ||
SecretKey secretKey = Keys.hmacShaKeyFor(RodaCoreFactory.getApiSecretKey().getBytes(StandardCharsets.UTF_8)); | ||
claims = Jwts.parser().verifyWith(secretKey).build().parseSignedClaims(accessKey.getKey()).getPayload(); | ||
} catch (JwtException e) { | ||
throw new AuthorizationDeniedException("Expired token"); | ||
} | ||
|