diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/ResolvedToken.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/ResolvedToken.java deleted file mode 100644 index adfd19f..0000000 --- a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/ResolvedToken.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - */ - -package cn.org.codecrafters.simplejwt; - -/** - * ResolvedToken - Generic Record for Holding Resolved Tokens. - *
- * This class represents a generic record that holds a resolved token of type {@code T}. It is used as a simple - * container to store the resolved token value for further processing. - *
- * Usage:
- * To create a new instance of {@code ResolvedToken}, use the static factory method {@code init}.
- *
- * @param
* The {@code TokenResolver} interface defines methods for creating,
* extracting, and renewing tokens, particularly JSON Web Tokens (JWTs). It
* provides a set of methods to generate tokens with various payload
@@ -44,54 +42,24 @@ import java.util.Map;
* expired token by providing a new expiration time, audience, subject, and
* optional custom payload data.
*
+ * @param
+ * This annotation is used to mark a property of a data class that should be
+ * excluded from being automatically injected into the JSON Web Token (JWT)
+ * payload during token generation. When a property is annotated with this
+ * annotation, it will not be included as part of the JWT payload.
+ *
+ * Usage:
+ * To exclude a property from the JWT payload, annotate the property with
+ * {@code @ExcludeFromPayload}:
+ *
+ * Note:
+ * This annotation should be used only on properties that are not intended to
+ * be included in the JWT payload due to their sensitive nature or for other
+ * reasons. It is important to carefully choose which properties are excluded
+ * from the payload to ensure the JWT remains secure and efficient.
+ *
+ * @since 1.0.0
+ * @version 1.0.0
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD})
+public @interface ExcludeFromPayload {
+}
diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/annotations/package-info.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/annotations/package-info.java
new file mode 100644
index 0000000..86f3e22
--- /dev/null
+++ b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/annotations/package-info.java
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+/**
+ * This package contains annotation classes that are used to prevent annotated
+ * properties from being automatically injected into the JSON Web Token (JWT)
+ * payload during token generation. These annotations can be applied to
+ * properties of a data class to exclude them from being included as part
+ * of the JWT payload.
+ *
+ * @version 1.0.0
+ * @since 1.0.0
+ */
+package cn.org.codecrafters.simplejwt.annotations;
\ No newline at end of file
diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/config/TokenResolverConfig.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/config/TokenResolverConfig.java
new file mode 100644
index 0000000..3b4473c
--- /dev/null
+++ b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/config/TokenResolverConfig.java
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+package cn.org.codecrafters.simplejwt.config;
+
+import cn.org.codecrafters.simplejwt.constants.TokenAlgorithm;
+
+/**
+ * The TokenResolverConfig interface provides a mechanism to configure a
+ * TokenResolver with algorithm functions.
+ *
+ * This generic interface is used to define the configuration details for a
+ * TokenResolver that utilizes algorithm functions. The interface allows for
+ * specifying algorithm functions corresponding to different TokenAlgorithm
+ * instances supported by the TokenResolver implementation.
+ *
+ * @param
+ * This method returns the algorithm function associated with the given
+ * TokenAlgorithm. The provided TokenAlgorithm represents the specific
+ * algorithm for which the corresponding algorithm function is required.
+ * The returned AlgorithmFunction represents the function implementation
+ * that can be used by the TokenResolver to handle the specific algorithm.
+ *
+ * @param algorithm the TokenAlgorithm for which the algorithm function is
+ * required
+ * @return the algorithm function associated with the given TokenAlgorithm
+ */
+ AlgorithmFunction getFunction(TokenAlgorithm algorithm);
+
+}
diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/constants/PredefinedKeys.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/constants/PredefinedKeys.java
new file mode 100644
index 0000000..4f0ac16
--- /dev/null
+++ b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/constants/PredefinedKeys.java
@@ -0,0 +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.
+ */
+
+package cn.org.codecrafters.simplejwt.constants;
+
+import java.util.List;
+
+/**
+ * PredefinedKeys
+ *
+ * @author Zihlu Wang
+ */
+public final class PredefinedKeys {
+
+ public static final List Supported Algorithms:
+ * This enum includes the following supported algorithms:
+ *
+ * To support a specified algorithm, you could
+ *
+ * @author Zihlu Wang
+ */
+public class UnsupportedAlgorithmException extends RuntimeException {
+
+ /**
+ * Constructs a new runtime exception with {@code null} as its
+ * detail message. The cause is not initialized, and may subsequently be
+ * initialized by a call to {@link #initCause}.
+ */
+ public UnsupportedAlgorithmException() {
+ }
+
+ /**
+ * Constructs a new runtime exception with the specified detail message.
+ * The cause is not initialized, and may subsequently be initialized by a
+ * call to {@link #initCause}.
+ *
+ * @param message the detail message. The detail message is saved for
+ * later retrieval by the {@link #getMessage()} method.
+ */
+ public UnsupportedAlgorithmException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a new runtime exception with the specified detail message and
+ * cause. Note that the detail message associated with
+ * {@code cause} is not automatically incorporated in
+ * this runtime exception's detail message.
+ *
+ * @param message the detail message (which is saved for later retrieval
+ * by the {@link #getMessage()} method).
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A {@code null} value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public UnsupportedAlgorithmException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructs a new runtime exception with the specified cause and a
+ * detail message of {@code (cause==null ? null : cause.toString())}
+ * (which typically contains the class and detail message of
+ * {@code cause}). This constructor is useful for runtime exceptions
+ * that are little more than wrappers for other throwables.
+ *
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A {@code null} value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public UnsupportedAlgorithmException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructs a new runtime exception with the specified detail
+ * message, cause, suppression enabled or disabled, and writable
+ * stack trace enabled or disabled.
+ *
+ * @param message the detail message.
+ * @param cause the cause. (A {@code null} value is permitted,
+ * and indicates that the cause is nonexistent or unknown.)
+ * @param enableSuppression whether or not suppression is enabled
+ * or disabled
+ * @param writableStackTrace whether or not the stack trace should
+ * be writable
+ * @since 1.7
+ */
+ public UnsupportedAlgorithmException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+}
ExcludeFromPayload
+ * Annotation to Exclude Property from JWT Payload.
+ * {@code
+ * public class UserData implements TokenPayload {
+ * private String username;
+ *
+ * // This property will not be included in the JWT payload
+ * {@literal @}ExcludeFromPayload
+ * private String sensitiveData;
+ *
+ * // Getters and setters...
+ * }
+ * }
+ *
+ *
+ *
+ *
+ * @since 1.0.0
+ * @version 1.0.0
+ */
+@Getter
+public enum TokenAlgorithm {
+ HS256,
+ HS384,
+ HS512,
+ RS256,
+ RS384,
+ RS512,
+ ES256,
+ ES384,
+ ES512,
+ ;
+
+}
diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/constants/package-info.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/constants/package-info.java
new file mode 100644
index 0000000..192ea9d
--- /dev/null
+++ b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/constants/package-info.java
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+/**
+ * This package contains constant values related to JSON Web Token (JWT)
+ * processing. These constants define various aspects of JWT, such as the
+ * algorithms being used for token signing and verification, and other
+ * configuration parameters.
+ *
+ * @since 1.0.0
+ * @version 1.0.0
+ */
+package cn.org.codecrafters.simplejwt.constants;
\ No newline at end of file
diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/exceptions/UnsupportedAlgorithmException.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/exceptions/UnsupportedAlgorithmException.java
new file mode 100644
index 0000000..54d14a5
--- /dev/null
+++ b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/exceptions/UnsupportedAlgorithmException.java
@@ -0,0 +1,102 @@
+/*
+ * 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.
+ */
+
+package cn.org.codecrafters.simplejwt.exceptions;
+
+/**
+ * This {@code UnsupportedAlgorithmException} is to indicates that the given
+ * algorithm is not supported by TokenResolver yet.
+ *