diff --git a/README.md b/README.md
index 21e00f5..d856dff 100644
--- a/README.md
+++ b/README.md
@@ -6,27 +6,19 @@ JDevKit is a Java Development Kit that offers a set of convenient tools for writ
> For more information, please visit the README file of each module.
-### `devkit-core`
-
-_[Learn more](https://github.com/CodeCraftersCN/jdevkit/devkit-core/README.md)_
+### `devkit-core` _[Learn more](https://github.com/CodeCraftersCN/jdevkit/devkit-core/README.md)_
The core module for `JDevKit`, by now, this module contains the commonly used classes of the whole `dev-kit`.
-### `devkit-utils`
-
-_[Learn more](https://github.com/CodeCraftersCN/jdevkit/devkit-utils/README.md)_
+### `devkit-utils` _[Learn more](https://github.com/CodeCraftersCN/jdevkit/devkit-utils/README.md)_
A collection of common utility classes to simplify Java development. It includes tools for Base64 encoding/decoding of strings, reducing if-else code blocks using Lambda expressions, converting between maps and arbitrary objects, high-precision chained mathematical calculations, and string hashing or message digest calculations.
-### `guid`
-
-_[Learn more](https://github.com/CodeCraftersCN/jdevkit/guid/README.md)_
+### `guid` _[Learn more](https://github.com/CodeCraftersCN/jdevkit/guid/README.md)_
A module for generating globally unique IDs. It includes a facade interface and an implementation of GUID generation using the Snowflake algorithm. More globally unique ID generation modes will be added in the future.
-### `WebCal`
-
-_[Learn more](https://github.com/CodeCraftersCN/jdevkit/webcal/README.md)_
+### `WebCal` _[Learn more](https://github.com/CodeCraftersCN/jdevkit/webcal/README.md)_
The module `webcal` is a Java library that facilitates the generation and resolution of iCalendar content for web-based calendar applications. It provides a flexible and easy-to-use API for creating web calendars with customisable settings and events.
@@ -34,27 +26,19 @@ With the `webcal` module, developers can easily integrate calendar functionality
Please note that the `webcal` module adheres to the iCalendar standard specified in RFC 5545, ensuring compatibility with other calendar applications that support this format.
-### `simple-jwt-facade`
-
-_[Learn more](https://github.com/CodeCraftersCN/jdevkit/simple-jwt-facade/README.md)_
+### `simple-jwt-facade` _[Learn more](https://github.com/CodeCraftersCN/jdevkit/simple-jwt-facade/README.md)_
A facade for Simple JWT (JSON Web Token) implementations in Java. This module provides a unified interface to work with JWTs regardless of the underlying implementation.
-### `simple-jwt-authzero`
-
-_[Learn more](https://github.com/CodeCraftersCN/jdevkit/simple-jwt-authzero/README.md)_
+### `simple-jwt-authzero` _[Learn more](https://github.com/CodeCraftersCN/jdevkit/simple-jwt-authzero/README.md)_
A Simple JWT implementation using the com.auth0:java-jwt library.
-### `simple-jwt-jjwt`
-
-_[Learn more](https://github.com/CodeCraftersCN/jdevkit/simple-jwt-jjwt/README.md)_
+### `simple-jwt-jjwt` _[Learn more](https://github.com/CodeCraftersCN/jdevkit/simple-jwt-jjwt/README.md)_
A Simple JWT implementation using the `io.jsonwebtoken:jjwt-api` library.
-### `simple-jwt-spring-boot-starter`
-
-_[Learn more](https://github.com/CodeCraftersCN/jdevkit/simple-jwt-spring-boot-starter/README.md)_
+### `simple-jwt-spring-boot-starter` _[Learn more](https://github.com/CodeCraftersCN/jdevkit/simple-jwt-spring-boot-starter/README.md)_
A Spring Boot autoconfiguration wrapper for the simple-jwt module, making it easier to integrate JWT functionality into Spring Boot applications.
diff --git a/devkit-core/build.gradle.kts b/devkit-core/build.gradle.kts
index 8263422..4ad9fa6 100644
--- a/devkit-core/build.gradle.kts
+++ b/devkit-core/build.gradle.kts
@@ -1,14 +1,31 @@
+/*
+ * Copyright (C) 2023 CodeCraftersCN.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
import java.net.URI
-val sGroupId: String by project
-val sVersion: String by project
+val buildGroupId: String by project
+val buildVersion: String by project
val projectUrl: String by project
val projectGithubUrl: String by project
val licenseName: String by project
val licenseUrl: String by project
-group = sGroupId
-version = sVersion
+group = buildGroupId
+version = buildVersion
java {
sourceCompatibility = JavaVersion.VERSION_17
@@ -24,9 +41,9 @@ tasks.test {
publishing {
publications {
create("devkitCore") {
- groupId = sGroupId
+ groupId = buildGroupId
artifactId = "devkit-core"
- version = sVersion
+ version = buildVersion
pom {
name = "DevKit - Core"
diff --git a/devkit-core/src/main/resources/logback.xml b/devkit-core/src/main/resources/logback.xml
index 46697b9..f229a7e 100644
--- a/devkit-core/src/main/resources/logback.xml
+++ b/devkit-core/src/main/resources/logback.xml
@@ -17,12 +17,10 @@
-->
-
-
+
+
-
+
${COLOURFUL_OUTPUT}
diff --git a/devkit-utils/build.gradle.kts b/devkit-utils/build.gradle.kts
index 06c7c6b..2f37818 100644
--- a/devkit-utils/build.gradle.kts
+++ b/devkit-utils/build.gradle.kts
@@ -1,14 +1,31 @@
+/*
+ * Copyright (C) 2023 CodeCraftersCN.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
import java.net.URI
-val sGroupId: String by project
-val sVersion: String by project
+val buildGroupId: String by project
+val buildVersion: String by project
val projectUrl: String by project
val projectGithubUrl: String by project
val licenseName: String by project
val licenseUrl: String by project
-group = sGroupId
-version = sVersion
+group = buildGroupId
+version = buildVersion
dependencies {
implementation(project(":devkit-core"))
@@ -28,9 +45,9 @@ tasks.test {
publishing {
publications {
create("devkitUtils") {
- groupId = sGroupId
+ groupId = buildGroupId
artifactId = "devkit-utils"
- version = sVersion
+ version = buildVersion
pom {
name = "DevKit - Utils"
diff --git a/devkit-utils/src/main/resources/logback.xml b/devkit-utils/src/main/resources/logback.xml
index 46697b9..f229a7e 100644
--- a/devkit-utils/src/main/resources/logback.xml
+++ b/devkit-utils/src/main/resources/logback.xml
@@ -17,12 +17,10 @@
-->
-
-
+
+
-
+
${COLOURFUL_OUTPUT}
diff --git a/gradle.properties b/gradle.properties
index 5a6c492..68a1400 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -21,13 +21,13 @@ slf4jVersion=2.0.9
lombokVersion=1.18.30
jacksonVersion=2.16.0
javaJwtVersion=4.4.0
-jjwtVersion=0.11.5
+jjwtVersion=0.12.5
okhttpVersion=4.12.0
-springVersion=6.1.1
-springBootVersion=3.2.0
+springVersion=6.1.3
+springBootVersion=3.2.3
-sGroupId=cn.org.codecrafters
-sVersion=1.3.2
+buildGroupId=cn.org.codecrafters
+buildVersion=1.4.0
projectUrl=https://codecrafters.org.cn/JDevKit
projectGithubUrl=https://github.com/CodeCraftersCN/JDevKit
licenseName=The Apache License, Version 2.0
diff --git a/guid/build.gradle.kts b/guid/build.gradle.kts
index cdc1455..4d3da40 100644
--- a/guid/build.gradle.kts
+++ b/guid/build.gradle.kts
@@ -1,14 +1,31 @@
+/*
+ * Copyright (C) 2023 CodeCraftersCN.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
import java.net.URI
-val sGroupId: String by project
-val sVersion: String by project
+val buildGroupId: String by project
+val buildVersion: String by project
val projectUrl: String by project
val projectGithubUrl: String by project
val licenseName: String by project
val licenseUrl: String by project
-group = sGroupId
-version = sVersion
+group = buildGroupId
+version = buildVersion
dependencies {
implementation(project(":devkit-core"))
@@ -28,9 +45,9 @@ tasks.test {
publishing {
publications {
create("guid") {
- groupId = sGroupId
+ groupId = buildGroupId
artifactId = "guid"
- version = sVersion
+ version = buildVersion
pom {
name = "DevKit - GUID"
diff --git a/guid/src/main/resources/logback.xml b/guid/src/main/resources/logback.xml
index 46697b9..5ba9d1b 100644
--- a/guid/src/main/resources/logback.xml
+++ b/guid/src/main/resources/logback.xml
@@ -15,14 +15,11 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
-
-
+
+
-
+
${COLOURFUL_OUTPUT}
diff --git a/property-guard-spring-boot-starter/build.gradle.kts b/property-guard-spring-boot-starter/build.gradle.kts
index ff7d9d1..51255f0 100644
--- a/property-guard-spring-boot-starter/build.gradle.kts
+++ b/property-guard-spring-boot-starter/build.gradle.kts
@@ -1,7 +1,24 @@
+/*
+ * Copyright (C) 2023 CodeCraftersCN.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
import java.net.URI
-val sGroupId: String by project
-val sVersion: String by project
+val buildGroupId: String by project
+val buildVersion: String by project
val projectUrl: String by project
val projectGithubUrl: String by project
val licenseName: String by project
@@ -9,8 +26,8 @@ val licenseUrl: String by project
val springBootVersion: String by project
-group = sGroupId
-version = sVersion
+group = buildGroupId
+version = buildVersion
dependencies {
implementation(project(":devkit-utils"))
@@ -34,9 +51,9 @@ tasks.test {
publishing {
publications {
create("propertyGuardSpringBootStarter") {
- groupId = sGroupId
+ groupId = buildGroupId
artifactId = "property-guard-spring-boot-starter"
- version = sVersion
+ version = buildVersion
pom {
name = "Property Guard Spring Boot Starter"
diff --git a/property-guard-spring-boot-starter/src/main/resources/logback.xml b/property-guard-spring-boot-starter/src/main/resources/logback.xml
index 46697b9..f229a7e 100644
--- a/property-guard-spring-boot-starter/src/main/resources/logback.xml
+++ b/property-guard-spring-boot-starter/src/main/resources/logback.xml
@@ -17,12 +17,10 @@
-->
-
-
+
+
-
+
${COLOURFUL_OUTPUT}
diff --git a/simple-jwt-authzero/build.gradle.kts b/simple-jwt-authzero/build.gradle.kts
index a576094..f4a1a94 100644
--- a/simple-jwt-authzero/build.gradle.kts
+++ b/simple-jwt-authzero/build.gradle.kts
@@ -1,7 +1,24 @@
+/*
+ * Copyright (C) 2023 CodeCraftersCN.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
import java.net.URI
-val sGroupId: String by project
-val sVersion: String by project
+val buildGroupId: String by project
+val buildVersion: String by project
val projectUrl: String by project
val projectGithubUrl: String by project
val licenseName: String by project
@@ -10,8 +27,8 @@ val licenseUrl: String by project
val jacksonVersion: String by project
val javaJwtVersion: String by project
-group = sGroupId
-version = sVersion
+group = buildGroupId
+version = buildVersion
dependencies {
implementation(project(":devkit-utils"))
@@ -35,9 +52,9 @@ tasks.test {
publishing {
publications {
create("simpleJwtAuthzero") {
- groupId = sGroupId
+ groupId = buildGroupId
artifactId = "simple-jwt-authzero"
- version = sVersion
+ version = buildVersion
pom {
name = "Simple JWT :: Auth0"
diff --git a/simple-jwt-authzero/src/main/resources/logback.xml b/simple-jwt-authzero/src/main/resources/logback.xml
index 46697b9..f229a7e 100644
--- a/simple-jwt-authzero/src/main/resources/logback.xml
+++ b/simple-jwt-authzero/src/main/resources/logback.xml
@@ -17,12 +17,10 @@
-->
-
-
+
+
-
+
${COLOURFUL_OUTPUT}
diff --git a/simple-jwt-facade/build.gradle.kts b/simple-jwt-facade/build.gradle.kts
index f835b00..ff57ac4 100644
--- a/simple-jwt-facade/build.gradle.kts
+++ b/simple-jwt-facade/build.gradle.kts
@@ -1,14 +1,31 @@
+/*
+ * Copyright (C) 2023 CodeCraftersCN.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
import java.net.URI
-val sGroupId: String by project
-val sVersion: String by project
+val buildGroupId: String by project
+val buildVersion: String by project
val projectUrl: String by project
val projectGithubUrl: String by project
val licenseName: String by project
val licenseUrl: String by project
-group = sGroupId
-version = sVersion
+group = buildGroupId
+version = buildVersion
dependencies {
implementation(project(":devkit-core"))
@@ -30,9 +47,9 @@ tasks.test {
publishing {
publications {
create("simpleJwtFacade") {
- groupId = sGroupId
+ groupId = buildGroupId
artifactId = "simple-jwt-facade"
- version = sVersion
+ version = buildVersion
pom {
name = "Simple JWT :: Facade"
diff --git a/simple-jwt-facade/src/main/resources/logback.xml b/simple-jwt-facade/src/main/resources/logback.xml
index 46697b9..f229a7e 100644
--- a/simple-jwt-facade/src/main/resources/logback.xml
+++ b/simple-jwt-facade/src/main/resources/logback.xml
@@ -17,12 +17,10 @@
-->
-
-
+
+
-
+
${COLOURFUL_OUTPUT}
diff --git a/simple-jwt-jjwt/build.gradle.kts b/simple-jwt-jjwt/build.gradle.kts
index 75e39e4..e2862cf 100644
--- a/simple-jwt-jjwt/build.gradle.kts
+++ b/simple-jwt-jjwt/build.gradle.kts
@@ -1,7 +1,24 @@
+/*
+ * Copyright (C) 2023 CodeCraftersCN.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
import java.net.URI
-val sGroupId: String by project
-val sVersion: String by project
+val buildGroupId: String by project
+val buildVersion: String by project
val projectUrl: String by project
val projectGithubUrl: String by project
val licenseName: String by project
@@ -10,8 +27,8 @@ val licenseUrl: String by project
val jacksonVersion: String by project
val jjwtVersion: String by project
-group = sGroupId
-version = sVersion
+group = buildGroupId
+version = buildVersion
dependencies {
implementation(project(":devkit-utils"))
@@ -37,9 +54,9 @@ tasks.test {
publishing {
publications {
create("simpleJwtJjwt") {
- groupId = sGroupId
+ groupId = buildGroupId
artifactId = "simple-jwt-jjwt"
- version = sVersion
+ version = buildVersion
pom {
name = "Simple JWT :: JJWT"
diff --git a/simple-jwt-jjwt/src/main/java/cn/org/codecrafters/simplejwt/jjwt/JjwtTokenResolver.java b/simple-jwt-jjwt/src/main/java/cn/org/codecrafters/simplejwt/jjwt/JjwtTokenResolver.java
index ba1f12f..dd32976 100644
--- a/simple-jwt-jjwt/src/main/java/cn/org/codecrafters/simplejwt/jjwt/JjwtTokenResolver.java
+++ b/simple-jwt-jjwt/src/main/java/cn/org/codecrafters/simplejwt/jjwt/JjwtTokenResolver.java
@@ -28,17 +28,16 @@ import cn.org.codecrafters.simplejwt.constants.PredefinedKeys;
import cn.org.codecrafters.simplejwt.constants.TokenAlgorithm;
import cn.org.codecrafters.simplejwt.exceptions.WeakSecretException;
import cn.org.codecrafters.simplejwt.jjwt.config.JjwtTokenResolverConfig;
-import com.fasterxml.jackson.core.type.TypeReference;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
-import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;
+import io.jsonwebtoken.security.SecureDigestAlgorithm;
import lombok.extern.slf4j.Slf4j;
+import javax.crypto.SecretKey;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
-import java.security.Key;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -46,7 +45,7 @@ import java.util.*;
/**
* The {@link JjwtTokenResolver} class is an implementation of the {@link
- * cn.org.codecrafters.simplejwt.TokenResolver} interface. It uses the {@code
+ * TokenResolver} interface. It uses the {@code
* io.jsonwebtoken:jjwt} library to handle JSON Web Token (JWT) resolution.
* This resolver provides functionality to create, extract, verify, and renew
* JWT tokens using various algorithms and custom payload data.
@@ -92,7 +91,7 @@ import java.util.*;
* @see Claims
* @see Jws
* @see Jwts
- * @see SignatureAlgorithm
+ * @see SecureDigestAlgorithm
* @see Keys
* @since 1.0.0
*/
@@ -101,14 +100,22 @@ public class JjwtTokenResolver implements TokenResolver> {
private final GuidCreator> jtiCreator;
- private final SignatureAlgorithm algorithm;
+ private final SecureDigestAlgorithm algorithm;
private final String issuer;
- private final Key key;
+ private final SecretKey key;
private final JjwtTokenResolverConfig config = JjwtTokenResolverConfig.getInstance();
+ /**
+ * Create a resolver with specified algorithm, issuer, secret and guid strategy.
+ *
+ * @param jtiCreator jwt id creator
+ * @param algorithm specified algorithm
+ * @param issuer specified issuer
+ * @param secret specified secret
+ */
public JjwtTokenResolver(GuidCreator> jtiCreator, TokenAlgorithm algorithm, String issuer, String secret) {
if (Objects.isNull(secret) || secret.isBlank()) {
throw new IllegalArgumentException("A secret is required to build a JSON Web Token.");
@@ -129,6 +136,13 @@ public class JjwtTokenResolver implements TokenResolver> {
this.key = Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8));
}
+ /**
+ * Create a resolver with specified algorithm, issuer, secret and default guid strategy.
+ *
+ * @param algorithm specified algorithm
+ * @param issuer specified issuer
+ * @param secret specified secret
+ */
public JjwtTokenResolver(TokenAlgorithm algorithm, String issuer, String secret) {
if (secret == null || secret.isBlank()) {
throw new IllegalArgumentException("A secret is required to build a JSON Web Token.");
@@ -149,6 +163,13 @@ public class JjwtTokenResolver implements TokenResolver> {
this.key = Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8));
}
+ /**
+ * Create a resolver with specified issuer, secret, default algorithm and guid strategy.
+ *
+ * @param issuer specified issuer
+ * @param secret specified secret
+ * @see #JjwtTokenResolver(TokenAlgorithm, String, String)
+ */
public JjwtTokenResolver(String issuer, String secret) {
if (secret == null || secret.isBlank()) {
throw new IllegalArgumentException("A secret is required to build a JSON Web Token.");
@@ -169,6 +190,12 @@ public class JjwtTokenResolver implements TokenResolver> {
this.key = Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8));
}
+ /**
+ * Create a resolver with specified issuer, random secret string, default algorithm and guid strategy.
+ *
+ * @param issuer specified issuer
+ * @see #JjwtTokenResolver(String, String)
+ */
public JjwtTokenResolver(String issuer) {
this.jtiCreator = UUID::randomUUID;
this.algorithm = config.getAlgorithm(TokenAlgorithm.HS256);
@@ -176,26 +203,6 @@ public class JjwtTokenResolver implements TokenResolver> {
this.key = Keys.hmacShaKeyFor(SecretCreator.createSecret(32, true, true, true).getBytes(StandardCharsets.UTF_8));
}
- private String buildToken(Duration expireAfter, String audience, String subject, Map claims) {
- var now = LocalDateTime.now();
- var builder = Jwts.builder()
- .setHeaderParam("typ", "JWT")
- .setIssuedAt(Date.from(now.atZone(ZoneId.systemDefault()).toInstant()))
- .setNotBefore(Date.from(now.atZone(ZoneId.systemDefault()).toInstant()))
- .setExpiration(Date.from(now.plus(expireAfter).atZone(ZoneId.systemDefault()).toInstant()))
- .setSubject(subject)
- .setAudience(audience)
- .setIssuer(this.issuer)
- .setId(jtiCreator.nextId().toString());
-
- if (claims != null && !claims.isEmpty()) {
- builder.addClaims(claims);
- }
-
- return builder.signWith(key, algorithm)
- .compact();
- }
-
/**
* Creates a new token with the specified expiration time, subject, and
* audience.
@@ -280,10 +287,10 @@ public class JjwtTokenResolver implements TokenResolver> {
*/
@Override
public Jws resolve(String token) {
- return Jwts.parserBuilder()
- .setSigningKey(key)
+ return Jwts.parser()
+ .verifyWith(key)
.build()
- .parseClaimsJws(token);
+ .parseSignedClaims(token);
}
/**
@@ -300,7 +307,7 @@ public class JjwtTokenResolver implements TokenResolver> {
public T extract(String token, Class targetType) {
var resolvedToken = resolve(token);
- var claims = resolvedToken.getBody();
+ var claims = resolvedToken.getPayload();
try {
var bean = targetType.getConstructor().newInstance();
@@ -351,9 +358,9 @@ public class JjwtTokenResolver implements TokenResolver> {
@Override
public String renew(String oldToken, Duration expireAfter) {
var resolvedToken = resolve(oldToken);
- var tokenPayloads = resolvedToken.getBody();
+ var tokenPayloads = resolvedToken.getPayload();
- var audience = tokenPayloads.getAudience();
+ var audience = tokenPayloads.getAudience().toArray(new String[]{})[0];
var subject = tokenPayloads.getSubject();
PredefinedKeys.KEYS.forEach(tokenPayloads::remove);
@@ -372,8 +379,8 @@ public class JjwtTokenResolver implements TokenResolver> {
*/
@Override
public String renew(String oldToken, Duration expireAfter, Map payload) {
- var resolvedTokenClaims = resolve(oldToken).getBody();
- var audience = resolvedTokenClaims.getAudience();
+ var resolvedTokenClaims = resolve(oldToken).getPayload();
+ var audience = resolvedTokenClaims.getAudience().toArray(new String[]{})[0];
var subject = resolvedTokenClaims.getSubject();
return createToken(expireAfter, audience, subject, payload);
@@ -404,8 +411,8 @@ public class JjwtTokenResolver implements TokenResolver> {
*/
@Override
public String renew(String oldToken, Duration expireAfter, T payload) {
- var resolvedTokenClaims = resolve(oldToken).getBody();
- var audience = resolvedTokenClaims.getAudience();
+ var resolvedTokenClaims = resolve(oldToken).getPayload();
+ var audience = resolvedTokenClaims.getAudience().toArray(new String[]{})[0];
var subject = resolvedTokenClaims.getSubject();
return createToken(expireAfter, audience, subject, payload);
@@ -424,4 +431,26 @@ public class JjwtTokenResolver implements TokenResolver> {
public String renew(String oldToken, T payload) {
return renew(oldToken, Duration.ofMinutes(30), payload);
}
+
+ private String buildToken(Duration expireAfter, String audience, String subject, Map claims) {
+ var now = LocalDateTime.now();
+ var builder = Jwts.builder()
+ .header().add("typ", "JWT")
+ .and()
+ .issuedAt(Date.from(now.atZone(ZoneId.systemDefault()).toInstant()))
+ .notBefore(Date.from(now.atZone(ZoneId.systemDefault()).toInstant()))
+ .expiration(Date.from(now.plus(expireAfter).atZone(ZoneId.systemDefault()).toInstant()))
+ .subject(subject)
+ .issuer(this.issuer)
+ .audience().add(audience)
+ .and()
+ .id(jtiCreator.nextId().toString());
+
+ if (claims != null && !claims.isEmpty()) {
+ builder.claims(claims);
+ }
+
+ return builder.signWith(key, algorithm)
+ .compact();
+ }
}
diff --git a/simple-jwt-jjwt/src/main/java/cn/org/codecrafters/simplejwt/jjwt/config/JjwtTokenResolverConfig.java b/simple-jwt-jjwt/src/main/java/cn/org/codecrafters/simplejwt/jjwt/config/JjwtTokenResolverConfig.java
index 89eefba..677682d 100644
--- a/simple-jwt-jjwt/src/main/java/cn/org/codecrafters/simplejwt/jjwt/config/JjwtTokenResolverConfig.java
+++ b/simple-jwt-jjwt/src/main/java/cn/org/codecrafters/simplejwt/jjwt/config/JjwtTokenResolverConfig.java
@@ -22,8 +22,12 @@ import cn.org.codecrafters.simplejwt.config.TokenResolverConfig;
import cn.org.codecrafters.simplejwt.constants.TokenAlgorithm;
import cn.org.codecrafters.simplejwt.exceptions.UnsupportedAlgorithmException;
import cn.org.codecrafters.simplejwt.jjwt.JjwtTokenResolver;
+import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
+import io.jsonwebtoken.security.MacAlgorithm;
+import io.jsonwebtoken.security.SecureDigestAlgorithm;
+import javax.crypto.SecretKey;
import java.util.HashMap;
import java.util.Map;
@@ -57,15 +61,15 @@ import java.util.Map;
* @version 1.1.1
* @since 1.0.0
*/
-public final class JjwtTokenResolverConfig implements TokenResolverConfig {
+public final class JjwtTokenResolverConfig implements TokenResolverConfig> {
private JjwtTokenResolverConfig() {
}
- private static final Map SUPPORTED_ALGORITHMS = new HashMap<>() {{
- put(TokenAlgorithm.HS256, SignatureAlgorithm.HS256);
- put(TokenAlgorithm.HS384, SignatureAlgorithm.HS384);
- put(TokenAlgorithm.HS512, SignatureAlgorithm.HS512);
+ private static final Map> SUPPORTED_ALGORITHMS = new HashMap<>() {{
+ put(TokenAlgorithm.HS256, Jwts.SIG.HS256);
+ put(TokenAlgorithm.HS384, Jwts.SIG.HS384);
+ put(TokenAlgorithm.HS512, Jwts.SIG.HS512);
}};
private static JjwtTokenResolverConfig instance;
@@ -95,7 +99,7 @@ public final class JjwtTokenResolverConfig implements TokenResolverConfig getAlgorithm(TokenAlgorithm algorithm) {
if (!SUPPORTED_ALGORITHMS.containsKey(algorithm)) {
throw new UnsupportedAlgorithmException("""
The request algorithm is not supported by our system yet. Please change to supported ones.""");
diff --git a/simple-jwt-jjwt/src/main/resources/logback.xml b/simple-jwt-jjwt/src/main/resources/logback.xml
index 46697b9..f229a7e 100644
--- a/simple-jwt-jjwt/src/main/resources/logback.xml
+++ b/simple-jwt-jjwt/src/main/resources/logback.xml
@@ -17,12 +17,10 @@
-->
-
-
+
+
-
+
${COLOURFUL_OUTPUT}
diff --git a/simple-jwt-spring-boot-starter/build.gradle.kts b/simple-jwt-spring-boot-starter/build.gradle.kts
index cfbdde4..6464090 100644
--- a/simple-jwt-spring-boot-starter/build.gradle.kts
+++ b/simple-jwt-spring-boot-starter/build.gradle.kts
@@ -17,8 +17,8 @@
import java.net.URI
-val sGroupId: String by project
-val sVersion: String by project
+val buildGroupId: String by project
+val buildVersion: String by project
val projectUrl: String by project
val projectGithubUrl: String by project
val licenseName: String by project
@@ -28,8 +28,8 @@ val javaJwtVersion: String by project
val jjwtVersion: String by project
val springBootVersion: String by project
-group = sGroupId
-version = sVersion
+group = buildGroupId
+version = buildVersion
dependencies {
implementation(project(":guid"))
@@ -60,9 +60,9 @@ tasks.test {
publishing {
publications {
create("simpleJwtSpringBootStarter") {
- groupId = sGroupId
+ groupId = buildGroupId
artifactId = "simple-jwt-spring-boot-starter"
- version = sVersion
+ version = buildVersion
pom {
name = "Simple JWT :: Spring Boot Starter"
diff --git a/simple-jwt-spring-boot-starter/src/main/resources/logback.xml b/simple-jwt-spring-boot-starter/src/main/resources/logback.xml
index 46697b9..f229a7e 100644
--- a/simple-jwt-spring-boot-starter/src/main/resources/logback.xml
+++ b/simple-jwt-spring-boot-starter/src/main/resources/logback.xml
@@ -17,12 +17,10 @@
-->
-
-
+
+
-
+
${COLOURFUL_OUTPUT}
diff --git a/webcal/build.gradle.kts b/webcal/build.gradle.kts
index 1dd216e..176c533 100644
--- a/webcal/build.gradle.kts
+++ b/webcal/build.gradle.kts
@@ -1,14 +1,14 @@
import java.net.URI
-val sGroupId: String by project
-val sVersion: String by project
+val buildGroupId: String by project
+val buildVersion: String by project
val projectUrl: String by project
val projectGithubUrl: String by project
val licenseName: String by project
val licenseUrl: String by project
-group = sGroupId
-version = sVersion
+group = buildGroupId
+version = buildVersion
dependencies {
implementation(project(":devkit-core"))
@@ -28,9 +28,9 @@ tasks.test {
publishing {
publications {
create("webcal") {
- groupId = sGroupId
+ groupId = buildGroupId
artifactId = "webcal"
- version = sVersion
+ version = buildVersion
pom {
name = "DevKit :: WebCal"
diff --git a/webcal/src/main/resources/logback.xml b/webcal/src/main/resources/logback.xml
index 46697b9..5ba9d1b 100644
--- a/webcal/src/main/resources/logback.xml
+++ b/webcal/src/main/resources/logback.xml
@@ -15,14 +15,11 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
-
-
+
+
-
+
${COLOURFUL_OUTPUT}