Skip to content

Commit dc9b6bf

Browse files
author
Pedro González Marcos
committed
feat: Update io.jsonwebtoken to 0.12.6
Migrate from 0.9.1 API to 0.12.6. Removed pom related dependencies to 0.9.1 version.
1 parent 9756c93 commit dc9b6bf

6 files changed

Lines changed: 151 additions & 171 deletions

File tree

pom.xml

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>io.github.isa-group</groupId>
99
<artifactId>Pricing4Java</artifactId>
10-
<version>5.5.1</version>
10+
<version>5.6.0-SNAPSHOT</version>
1111

1212
<name>${project.groupId}:${project.artifactId}</name>
1313
<description>A pricing driven feature toggling library for java</description>
@@ -49,13 +49,14 @@
4949
</distributionManagement>
5050

5151
<properties>
52-
<jackson.version>2.14.2</jackson.version>
53-
<aspectj.version>1.9.7</aspectj.version>
54-
<spring.version>6.1.5</spring.version>
55-
<spring.boot.version>3.2.0</spring.boot.version>
5652
<maven.compiler.source>17</maven.compiler.source>
5753
<maven.compiler.target>17</maven.compiler.target>
5854
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
55+
<jjwt.version>0.12.6</jjwt.version>
56+
<aspectj.version>1.9.7</aspectj.version>
57+
<spring.version>6.1.5</spring.version>
58+
<spring.boot.version>3.2.0</spring.boot.version>
59+
<snakeyaml.version>2.3</snakeyaml.version>
5960
</properties>
6061

6162

@@ -143,42 +144,35 @@
143144
<!-- JSON WEB TOKEN -->
144145
<dependency>
145146
<groupId>io.jsonwebtoken</groupId>
146-
<artifactId>jjwt</artifactId>
147-
<version>0.9.1</version>
148-
</dependency>
149-
<dependency>
150-
<groupId>org.json</groupId>
151-
<artifactId>json</artifactId>
152-
<version>20250107</version>
147+
<artifactId>jjwt-api</artifactId>
148+
<version>${jjwt.version}</version>
153149
</dependency>
154150

155-
<!-- YAML PARSER -->
156151
<dependency>
157-
<groupId>org.yaml</groupId>
158-
<artifactId>snakeyaml</artifactId>
159-
<version>2.3</version>
152+
<groupId>io.jsonwebtoken</groupId>
153+
<artifactId>jjwt-impl</artifactId>
154+
<version>${jjwt.version}</version>
155+
<scope>test</scope>
160156
</dependency>
161157

162-
<!-- API, java.xml.bind module -->
163158
<dependency>
164-
<groupId>jakarta.xml.bind</groupId>
165-
<artifactId>jakarta.xml.bind-api</artifactId>
166-
<version>2.3.2</version>
159+
<groupId>io.jsonwebtoken</groupId>
160+
<artifactId>jjwt-jackson</artifactId>
161+
<version>${jjwt.version}</version>
162+
<scope>test</scope>
167163
</dependency>
168164

169-
<!-- Runtime, com.sun.xml.bind module -->
165+
<!-- YAML PARSER -->
170166
<dependency>
171-
<groupId>org.glassfish.jaxb</groupId>
172-
<artifactId>jaxb-runtime</artifactId>
173-
<version>2.3.2</version>
167+
<groupId>org.yaml</groupId>
168+
<artifactId>snakeyaml</artifactId>
169+
<version>${snakeyaml.version}</version>
174170
</dependency>
175171
</dependencies>
176172

177173
<build>
178174
<finalName>Pricing4Java</finalName>
179175
<plugins>
180-
181-
182176
<plugin>
183177
<groupId>org.apache.maven.plugins</groupId>
184178
<artifactId>maven-gpg-plugin</artifactId>

src/main/java/io/github/isagroup/PricingEvaluatorUtil.java

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package io.github.isagroup;
22

3-
import java.util.*;
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import java.util.Optional;
46
import java.util.logging.Logger;
57

6-
import io.github.isagroup.models.*;
78
import org.springframework.beans.factory.annotation.Autowired;
89
import org.springframework.expression.spel.SpelEvaluationException;
910
import org.springframework.stereotype.Component;
1011

1112
import io.github.isagroup.exceptions.PricingPlanEvaluationException;
13+
import io.github.isagroup.models.Feature;
14+
import io.github.isagroup.models.FeatureStatus;
15+
import io.github.isagroup.models.PlanContextManager;
16+
import io.github.isagroup.models.PricingManager;
1217
import io.github.isagroup.services.jwt.PricingJwtUtils;
13-
import io.jsonwebtoken.Jwts;
14-
import io.jsonwebtoken.SignatureAlgorithm;
1518

1619
/**
1720
* Utility class that provides methods to generate and manage JWT that contains
@@ -58,23 +61,19 @@ public String generateUserToken() {
5861
planContextManager.setUserContext(pricingContext.getUserContext());
5962
claims.put("userContext", planContextManager.getUserContext());
6063
} catch (Exception e) {
61-
throw new PricingPlanEvaluationException("Error while retrieving user context! Please check your PricingContext.getUserContext() method");
64+
throw new PricingPlanEvaluationException(
65+
"Error while retrieving user context! Please check your PricingContext.getUserContext() method");
6266
}
6367

6468
if (!pricingContext.userAffectedByPricing()) {
65-
return Jwts.builder()
66-
.setClaims(claims)
67-
.setSubject(subject)
68-
.setIssuedAt(new Date(System.currentTimeMillis()))
69-
.setExpiration(new Date(System.currentTimeMillis() + pricingContext.getJwtExpiration()))
70-
.signWith(SignatureAlgorithm.HS512, pricingContext.getJwtSecret())
71-
.compact();
69+
return jwtUtils.createJwtToken(claims, subject);
7270
}
7371

7472
try {
7573
planContextManager.setPlanContext(pricingContext.getPlanContext());
7674
} catch (NullPointerException e) {
77-
throw new PricingPlanEvaluationException("Error while retrieving plan context! Please check your configuration file or add a plan with the given name");
75+
throw new PricingPlanEvaluationException(
76+
"Error while retrieving plan context! Please check your configuration file or add a plan with the given name");
7877
}
7978

8079
PricingManager pricingManager = pricingContext.getPricingManager();
@@ -86,18 +85,11 @@ public String generateUserToken() {
8685
claims.put("features", featureStatuses);
8786
claims.put("planContext", planContextManager.getPlanContext());
8887

89-
return Jwts.builder()
90-
.setClaims(claims)
91-
.setSubject(subject)
92-
.setIssuedAt(new Date(System.currentTimeMillis()))
93-
.setExpiration(new Date(System.currentTimeMillis() + pricingContext.getJwtExpiration()))
94-
.signWith(SignatureAlgorithm.HS512, pricingContext.getJwtSecret())
95-
.compact();
88+
return jwtUtils.createJwtToken(claims, subject);
9689
}
9790

98-
9991
private Map<String, FeatureStatus> computeFeatureStatuses(PlanContextManager planContextManager,
100-
Map<String, Feature> features) {
92+
Map<String, Feature> features) {
10193

10294
Map<String, FeatureStatus> featureStatuses = new HashMap<>();
10395

@@ -109,10 +101,11 @@ private Map<String, FeatureStatus> computeFeatureStatuses(PlanContextManager pla
109101
String expression = features.get(featureName).getExpression();
110102
try {
111103
Boolean eval = FeatureStatus.computeFeatureEvaluation(expression, planContextManager)
112-
.orElseThrow(() -> new PricingPlanEvaluationException("Evaluation was null"));
104+
.orElseThrow(() -> new PricingPlanEvaluationException("Evaluation was null"));
113105
featureStatus.setEval(eval);
114106
} catch (SpelEvaluationException e) {
115-
throw new PricingPlanEvaluationException("Error while evaluating the expression of the feature " + featureName + "! Please check the expression");
107+
throw new PricingPlanEvaluationException("Error while evaluating the expression of the feature "
108+
+ featureName + "! Please check the expression");
116109
}
117110

118111
Optional<String> userContextKey = FeatureStatus.computeUserContextVariable(expression);
@@ -124,9 +117,12 @@ private Map<String, FeatureStatus> computeFeatureStatuses(PlanContextManager pla
124117
featureStatus.setUsed(planContextManager.getUserContext().get(userContextKey.get()));
125118
if (feature.getExpression().contains("usageLimits")) {
126119
String usageLimitName = feature.getExpression().split("usageLimits")[1].split("[',\"]")[2];
127-
featureStatus.setLimit(((Map<String, Object>) planContextManager.getPlanContext().get("usageLimits")).get(usageLimitName));
120+
featureStatus
121+
.setLimit(((Map<String, Object>) planContextManager.getPlanContext().get("usageLimits"))
122+
.get(usageLimitName));
128123
} else {
129-
featureStatus.setLimit(((Map<String, Object>) planContextManager.getPlanContext().get("features")).get(featureName));
124+
featureStatus.setLimit(((Map<String, Object>) planContextManager.getPlanContext().get("features"))
125+
.get(featureName));
130126
}
131127

132128
}
@@ -148,7 +144,7 @@ private Map<String, FeatureStatus> computeFeatureStatuses(PlanContextManager pla
148144
* @param expression the expression of the feature that will replace its
149145
* evaluation
150146
* @return Modified version of the provided JWT that contains the new expression
151-
* in the "eval" attribute of the feature.
147+
* in the "eval" attribute of the feature.
152148
*/
153149
public String addExpressionToToken(String token, String featureId, String expression) {
154150

@@ -173,13 +169,7 @@ private String buildJwtToken(Map<String, Map<String, Object>> features, String s
173169
claims.put("userContext", pricingContext.getUserContext());
174170
claims.put("planContext", pricingContext.getPlanContext());
175171

176-
return Jwts.builder()
177-
.setClaims(claims)
178-
.setSubject(subject)
179-
.setIssuedAt(new Date(System.currentTimeMillis()))
180-
.setExpiration(new Date(System.currentTimeMillis() + pricingContext.getJwtExpiration()))
181-
.signWith(SignatureAlgorithm.HS512, pricingContext.getJwtSecret())
182-
.compact();
172+
return jwtUtils.createJwtToken(claims, subject);
183173
}
184174

185175
}

0 commit comments

Comments
 (0)