Merge remote-tracking branch 'origin/master'

This commit is contained in:
Zihlu Wang
2024-01-26 08:42:50 +08:00
12 changed files with 77 additions and 12 deletions
+1 -1
View File
@@ -23,7 +23,7 @@
<parent> <parent>
<groupId>cn.org.codecrafters</groupId> <groupId>cn.org.codecrafters</groupId>
<artifactId>jdevkit</artifactId> <artifactId>jdevkit</artifactId>
<version>1.2.1</version> <version>1.2.2</version>
</parent> </parent>
<artifactId>devkit-core</artifactId> <artifactId>devkit-core</artifactId>
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>cn.org.codecrafters</groupId> <groupId>cn.org.codecrafters</groupId>
<artifactId>jdevkit</artifactId> <artifactId>jdevkit</artifactId>
<version>1.2.1</version> <version>1.2.2</version>
</parent> </parent>
<artifactId>devkit-utils</artifactId> <artifactId>devkit-utils</artifactId>
@@ -60,6 +60,10 @@ public final class Base64Util {
private static Base64.Decoder decoder; private static Base64.Decoder decoder;
private static Base64.Encoder urlEncoder;
private static Base64.Decoder urlDecoder;
/** /**
* Ensure that there is only one Base64 Encoder. * Ensure that there is only one Base64 Encoder.
* *
@@ -84,6 +88,20 @@ public final class Base64Util {
return decoder; return decoder;
} }
private static Base64.Encoder getUrlEncoder() {
if (Objects.isNull(urlEncoder)) {
urlEncoder = Base64.getUrlEncoder();
}
return urlEncoder;
}
public static Base64.Decoder getUrlDecoder() {
if (Objects.isNull(urlDecoder)) {
urlDecoder = Base64.getUrlDecoder();
}
return urlDecoder;
}
/** /**
* Private constructor to prevent instantiation of the class. * Private constructor to prevent instantiation of the class.
*/ */
@@ -136,4 +154,50 @@ public final class Base64Util {
return decode(value, StandardCharsets.UTF_8); return decode(value, StandardCharsets.UTF_8);
} }
/**
* Encodes the given string using the specified charset.
*
* @param value the string to be encoded
* @param charset the charset to be used for encoding
* @return the Base64 encoded string
*/
public static String encodeUrlComponents(String value, Charset charset) {
var encoded = getUrlEncoder().encode(value.getBytes(charset));
return new String(encoded);
}
/**
* Encodes the given string using the default UTF-8 charset.
*
* @param value the string to be encoded
* @return the Base64 encoded string
*/
public static String encodeUrlComponents(String value) {
return encodeUrlComponents(value, StandardCharsets.UTF_8);
}
/**
* Decodes the given Base64 encoded string using the specified charset.
*
* @param value the Base64 encoded string to be decoded
* @param charset the charset to be used for decoding
* @return the decoded string
*/
public static String decodeUrlComponents(String value, Charset charset) {
var decoded = getUrlDecoder().decode(value.getBytes(charset));
return new String(decoded);
}
/**
* Decodes the given Base64 encoded string using the default UTF-8 charset.
*
* @param value the Base64 encoded string to be decoded
* @return the decoded string
*/
public static String decodeUrlComponents(String value) {
return decodeUrlComponents(value, StandardCharsets.UTF_8);
}
} }
+1 -1
View File
@@ -23,7 +23,7 @@
<parent> <parent>
<groupId>cn.org.codecrafters</groupId> <groupId>cn.org.codecrafters</groupId>
<artifactId>jdevkit</artifactId> <artifactId>jdevkit</artifactId>
<version>1.2.1</version> <version>1.2.2</version>
</parent> </parent>
<artifactId>guid</artifactId> <artifactId>guid</artifactId>
+2 -1
View File
@@ -29,7 +29,7 @@
<groupId>cn.org.codecrafters</groupId> <groupId>cn.org.codecrafters</groupId>
<artifactId>jdevkit</artifactId> <artifactId>jdevkit</artifactId>
<version>1.2.1</version> <version>1.2.2</version>
<inceptionYear>2023</inceptionYear> <inceptionYear>2023</inceptionYear>
<packaging>pom</packaging> <packaging>pom</packaging>
@@ -93,6 +93,7 @@
<jackson.version>2.15.2</jackson.version> <jackson.version>2.15.2</jackson.version>
<auth0-jwt.version>4.4.0</auth0-jwt.version> <auth0-jwt.version>4.4.0</auth0-jwt.version>
<jjwt-jwt.version>0.11.5</jjwt-jwt.version> <jjwt-jwt.version>0.11.5</jjwt-jwt.version>
<ok-http.version>4.11.0</ok-http.version>
<!-- Spring Dependency Versions --> <!-- Spring Dependency Versions -->
<spring.version>6.0.9</spring.version> <spring.version>6.0.9</spring.version>
+1 -1
View File
@@ -23,7 +23,7 @@
<parent> <parent>
<groupId>cn.org.codecrafters</groupId> <groupId>cn.org.codecrafters</groupId>
<artifactId>jdevkit</artifactId> <artifactId>jdevkit</artifactId>
<version>1.2.1</version> <version>1.2.2</version>
</parent> </parent>
<artifactId>property-guard-spring-boot-starter</artifactId> <artifactId>property-guard-spring-boot-starter</artifactId>
+1 -1
View File
@@ -23,7 +23,7 @@
<parent> <parent>
<groupId>cn.org.codecrafters</groupId> <groupId>cn.org.codecrafters</groupId>
<artifactId>jdevkit</artifactId> <artifactId>jdevkit</artifactId>
<version>1.2.1</version> <version>1.2.2</version>
</parent> </parent>
<artifactId>simple-jwt-authzero</artifactId> <artifactId>simple-jwt-authzero</artifactId>
@@ -429,7 +429,7 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
public <T extends TokenPayload> T extract(String token, Class<T> targetType) { public <T extends TokenPayload> T extract(String token, Class<T> targetType) {
try { try {
// Get claims from token. // Get claims from token.
var payloads = objectMapper.readValue(Base64Util.decode(resolve(token).getPayload()), new MapTypeReference()); var payloads = objectMapper.readValue(Base64Util.decodeUrlComponents(resolve(token).getPayload()), new MapTypeReference());
// Get the no-argument constructor to create an instance. // Get the no-argument constructor to create an instance.
var bean = targetType.getConstructor().newInstance(); var bean = targetType.getConstructor().newInstance();
@@ -478,7 +478,7 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
var resolved = resolve(oldToken); var resolved = resolve(oldToken);
try { try {
var payload = objectMapper.readValue(Base64Util.decode(resolved.getPayload()), ObjectNode.class); var payload = objectMapper.readValue(Base64Util.decodeUrlComponents(resolved.getPayload()), ObjectNode.class);
payload.remove(PredefinedKeys.KEYS); payload.remove(PredefinedKeys.KEYS);
var payloadMap = objectMapper.convertValue(payload, new MapTypeReference()); var payloadMap = objectMapper.convertValue(payload, new MapTypeReference());
+1 -1
View File
@@ -23,7 +23,7 @@
<parent> <parent>
<groupId>cn.org.codecrafters</groupId> <groupId>cn.org.codecrafters</groupId>
<artifactId>jdevkit</artifactId> <artifactId>jdevkit</artifactId>
<version>1.2.1</version> <version>1.2.2</version>
</parent> </parent>
<artifactId>simple-jwt-facade</artifactId> <artifactId>simple-jwt-facade</artifactId>
+1 -1
View File
@@ -23,7 +23,7 @@
<parent> <parent>
<groupId>cn.org.codecrafters</groupId> <groupId>cn.org.codecrafters</groupId>
<artifactId>jdevkit</artifactId> <artifactId>jdevkit</artifactId>
<version>1.2.1</version> <version>1.2.2</version>
</parent> </parent>
<artifactId>simple-jwt-jjwt</artifactId> <artifactId>simple-jwt-jjwt</artifactId>
+1 -1
View File
@@ -23,7 +23,7 @@
<parent> <parent>
<groupId>cn.org.codecrafters</groupId> <groupId>cn.org.codecrafters</groupId>
<artifactId>jdevkit</artifactId> <artifactId>jdevkit</artifactId>
<version>1.2.1</version> <version>1.2.2</version>
</parent> </parent>
<artifactId>simple-jwt-spring-boot-starter</artifactId> <artifactId>simple-jwt-spring-boot-starter</artifactId>
+1 -1
View File
@@ -23,7 +23,7 @@
<parent> <parent>
<groupId>cn.org.codecrafters</groupId> <groupId>cn.org.codecrafters</groupId>
<artifactId>jdevkit</artifactId> <artifactId>jdevkit</artifactId>
<version>1.2.1</version> <version>1.2.2</version>
</parent> </parent>
<artifactId>webcal</artifactId> <artifactId>webcal</artifactId>