Skip to content

Commit 0b80638

Browse files
author
Zihlu Wang
authored
Merge pull request #21 from CodeCraftersCN/dev/v1.2.2
Upgrade to v1.2.2
2 parents e1f2b93 + 60e5fc3 commit 0b80638

File tree

12 files changed

+77
-12
lines changed

12 files changed

+77
-12
lines changed

devkit-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>cn.org.codecrafters</groupId>
2525
<artifactId>jdevkit</artifactId>
26-
<version>1.2.1</version>
26+
<version>1.2.2</version>
2727
</parent>
2828

2929
<artifactId>devkit-core</artifactId>

devkit-utils/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>cn.org.codecrafters</groupId>
88
<artifactId>jdevkit</artifactId>
9-
<version>1.2.1</version>
9+
<version>1.2.2</version>
1010
</parent>
1111

1212
<artifactId>devkit-utils</artifactId>

devkit-utils/src/main/java/cn/org/codecrafters/devkit/utils/Base64Util.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public final class Base64Util {
6060

6161
private static Base64.Decoder decoder;
6262

63+
private static Base64.Encoder urlEncoder;
64+
65+
private static Base64.Decoder urlDecoder;
66+
6367
/**
6468
* Ensure that there is only one Base64 Encoder.
6569
*
@@ -84,6 +88,20 @@ private static Base64.Decoder getDecoder() {
8488
return decoder;
8589
}
8690

91+
private static Base64.Encoder getUrlEncoder() {
92+
if (Objects.isNull(urlEncoder)) {
93+
urlEncoder = Base64.getUrlEncoder();
94+
}
95+
return urlEncoder;
96+
}
97+
98+
public static Base64.Decoder getUrlDecoder() {
99+
if (Objects.isNull(urlDecoder)) {
100+
urlDecoder = Base64.getUrlDecoder();
101+
}
102+
return urlDecoder;
103+
}
104+
87105
/**
88106
* Private constructor to prevent instantiation of the class.
89107
*/
@@ -136,4 +154,50 @@ public static String decode(String value) {
136154
return decode(value, StandardCharsets.UTF_8);
137155
}
138156

157+
/**
158+
* Encodes the given string using the specified charset.
159+
*
160+
* @param value the string to be encoded
161+
* @param charset the charset to be used for encoding
162+
* @return the Base64 encoded string
163+
*/
164+
public static String encodeUrlComponents(String value, Charset charset) {
165+
var encoded = getUrlEncoder().encode(value.getBytes(charset));
166+
167+
return new String(encoded);
168+
}
169+
170+
/**
171+
* Encodes the given string using the default UTF-8 charset.
172+
*
173+
* @param value the string to be encoded
174+
* @return the Base64 encoded string
175+
*/
176+
public static String encodeUrlComponents(String value) {
177+
return encodeUrlComponents(value, StandardCharsets.UTF_8);
178+
}
179+
180+
/**
181+
* Decodes the given Base64 encoded string using the specified charset.
182+
*
183+
* @param value the Base64 encoded string to be decoded
184+
* @param charset the charset to be used for decoding
185+
* @return the decoded string
186+
*/
187+
public static String decodeUrlComponents(String value, Charset charset) {
188+
var decoded = getUrlDecoder().decode(value.getBytes(charset));
189+
190+
return new String(decoded);
191+
}
192+
193+
/**
194+
* Decodes the given Base64 encoded string using the default UTF-8 charset.
195+
*
196+
* @param value the Base64 encoded string to be decoded
197+
* @return the decoded string
198+
*/
199+
public static String decodeUrlComponents(String value) {
200+
return decodeUrlComponents(value, StandardCharsets.UTF_8);
201+
}
202+
139203
}

guid/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>cn.org.codecrafters</groupId>
2525
<artifactId>jdevkit</artifactId>
26-
<version>1.2.1</version>
26+
<version>1.2.2</version>
2727
</parent>
2828

2929
<artifactId>guid</artifactId>

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
<groupId>cn.org.codecrafters</groupId>
3131
<artifactId>jdevkit</artifactId>
32-
<version>1.2.1</version>
32+
<version>1.2.2</version>
3333
<inceptionYear>2023</inceptionYear>
3434

3535
<packaging>pom</packaging>
@@ -93,6 +93,7 @@
9393
<jackson.version>2.15.2</jackson.version>
9494
<auth0-jwt.version>4.4.0</auth0-jwt.version>
9595
<jjwt-jwt.version>0.11.5</jjwt-jwt.version>
96+
<ok-http.version>4.11.0</ok-http.version>
9697

9798
<!-- Spring Dependency Versions -->
9899
<spring.version>6.0.9</spring.version>

property-guard-spring-boot-starter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>cn.org.codecrafters</groupId>
2525
<artifactId>jdevkit</artifactId>
26-
<version>1.2.1</version>
26+
<version>1.2.2</version>
2727
</parent>
2828

2929
<artifactId>property-guard-spring-boot-starter</artifactId>

simple-jwt-authzero/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>cn.org.codecrafters</groupId>
2525
<artifactId>jdevkit</artifactId>
26-
<version>1.2.1</version>
26+
<version>1.2.2</version>
2727
</parent>
2828

2929
<artifactId>simple-jwt-authzero</artifactId>

simple-jwt-authzero/src/main/java/cn/org/codecrafters/simplejwt/authzero/AuthzeroTokenResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ public DecodedJWT resolve(String token) {
429429
public <T extends TokenPayload> T extract(String token, Class<T> targetType) {
430430
try {
431431
// Get claims from token.
432-
var payloads = objectMapper.readValue(Base64Util.decode(resolve(token).getPayload()), new MapTypeReference());
432+
var payloads = objectMapper.readValue(Base64Util.decodeUrlComponents(resolve(token).getPayload()), new MapTypeReference());
433433
// Get the no-argument constructor to create an instance.
434434
var bean = targetType.getConstructor().newInstance();
435435

@@ -478,7 +478,7 @@ public String renew(String oldToken, Duration expireAfter) {
478478
var resolved = resolve(oldToken);
479479

480480
try {
481-
var payload = objectMapper.readValue(Base64Util.decode(resolved.getPayload()), ObjectNode.class);
481+
var payload = objectMapper.readValue(Base64Util.decodeUrlComponents(resolved.getPayload()), ObjectNode.class);
482482
payload.remove(PredefinedKeys.KEYS);
483483

484484
var payloadMap = objectMapper.convertValue(payload, new MapTypeReference());

simple-jwt-facade/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>cn.org.codecrafters</groupId>
2525
<artifactId>jdevkit</artifactId>
26-
<version>1.2.1</version>
26+
<version>1.2.2</version>
2727
</parent>
2828

2929
<artifactId>simple-jwt-facade</artifactId>

simple-jwt-jjwt/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>cn.org.codecrafters</groupId>
2525
<artifactId>jdevkit</artifactId>
26-
<version>1.2.1</version>
26+
<version>1.2.2</version>
2727
</parent>
2828

2929
<artifactId>simple-jwt-jjwt</artifactId>

0 commit comments

Comments
 (0)