diff --git a/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/Base64Util.java b/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/Base64Util.java index eff3ca7..e3548ab 100644 --- a/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/Base64Util.java +++ b/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/Base64Util.java @@ -22,19 +22,18 @@ import java.nio.charset.StandardCharsets; import java.util.Base64; /** - * Utility class for Base64 encoding and decoding of strings. *
* The {@code Base64Util} class provides static methods to encode and decode * strings using Base64 encoding. It utilizes the {@link Base64} class from the * Java standard library for performing the encoding and decoding operations. * This utility class offers convenient methods to encode and decode strings * with different character sets. - *
+ * ** This class is designed as a final class with a private constructor to * prevent instantiation. All methods in this class are static, allowing easy * access to the Base64 encoding and decoding functionality. - *
+ * ** Example usage: *
@@ -48,12 +47,12 @@ import java.util.Base64;
* String decoded = Base64Util.decode(encoded);
* System.out.println("Decoded string: " + decoded);
*
- *
+ *
* * Note: This utility class uses the default charset (UTF-8) if no * specific charset is provided. It is recommended to specify the charset * explicitly to ensure consistent encoding and decoding. - *
+ * * * @author Zihlu Wang * @version 1.0.0 diff --git a/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/BranchUtil.java b/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/BranchUtil.java index 9019414..6e242b1 100644 --- a/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/BranchUtil.java +++ b/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/BranchUtil.java @@ -23,18 +23,19 @@ import java.util.function.BooleanSupplier; import java.util.function.Supplier; /** - * Utility class to simplify if...else logic using lambda expressions. ** The BranchUtil class provides static methods to simplify conditional logic * in Java development by leveraging lambda expressions. It offers convenient * methods to replace verbose if...else statements with more concise and * expressive functional constructs. - *
+ * + * ** Developers can use the methods in this utility class to streamline their * code, enhance readability, and promote a more functional style of * programming when dealing with branching logic and conditional statements. - *
+ * + * ** Example: *
@@ -66,12 +67,11 @@ import java.util.function.Supplier; * // do something * }); *- * + * *
* Note: * The {@link #and(Boolean...)} and {@link #or(Boolean...)} methods accept any * number of boolean expressions. - *
* * @param* Handles the result of the boolean expressions by executing the * appropriate handler based on the result. - *
+ * ** If the result is {@code true}, the {@code ifHandler} is executed. If the * result is {@code false} and an {@code elseHandler} is provided, it is * executed. - *
+ * ** Returns the result of the executed handler. - *
* * @param ifHandler the handler to be executed if the result is * {@code true} @@ -200,10 +199,9 @@ public final class BranchUtil* Handles the result of the boolean expressions by executing the provided * handler if the result is {@code true}. - *
+ * ** Returns the result of the executed handler. - *
* * @param ifHandler the handler to be executed if the result is * {@code true} @@ -217,12 +215,11 @@ public final class BranchUtil* Handles the result of the boolean expressions by executing the * appropriate handler based on the result. - *
+ * ** If the result is {@code true}, the {@code ifHandler} is executed. If the * result is {@code false} and an {@code elseHandler} is provided, it is * executed. - *
* * @param ifHandler the handler to be executed if the result is * {@code true} diff --git a/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/ChainedCalcUtil.java b/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/ChainedCalcUtil.java index 3c1651d..5817d88 100644 --- a/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/ChainedCalcUtil.java +++ b/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/ChainedCalcUtil.java @@ -26,7 +26,8 @@ import java.util.function.Function; /** ** Utility class for chained high-precision calculations using BigDecimal. - *
+ * + * ** The ChainedCalcUtil class provides a convenient way to perform chained * high-precision calculations using BigDecimal. It allows users to perform @@ -34,7 +35,8 @@ import java.util.function.Function; * and division with customizable precision and scale. By using this utility * class, developers can achieve accurate results and avoid precision loss * in their calculations. - *
+ * + * ** Usage: *
@@ -83,14 +85,13 @@ import java.util.function.Function; ** The above expressions perform various mathematical calculations using the * ChainedCalcUtil class. - * + * *
* Note: * The ChainedCalcUtil class internally uses BigDecimal to handle * high-precision calculations. It is important to note that BigDecimal * operations can be memory-intensive and may have performance implications * for extremely large numbers or complex calculations. - *
* * @author sunzsh * @version 1.0.0 diff --git a/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/HashUtil.java b/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/HashUtil.java index fd6ac41..37bb01b 100644 --- a/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/HashUtil.java +++ b/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/HashUtil.java @@ -27,13 +27,13 @@ import java.util.Optional; /** ** Utility class for performing hash operations on strings. - *
+ * ** The HashUtil class provides convenient methods for calculating various hash * functions on strings, including MD2, MD5, SHA-1, SHA-224, SHA-256, SHA-384, * and SHA-512. It allows developers to easily obtain the hash value of a given * string using different algorithms. - *
+ * ** Example usage: *
@@ -60,14 +60,13 @@ import java.util.Optional; ** The above examples demonstrate how to use the HashUtil class to calculate * hash values for a given string using different algorithms. - * + * *
* Note: * The hash functions provided by the HashUtil class are one-way hash * functions, meaning the original data cannot be retrieved from the hash * value. These hash functions are commonly used for data integrity checks and * password storage, but they should not be used for encryption purposes. - *
* * @author Zihlu Wang * @version 1.0.0 diff --git a/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/MapUtil.java b/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/MapUtil.java index 9258772..3d2cf36 100644 --- a/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/MapUtil.java +++ b/dev-utils/src/main/java/cn/org/codecrafters/devkit/utils/MapUtil.java @@ -27,11 +27,10 @@ import java.util.Map; ** MapUtil is a utility class that provides methods for converting objects to * maps and maps to objects. - *
+ * ** It also provides methods for getting and setting field values using * reflection. - *
* * @author Zihlu Wang * @version 1.0.0 @@ -150,6 +149,7 @@ public final class MapUtil { * field * @throws InvocationTargetException if an error occurs while invoking the * field getter method + * @throws NoSuchMethodException if the specified getter is not present */ public static* This package is part of JDevKit, an open-source Java Development Kit that * provides a set of convenient tools to streamline code development and * enhance productivity. This package serves as the root package for the module * dev-utils, which contains a collection of common utility classes commonly * used in all Java Application development. - *
* * @author Zihlu Wang * @since 1.0.0 diff --git a/devkit-core/src/main/java/cn/org/codecrafters/devkit/core/exceptions/NotImplementedException.java b/devkit-core/src/main/java/cn/org/codecrafters/devkit/core/exceptions/NotImplementedException.java index f10e78f..dbf1b5a 100644 --- a/devkit-core/src/main/java/cn/org/codecrafters/devkit/core/exceptions/NotImplementedException.java +++ b/devkit-core/src/main/java/cn/org/codecrafters/devkit/core/exceptions/NotImplementedException.java @@ -24,15 +24,16 @@ package cn.org.codecrafters.devkit.core.exceptions; * that represents a situation where a particular method or functionality is * not implemented or is currently unavailable in the codebase. It extends the * standard {@code RuntimeException} class, making it an unchecked exception. - * + * ** This exception is typically thrown when developers need to indicate that a * specific part of the code is incomplete or requires further implementation. * It serves as a placeholder to highlight unfinished sections of the * application during development and testing phases. - *
+ * ** Usage Example: + * *
* public void someMethod() {
* // Some code...
@@ -41,13 +42,8 @@ package cn.org.codecrafters.devkit.core.exceptions;
* """);
* }
*
- *
- * - * For more information and the latest version of JDevKit, please visit our - * website codecrafters.org.cn. - *
- *- *
* This package is a part of JDevKit, an open-source Java Development Kit that * provides a set of convenient tools to streamline code development and * enhance productivity. This package serves as the core package containing * common exceptions that are used throughout the entireJDevKit project. - *
+ * ** JDevKit is designed to be modular, and other specific feature modules within * the library may rely on these exceptions from the core package. - *
+ * ** For more information and the latest version of JDevKit, please visit our * website codecrafters.org.cn. - *
+ * *- *
* This package is the main part of JDevKit, an open-source Java class library * that provides a set of convenient tools to streamline code development and * enhance productivity. This package serves as the root package for several * modules, containing devkit-core, guid and dev-utils module. - *
+ * ** For more information and the latest version of JDevKit, please visit our * website codecrafters.org.cn. - *
+ * *- *
* The {@code GuidCreator} is a generic interface for generating globally unique * identifiers (GUIDs) of a specific type. - *
+ * ** The type of ID is determined by the class implementing this interface. - *
+ * * * @param* SnowflakeGuidCreator - GUID generator based on the Snowflake algorithm. - *
+ * ** The SnowflakeGuidCreator generates unique identifiers using the Snowflake * algorithm, which combines a timestamp, worker ID, and data center ID to @@ -38,7 +38,6 @@ import java.time.ZoneOffset; *
* When initializing the SnowflakeGuidCreator, you must provide the worker ID @@ -47,7 +46,6 @@ import java.time.ZoneOffset; * increments for IDs generated within the same millisecond. If the system * clock moves backward, an exception is thrown to prevent generating IDs with * repeated timestamps. - *
* * @author Zihlu Wang * @version 1.0.0 diff --git a/guid/src/main/java/cn/org/codecrafters/guid/exceptions/TimingException.java b/guid/src/main/java/cn/org/codecrafters/guid/exceptions/TimingException.java index 57ae91e..08c446c 100644 --- a/guid/src/main/java/cn/org/codecrafters/guid/exceptions/TimingException.java +++ b/guid/src/main/java/cn/org/codecrafters/guid/exceptions/TimingException.java @@ -21,24 +21,24 @@ package cn.org.codecrafters.guid.exceptions; ** The TimingException class represents an exception that is thrown when there * is an error related to time sequence. - *
+ * ** This class extends the RuntimeException class, which means that instances of * TimingException do not need to be declared in a method or constructor's * throws clause. - *
+ * ** Instances of TimingException can be created with or without a message and a * cause. The message provides a description of the exception, while the cause * represents the underlying cause of the exception and provides additional * information about the error. - *
+ * ** TimingException is typically used to handle exceptions related to timing, * such as timeouts or synchronization issues. It is a subclass of * RuntimeException, which means it is an unchecked exception and does not need * to be caught or declared. - *
+ * * * @author Zihlu Wang * @since 1.0.0 diff --git a/guid/src/main/java/cn/org/codecrafters/guid/exceptions/package-info.java b/guid/src/main/java/cn/org/codecrafters/guid/exceptions/package-info.java index 1fac43d..565cad2 100644 --- a/guid/src/main/java/cn/org/codecrafters/guid/exceptions/package-info.java +++ b/guid/src/main/java/cn/org/codecrafters/guid/exceptions/package-info.java @@ -20,14 +20,12 @@ * This package contains the custom exception classes related to GUID * generation. These exceptions are thrown when there are issues or errors * during the generation or processing of global unique identifiers (GUIDs). - * * ** The main exception class in this package is {@link * cn.org.codecrafters.guid.exceptions.TimingException}, which is a runtime * exception and serves as the base exception for all other custom exceptions * related to GUID generation. - *
* ** Custom exceptions in this package provide specific information about the @@ -36,13 +34,11 @@ * GUIDs. They are designed to enhance the robustness and reliability of the * GUID generation process by providing clear and meaningful error messages to * the developers. - *
* ** Developers using the GUID generation module should be aware of the possible * exceptions that can be thrown and handle them appropriately to ensure smooth * operation and error handling in their applications. - *
* * @since 1.0.0 */ diff --git a/guid/src/main/java/cn/org/codecrafters/guid/package-info.java b/guid/src/main/java/cn/org/codecrafters/guid/package-info.java index c102a7d..8e7f31a 100644 --- a/guid/src/main/java/cn/org/codecrafters/guid/package-info.java +++ b/guid/src/main/java/cn/org/codecrafters/guid/package-info.java @@ -19,12 +19,12 @@ ** The package provides a set of tools for generating globally unique * identifiers (GUIDs). - *
+ * ** The goal of this library is to provide an efficient, reliable way to * generate globally unique identifiers without requiring any specific * environment or configuration. - *
+ * ** Key features include: *
* Dependencies: * This implementation relies on the {@code com.auth0:java-jwt} library. Please * ensure you have added this library as a dependency to your project before * using this resolver. - *
+ * ** Usage: * To use the {@code AuthzeroTokenResolver}, first, create an instance of this @@ -61,7 +61,7 @@ import java.util.*; * "Token Issuer", * "Token Secret"); * } - *
+ * ** Then, you can utilize the various methods provided by this resolver to * handle JWT tokens: @@ -82,14 +82,13 @@ import java.util.*; * String renewedToken = * tokenResolver.renew(token, Duration.ofMinutes(30), customPayloads); * } - *
+ * ** Note: * It is essential to configure the appropriate algorithms, secret, and issuer * according to your specific use case when using this resolver. * Additionally, ensure that the {@code com.auth0:java-jwt} library is * correctly configured in your project's dependencies. - *
* * @author Zihlu Wang * @version 1.0.0 @@ -264,10 +263,9 @@ public class AuthzeroTokenResolver implements TokenResolver* Finish creating a token. - *
+ * ** This is the final step of create a token, to sign this token. - *
* * @param builder the builder to build this JWT * @return the generated token as a {@code String} diff --git a/simple-jwt-authzero/src/main/java/cn/org/codecrafters/simplejwt/authzero/config/AuthzeroTokenResolverConfig.java b/simple-jwt-authzero/src/main/java/cn/org/codecrafters/simplejwt/authzero/config/AuthzeroTokenResolverConfig.java index 2d370f9..63ca6ae 100644 --- a/simple-jwt-authzero/src/main/java/cn/org/codecrafters/simplejwt/authzero/config/AuthzeroTokenResolverConfig.java +++ b/simple-jwt-authzero/src/main/java/cn/org/codecrafters/simplejwt/authzero/config/AuthzeroTokenResolverConfig.java @@ -64,12 +64,11 @@ public final class AuthzeroTokenResolverConfig implements TokenResolverConfig* The constructor is set as private to enforce the singleton pattern for * this configuration class. Instances of AuthzeroTokenResolverConfig * should be obtained through the {@link #getInstance()} method. - *
*/ private AuthzeroTokenResolverConfig() { } @@ -77,20 +76,19 @@ public final class AuthzeroTokenResolverConfig implements TokenResolverConfig* This instance is used to ensure that only one instance of * AuthzeroTokenResolverConfig is created and shared throughout the * application. The singleton pattern is implemented to provide centralized * configuration and avoid redundant object creation. - *
*/ private static AuthzeroTokenResolverConfig instance; /** ** The supported algorithms and their corresponding algorithm functions. - *
+ * *
* This map stores the supported algorithms as keys and their corresponding
* algorithm functions as values. The algorithm functions represent the
@@ -126,14 +124,13 @@ public final class AuthzeroTokenResolverConfig implements TokenResolverConfig
* 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 diff --git a/simple-jwt-authzero/src/main/java/cn/org/codecrafters/simplejwt/authzero/config/package-info.java b/simple-jwt-authzero/src/main/java/cn/org/codecrafters/simplejwt/authzero/config/package-info.java index a5d8517..19f0774 100644 --- a/simple-jwt-authzero/src/main/java/cn/org/codecrafters/simplejwt/authzero/config/package-info.java +++ b/simple-jwt-authzero/src/main/java/cn/org/codecrafters/simplejwt/authzero/config/package-info.java @@ -21,13 +21,11 @@ * configuration classes related to the {@link * cn.org.codecrafters.simplejwt.authzero.AuthzeroTokenResolver} * implementation. - * * ** The classes in this package provide configuration options and settings for * the {@link cn.org.codecrafters.simplejwt.authzero.AuthzeroTokenResolver}, * which is used for resolving JSON Web Tokens (JWT) using the Auth0 library. - *
* ** The {@link @@ -39,7 +37,6 @@ * JWT algorithms. It enables developers to specify and customize the * algorithm functions according to the chosen JWT algorithm and the library * being used. - *
* ** The configuration options in this package help developers integrate and @@ -48,7 +45,6 @@ * into their Spring Boot applications. Developers can fine-tune the token * resolution process and customize algorithm handling to align with their * specific requirements and desired level of security. - *
* ** It is recommended to explore the classes in this package to understand how @@ -56,7 +52,6 @@ * cn.org.codecrafters.simplejwt.authzero.AuthzeroTokenResolver} effectively * in the Spring Boot environment to handle JWT authentication and * authorization securely and efficiently. - *
* * @since 1.0.0 */ diff --git a/simple-jwt-authzero/src/main/java/cn/org/codecrafters/simplejwt/authzero/package-info.java b/simple-jwt-authzero/src/main/java/cn/org/codecrafters/simplejwt/authzero/package-info.java index 0ac8dd8..624013f 100644 --- a/simple-jwt-authzero/src/main/java/cn/org/codecrafters/simplejwt/authzero/package-info.java +++ b/simple-jwt-authzero/src/main/java/cn/org/codecrafters/simplejwt/authzero/package-info.java @@ -16,20 +16,16 @@ */ /** - ** This package contains classes related to the integration of the {@code - * com.auth0:java-jwt} library in the Simple JWT project. {@code + * com.auth0:java-jwt} library in the Simple JWT project. {@code * com.auth0:java-jwt} is a powerful and widely-used Identity as a Service * (IDaaS) platform that provides secure authentication and authorization * solutions for web and mobile applications. The classes in this package * provide the necessary functionality to handle JSON Web Tokens (JWTs) using * the {@code com.auth0:java-jwt} library. - *
* *- * The main class in this package is the {@link + * The main class in this package is the {@link * cn.org.codecrafters.simplejwt.authzero.AuthzeroTokenResolver}, which * implements the {@link cn.org.codecrafters.simplejwt.TokenResolver} interface * and uses the {@code com.auth0:java-jwt} library to handle JWT operations. It @@ -37,7 +33,6 @@ * {@code com.auth0:java-jwt} library. Developers can use this class as the * main token resolver in the Simple JWT project when integrating {@code * com.auth0:java-jwt} as the JWT management library. - *
* ** The {@code AuthzeroTokenResolver} relies on the {@code com.auth0:java-jwt} @@ -45,7 +40,6 @@ * validation, and extraction. It utilizes the {@code com.auth0:java-jwt} * {@code Algorithm} class to define and use different algorithms for JWT * signing and verification. - *
* ** To use the {@code AuthzeroTokenResolver}, developers must provide the @@ -54,14 +48,12 @@ * issuer name, and the secret key used for token signing and validation. The * {@code AuthzeroTokenResolverConfig} class provides a convenient way to * configure these dependencies. - *
* ** Developers using the {@code com.auth0:java-jwt} integration should be * familiar with the concepts and usage of the {@code com.auth0:java-jwt} * library and follow the official {@code com.auth0:java-jwt} documentation for * best practices and security considerations. - *
* * @since 1.0.0 */ diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenPayload.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenPayload.java index 298a8e7..a7b5d0c 100644 --- a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenPayload.java +++ b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenPayload.java @@ -22,19 +22,19 @@ import java.util.Map; /** ** TokenPayload - Interface for JWT Payload Data Classes. - *
+ * ** The {@code TokenPayload} interface is used to mark a data class as suitable * for being used as the payload in a JSON Web Token (JWT). Any class * implementing this interface can be used to represent the payload data that * will be included in a JWT. - *
+ * ** Implementing this interface indicates that the data class contains * information that needs to be securely transmitted and verified as part of a * JWT. The payload typically contains claims or attributes that provide * additional information about the JWT subject or context. - *
+ * ** Usage: * To use a class as a JWT payload, simply implement the {@code TokenPayload} @@ -44,7 +44,6 @@ import java.util.Map; * // Class implementation with payload data... * } * - *
* * @since 1.0.0 * @version 1.0.0 diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenResolver.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenResolver.java index d256c0c..a4c9ff0 100644 --- a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenResolver.java +++ b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenResolver.java @@ -26,26 +26,25 @@ import java.util.Map; * extracting, and renewing tokens, particularly JSON Web Tokens (JWTs). It * provides a set of methods to generate tokens with various payload * configurations, extract payloads from tokens, and renew expired tokens. - * + * ** Token Creation: * The interface provides overloaded methods for creating tokens with different * payload configurations, including expiration time, audience, subject, and * custom payload data. Clients can choose the appropriate method based on * their specific token requirements. - *
+ * ** Token Extraction: * The interface includes methods to extract payload information from a given * token. Clients can use these methods to obtain the payload data encoded in * the token. - *
+ * ** Token Renewal: * The interface also offers methods for token renewal. Clients can renew an * 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 @@ -47,17 +45,15 @@ import java.lang.annotation.Target; * // Getters and setters... * } * } - *
* *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 + * @since 1.0.0 */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD}) 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 index d8aafc5..9f80df0 100644 --- 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 @@ -23,13 +23,13 @@ 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* Other configuration classes may be added in the future to support additional * customization options and features. Developers using the Simple JWT library * should be familiar with the available configuration options to ensure proper * integration and usage of the library. - *
* * @since 1.0.0 */ 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 index 093ec63..c648b19 100644 --- 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 @@ -20,47 +20,77 @@ package cn.org.codecrafters.simplejwt.constants; import java.util.List; /** - *- * This class contains predefined keys that are commonly used in JSON Web - * Tokens (JWT). - *
+ * The {@code PredefinedKeys} class contains constants for standard JSON Web Token (JWT) claims. These constants + * represent the names of the standard claims that can be included in a JWT payload. Developers can use these constants + * when working with JWTs to ensure consistent naming of the claims. * - *- * JWTs consist of a set of claims represented as key-value pairs. These claims - * store various pieces of information, such as the subject, issuer, expiration - * time, and more. To ensure consistency and avoid spelling mistakes, this - * class provides constants for the standard keys used in JWT claims. - *
+ *The class provides the following standard JWT claim constants: + *
- * Developers using this JWT library can use these predefined keys to set and - * retrieve claims in a safer and more readable way. By using constants instead - * of plain strings, it helps prevent typos and makes the code more - * maintainable. - *
+ *The class also contains a list of all the standard claim constants, accessible via the {@link #KEYS} field. This + * list can be useful for iterating through all the standard claims or checking for the presence of specific claims. + * + *
Note: This class is final and cannot be instantiated. It only serves as a utility class to hold the standard JWT
+ * claim constants.
*
* @since 1.0.0
*/
public final class PredefinedKeys {
- // Constants for standard JWT claims
+ /**
+ * Constant representing the "iss" (Issuer) claim in a JWT payload.
+ */
public static final String ISSUER = "iss";
+ /**
+ * Constant representing the "sub" (Subject) claim in a JWT payload.
+ */
public static final String SUBJECT = "sub";
+ /**
+ * Constant representing the "aud" (Audience) claim in a JWT payload.
+ */
public static final String AUDIENCE = "aud";
+ /**
+ * Constant representing the "exp" (Expiration Time) claim in a JWT payload.
+ */
public static final String EXPIRATION_TIME = "exp";
+ /**
+ * Constant representing the "nbf" (Not Before) claim in a JWT payload.
+ */
public static final String NOT_BEFORE = "nbf";
+ /**
+ * Constant representing the "iat" (Issued At) claim in a JWT payload.
+ */
public static final String ISSUED_AT = "iat";
+ /**
+ * Constant representing the "jti" (JWT ID) claim in a JWT payload.
+ */
public static final String JWT_ID = "jti";
+ /**
+ * List containing all the standard JWT claim constants.
+ */
+ public static final List
* The {@code TokenAlgorithm} enum class defines the algorithms that can be
* used for signing and verifying JSON Web Tokens (JWT). JWT allows various
* cryptographic algorithms to be used for secure token generation and
* validation. This enum provides a list of supported algorithms to ensure
* consistent usage and avoid potential security issues.
- * Supported Algorithms:
* This enum includes the following supported algorithms:
*
@@ -40,21 +39,56 @@ import lombok.Getter;
*
- *
* This {@code UnsupportedAlgorithmException} is to indicates that the given * algorithm is not supported by TokenResolver yet. - *
+ * ** To support a specified algorithm, you could - *
+ * * * @author Zihlu Wang */ @@ -54,11 +54,11 @@ public class UnsupportedAlgorithmException extends RuntimeException { ** 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). diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/exceptions/package-info.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/exceptions/package-info.java index b9fec6e..fcd7929 100644 --- a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/exceptions/package-info.java +++ b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/exceptions/package-info.java @@ -21,7 +21,7 @@ * custom exception classes related to the Simple JWT library. These * exceptions are thrown when there are issues or errors during the generation * , validation, or processing of JSON Web Tokens (JWTs) in Java applications. - * + * * ** Custom exception classes in this package are designed to enhance the @@ -30,13 +30,12 @@ * identify and troubleshoot issues related to JWT generation, validation, or * extraction and ensure smooth operation and error handling in their * applications. - *
+ * * ** Developers using the Simple JWT library should be aware of the possible * exceptions that can be thrown and handle them appropriately to ensure secure * and reliable JWT handling in their Java applications. - *
* * @since 1.0.0 */ diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/package-info.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/package-info.java index dd2441c..feca898 100644 --- a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/package-info.java +++ b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/package-info.java @@ -24,7 +24,7 @@ * used to secure web and mobile applications. This library aims to simplify * the JWT handling process and provide convenient abstractions for JWT * generation, validation, and extraction. - * + * * ** The Simple JWT library is designed to be flexible and customizable, allowing @@ -32,13 +32,13 @@ * classes based on their specific application requirements. It aims to * simplify the JWT handling process while maintaining security and best * practices for working with JWTs. - *
+ * * ** Developers should refer to the official documentation and examples for the * Simple JWT project to understand how to use the library effectively and * securely in their Java applications. - *
+ * * * @since 1.0.0 */ diff --git a/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/autoconfiguration/GuidAutoConfiguration.java b/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/autoconfiguration/GuidAutoConfiguration.java new file mode 100644 index 0000000..aa64a11 --- /dev/null +++ b/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/autoconfiguration/GuidAutoConfiguration.java @@ -0,0 +1,45 @@ +/* + * 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.autoconfiguration; + +import cn.org.codecrafters.guid.GuidCreator; +import cn.org.codecrafters.simplejwt.autoconfiguration.properties.SimpleJwtProperties; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; + +import java.util.UUID; + +/** + * GuidAutoConfiguration + * + * @author Zihlu Wang + */ +@Slf4j +@AutoConfiguration +@ConditionalOnMissingBean(value = GuidCreator.class, name = "jtiCreator") +public class GuidAutoConfiguration { + + @Bean + public GuidCreator* This auto-configuration class sets up the necessary beans and components * required for JWT generation and validation. It automatically creates and * configures the {@link TokenResolver} bean based on the available options and * properties. - *
+ * * ** Developers using the Simple JWT library with Spring Boot do not need to @@ -54,31 +55,21 @@ import java.util.UUID; * setting up the necessary components and configurations automatically. * However, developers still have the flexibility to customize the behavior of * the library by providing their own configurations and properties. - *
+ * * * @author Zihlu Wang * @version 1.0.0 * @since 1.0.0 */ @Slf4j -@Configuration +@AutoConfiguration @EnableConfigurationProperties(value = {SimpleJwtProperties.class}) public class SimpleJwtAutoConfiguration { /** * The GuidCreator instance to be used for generating JWT IDs (JTI). */ - private GuidCreator> jtiCreator; - - /** - * Sets the GuidCreator instance to be used for generating JWT IDs (JTI). - * - * @param jtiCreator the {@code GuidCreator} instance - */ - @Autowired - public void setJtiCreator(GuidCreator> jtiCreator) { - this.jtiCreator = jtiCreator; - } + private final GuidCreator> jtiCreator; /** * The {@code SimpleJwtProperties} instance containing the configuration @@ -93,23 +84,11 @@ public class SimpleJwtAutoConfiguration { * @param simpleJwtProperties the SimpleJwtProperties instance */ @Autowired - public SimpleJwtAutoConfiguration(SimpleJwtProperties simpleJwtProperties) { + public SimpleJwtAutoConfiguration(SimpleJwtProperties simpleJwtProperties, GuidCreator> jtiCreator) { + this.jtiCreator = jtiCreator; this.simpleJwtProperties = simpleJwtProperties; } - /** - * Creates a new {@code GuidCreator} bean if no existing bean with the name - * "jtiCreator" is found. The created {@code GuidCreator} is used for - * generating JWT IDs (JTI). - * - * @return the GuidCreator instance - */ - @Bean - @ConditionalOnMissingBean(value = GuidCreator.class, name = "jtiCreator") - public GuidCreator> jtiCreator() { - return (GuidCreator* Developers using the Simple JWT library with Spring Boot do not need to @@ -31,7 +31,7 @@ * automatically. However, developers still have the flexibility to customize * the behavior of the library by providing their own configurations and * properties. - *
+ * * * @since 1.0.0 */ diff --git a/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/autoconfiguration/properties/SimpleJwtProperties.java b/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/autoconfiguration/properties/SimpleJwtProperties.java index 57d00a8..4ae153c 100644 --- a/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/autoconfiguration/properties/SimpleJwtProperties.java +++ b/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/autoconfiguration/properties/SimpleJwtProperties.java @@ -27,7 +27,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * store the properties related to Simple JWT library configuration. These * properties can be configured in the application's properties file (e.g., * application.properties) with the prefix "code-crafters.simple-jwt". - * + * * ** SimpleJwtProperties provides configuration options for the JWT algorithm, @@ -35,14 +35,14 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * cn.org.codecrafters.simplejwt.autoconfiguration.SimpleJwtAutoConfiguration} * class to set up the necessary configurations for JWT generation and * validation. - *
+ * * ** Developers can customize the JWT algorithm, issuer, and secret by setting * the corresponding properties in the application's properties file. The * SimpleJwtAutoConfiguration class reads these properties and uses them to * create the TokenResolver bean with the desired configuration. - *
+ * * * @since 1.0.0 */ diff --git a/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/autoconfiguration/properties/package-info.java b/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/autoconfiguration/properties/package-info.java index 4c154ea..fc5a7f4 100644 --- a/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/autoconfiguration/properties/package-info.java +++ b/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/autoconfiguration/properties/package-info.java @@ -23,7 +23,7 @@ * configured in the application's properties file (e.g., * application.properties) to customize the behavior and settings of the Simple * JWT library. - * + * * ** Developers can customize the JWT algorithm, issuer, and secret by setting @@ -32,7 +32,6 @@ * reads these properties and uses them to create the {@link * cn.org.codecrafters.simplejwt.TokenResolver} bean with the desired * configuration. - *
* * @since 1.0.0 */ diff --git a/simple-jwt-spring-boot-starter/src/main/resources/META-INF/springvorbote-webdev-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/simple-jwt-spring-boot-starter/src/main/resources/META-INF/springvorbote-webdev-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 7a213b1..0000000 --- a/simple-jwt-spring-boot-starter/src/main/resources/META-INF/springvorbote-webdev-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -cn.org.codecrafters.simplejwt.SimpleJwtAutoConfiguration \ No newline at end of file