Skip to content

Commit c48e267

Browse files
jjwt dependency update
1 parent 32cea81 commit c48e267

4 files changed

Lines changed: 23 additions & 17 deletions

File tree

symphony-bdk-bom/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ dependencies {
5555
api 'org.apache.commons:commons-text:1.14.0'
5656
api 'commons-logging:commons-logging:1.3.5'
5757
api 'com.brsanthu:migbase64:2.2'
58-
api 'io.jsonwebtoken:jjwt:0.9.1'
58+
api 'io.jsonwebtoken:jjwt-api:0.13.0'
59+
api 'io.jsonwebtoken:jjwt-impl:0.13.0'
60+
api 'io.jsonwebtoken:jjwt-jackson:0.13.0'
5961
api 'org.bouncycastle:bcpkix-jdk18on:1.79'
6062
api 'com.google.code.findbugs:jsr305:3.0.2'
6163

symphony-bdk-core/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ dependencies {
4747
implementation 'org.apache.commons:commons-lang3'
4848
implementation 'org.apache.commons:commons-text'
4949
implementation 'com.brsanthu:migbase64'
50-
implementation 'io.jsonwebtoken:jjwt'
50+
implementation 'io.jsonwebtoken:jjwt-api'
51+
runtimeOnly 'io.jsonwebtoken:jjwt-impl'
52+
runtimeOnly 'io.jsonwebtoken:jjwt-jackson'
5153
implementation 'org.bouncycastle:bcpkix-jdk18on'
5254
api 'com.fasterxml.jackson.core:jackson-databind'
5355
implementation 'io.github.resilience4j:resilience4j-retry'

symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/jwt/JwtHelper.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import io.jsonwebtoken.Claims;
1010
import io.jsonwebtoken.JwtException;
1111
import io.jsonwebtoken.Jwts;
12-
import io.jsonwebtoken.SignatureAlgorithm;
1312
import org.apiguardian.api.API;
1413
import org.bouncycastle.asn1.pkcs.RSAPrivateKey;
1514
import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters;
@@ -23,7 +22,6 @@
2322
import java.io.StringReader;
2423
import java.nio.charset.StandardCharsets;
2524
import java.security.GeneralSecurityException;
26-
import java.security.Key;
2725
import java.security.KeyFactory;
2826
import java.security.NoSuchAlgorithmException;
2927
import java.security.PrivateKey;
@@ -65,7 +63,7 @@ public class JwtHelper {
6563

6664

6765
/**
68-
* Creates a JWT with the provided user name and expiration date, signed with the provided private key.
66+
* Creates a JWT with the provided username and expiration date, signed with the provided private key.
6967
*
7068
* @param user the username to authenticate; will be verified by the pod
7169
* @param expiration of the authentication request in milliseconds; cannot be longer than the value defined on the
@@ -75,16 +73,16 @@ public class JwtHelper {
7573
* the public key stored for the user
7674
* @return a signed JWT for a specific user (or subject)
7775
*/
78-
public static String createSignedJwt(String user, long expiration, Key privateKey) {
76+
public static String createSignedJwt(String user, long expiration, PrivateKey privateKey) {
7977
return Jwts.builder()
80-
.setSubject(user)
81-
.setExpiration(new Date(System.currentTimeMillis() + expiration))
82-
.signWith(SignatureAlgorithm.RS512, privateKey)
78+
.subject(user)
79+
.expiration(new Date(System.currentTimeMillis() + expiration))
80+
.signWith(privateKey, Jwts.SIG.RS512)
8381
.compact();
8482
}
8583

8684
/**
87-
* Creates a RSA Private Key from a PEM String. It supports PKCS#1 and PKCS#8 string formats.
85+
* Creates an RSA Private Key from a PEM String. It supports PKCS#1 and PKCS#8 string formats.
8886
*
8987
* @param pemPrivateKey RSA Private Key content
9088
* @return a {@link PrivateKey} instance
@@ -110,18 +108,21 @@ else if (pemPrivateKey.contains(PEM_RSA_PRIVATE_START)) {
110108
/**
111109
* Validates a jwt against a certificate.
112110
*
113-
* @param jwt
111+
* @param jwt string of the jwt to be validated
114112
* @param certificate string of the X.509 certificate content in pem format.
115-
* @return the content of jwt clain "user" if jwt is successfully validated.
113+
* @return the content of jwt claim "user" if jwt is successfully validated.
116114
* @throws AuthInitializationException if certificate or jwt are invalid.
117115
*/
118116
public static UserClaim validateJwt(String jwt, String certificate) throws AuthInitializationException {
119117
final Certificate x509Certificate = parseX509Certificate(certificate);
120118

121119
try {
122-
final Claims body = Jwts.parser().setSigningKey(x509Certificate.getPublicKey())
123-
.parseClaimsJws(jwt).getBody();
124-
return mapper.convertValue(body.get("user"), UserClaim.class);
120+
final Claims claims = Jwts.parser()
121+
.verifyWith(x509Certificate.getPublicKey())
122+
.build()
123+
.parseSignedClaims(jwt)
124+
.getPayload();
125+
return mapper.convertValue(claims.get("user"), UserClaim.class);
125126
} catch (JwtException e) {
126127
throw new AuthInitializationException("Unable to validate JWT", e);
127128
}

symphony-bdk-http/symphony-bdk-http-jersey2/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ dependencies {
1616

1717
implementation 'org.slf4j:slf4j-api'
1818
implementation 'org.apiguardian:apiguardian-api'
19-
implementation 'io.jsonwebtoken:jjwt'
19+
implementation 'io.jsonwebtoken:jjwt-api'
20+
runtimeOnly 'io.jsonwebtoken:jjwt-impl'
21+
runtimeOnly 'io.jsonwebtoken:jjwt-jackson'
2022
implementation 'org.bouncycastle:bcpkix-jdk18on'
2123
implementation 'commons-io:commons-io'
2224
implementation 'org.apache.commons:commons-lang3'
@@ -42,4 +44,3 @@ dependencies {
4244
testImplementation 'org.mockito:mockito-junit-jupiter'
4345
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
4446
}
45-

0 commit comments

Comments
 (0)