docs(global): Optimised javadoc, changed the spelling to British English.
This commit is contained in:
+24
-27
@@ -122,11 +122,11 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
private final AuthzeroTokenResolverConfig config = AuthzeroTokenResolverConfig.getInstance();
|
||||
|
||||
/**
|
||||
* Creates a new instance of AuthzeroTokenResolver with the provided
|
||||
* configurations.
|
||||
* Creates a new instance of {@code AuthzeroTokenResolver} with the
|
||||
* provided configurations.
|
||||
*
|
||||
* @param jtiCreator the GuidCreator used for generating unique identifiers
|
||||
* for "jti" claim in JWT tokens
|
||||
* @param jtiCreator the {@link GuidCreator} used for generating unique
|
||||
* identifiers for "jti" claim in JWT tokens
|
||||
* @param algorithm the algorithm used for signing and verifying JWT
|
||||
* tokens
|
||||
* @param issuer the issuer claim value to be included in JWT tokens
|
||||
@@ -151,8 +151,8 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of AuthzeroTokenResolver with the provided
|
||||
* configurations and a simple UUID GuidCreator.
|
||||
* Creates a new instance of {@link AuthzeroTokenResolver} with the
|
||||
* provided configurations and a simple UUID GuidCreator.
|
||||
*
|
||||
* @param algorithm the algorithm used for signing and verifying JWT tokens
|
||||
* @param issuer the issuer claim value to be included in JWT tokens
|
||||
@@ -168,7 +168,7 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
log.warn("The provided secret which owns {} characters is too weak. Please consider replacing it with a stronger one.", secret.length());
|
||||
}
|
||||
|
||||
this.jtiCreator = (GuidCreator<UUID>) UUID::randomUUID;
|
||||
this.jtiCreator = UUID::randomUUID;
|
||||
this.algorithm = config
|
||||
.getAlgorithm(algorithm)
|
||||
.apply(secret);
|
||||
@@ -177,8 +177,9 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of AuthzeroTokenResolver with the provided
|
||||
* configurations, HMAC256 algorithm and a simple UUID GuidCreator.
|
||||
* Creates a new instance of {@link AuthzeroTokenResolver} with the
|
||||
* provided configurations, HMAC256 algorithm and a simple
|
||||
* UUID GuidCreator.
|
||||
*
|
||||
* @param issuer the issuer claim value to be included in JWT tokens
|
||||
* @param secret the secret used for HMAC-based algorithms (HS256,
|
||||
@@ -193,7 +194,7 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
log.warn("The provided secret which owns {} characters is too weak. Please consider replacing it with a stronger one.", secret.length());
|
||||
}
|
||||
|
||||
this.jtiCreator = (GuidCreator<UUID>) UUID::randomUUID;
|
||||
this.jtiCreator = UUID::randomUUID;
|
||||
this.algorithm = config
|
||||
.getAlgorithm(TokenAlgorithm.HS256)
|
||||
.apply(secret);
|
||||
@@ -202,15 +203,16 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of AuthzeroTokenResolver with the provided
|
||||
* configurations, HMAC256 algorithm and a simple UUID GuidCreator.
|
||||
* Creates a new instance of {@link AuthzeroTokenResolver} with the
|
||||
* provided configurations, HMAC256 algorithm and a simple
|
||||
* UUID GuidCreator.
|
||||
*
|
||||
* @param issuer the issuer claim value to be included in JWT tokens
|
||||
*/
|
||||
public AuthzeroTokenResolver(String issuer) {
|
||||
var secret = SecretCreator.createSecret(32, true, true, true);
|
||||
|
||||
this.jtiCreator = (GuidCreator<UUID>) UUID::randomUUID;
|
||||
this.jtiCreator = UUID::randomUUID;
|
||||
this.algorithm = config
|
||||
.getAlgorithm(TokenAlgorithm.HS256)
|
||||
.apply(secret);
|
||||
@@ -286,16 +288,13 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Builds the custom claims of the JSON Web Token (JWT) using the provided
|
||||
* Map of claims and adds them to the JWTCreator.Builder.
|
||||
* <p>
|
||||
* <p>
|
||||
* This method is used to add custom claims to the JWT. It takes a Map of
|
||||
* claims, where each entry represents a custom claim name (key) and its
|
||||
* corresponding value (value). The custom claims will be added to the JWT
|
||||
* using the JWTCreator.Builder.
|
||||
* <p>
|
||||
*
|
||||
* @param claims a Map containing the custom claims to be added to the JWT
|
||||
* @param builder the JWTCreator.Builder instance to which the custom
|
||||
@@ -310,9 +309,7 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Finish creating a token.
|
||||
*
|
||||
* <p>
|
||||
* This is the final step of create a token, to sign this token.
|
||||
*
|
||||
@@ -324,7 +321,7 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new token with the specified expiration time, subject, and
|
||||
* Creates a new token with the specified expiration duration, subject, and
|
||||
* audience.
|
||||
*
|
||||
* @param expireAfter the duration after which the token will expire
|
||||
@@ -387,7 +384,7 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
// Build Claims
|
||||
addClaim(builder, field.getName(), field.get(payload));
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error("Cannot access field %s!".formatted(field.getName()));
|
||||
log.error("Cannot access field {}!", field.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,10 +392,10 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the given token into a DecodedJWT object.
|
||||
* Resolves the given token into a {@link DecodedJWT} object.
|
||||
*
|
||||
* @param token the token to be resolved
|
||||
* @return a ResolvedToken object
|
||||
* @return a {@link DecodedJWT} object
|
||||
*/
|
||||
@Override
|
||||
public DecodedJWT resolve(String token) {
|
||||
@@ -449,9 +446,9 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
|
||||
return bean;
|
||||
} catch (NoSuchMethodException e) {
|
||||
log.error("Unable to find a no-argument constructor declaration for class %s.".formatted(targetType.getCanonicalName()));
|
||||
log.error("Unable to find a no-argument constructor declaration for class {}.", targetType.getCanonicalName());
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
log.error("Unable to create a new instance of class %s.".formatted(targetType.getCanonicalName()));
|
||||
log.error("Unable to create a new instance of class {}.", targetType.getCanonicalName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -475,7 +472,7 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
/**
|
||||
* Renews the given expired token with the specified custom payload data.
|
||||
*
|
||||
* @param oldToken the expired token to be renewed
|
||||
* @param oldToken the expiring token to be renewed
|
||||
* @param payload the custom payload data to be included in the renewed
|
||||
* token
|
||||
* @return the renewed token as a {@code String}
|
||||
@@ -489,7 +486,7 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
* Renews the given expired token with the new specified strongly-typed
|
||||
* payload data.
|
||||
*
|
||||
* @param oldToken the expired token to be renewed
|
||||
* @param oldToken the expiring token to be renewed
|
||||
* @param payload the strongly-typed payload data to be included in the
|
||||
* renewed token
|
||||
* @return the renewed token as a {@code String}
|
||||
@@ -511,7 +508,7 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
||||
* @param oldToken the expired token to be renewed
|
||||
* @param payload the strongly-typed payload data to be included in the
|
||||
* renewed token
|
||||
* @return the renewed token as a {@code String}
|
||||
* @return the renewed token as a {@link String}
|
||||
*/
|
||||
@Override
|
||||
public <T extends TokenPayload> String renew(String oldToken, T payload) {
|
||||
|
||||
+44
-47
@@ -17,6 +17,8 @@
|
||||
|
||||
package cn.org.codecrafters.simplejwt.authzero.config;
|
||||
|
||||
import cn.org.codecrafters.simplejwt.TokenResolver;
|
||||
import cn.org.codecrafters.simplejwt.authzero.AuthzeroTokenResolver;
|
||||
import cn.org.codecrafters.simplejwt.config.TokenResolverConfig;
|
||||
import cn.org.codecrafters.simplejwt.constants.TokenAlgorithm;
|
||||
import cn.org.codecrafters.simplejwt.exceptions.UnsupportedAlgorithmException;
|
||||
@@ -29,29 +31,29 @@ import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* The AuthzeroTokenResolverConfig class provides the configuration for the
|
||||
* AuthzeroTokenResolver.
|
||||
* The {@code AuthzeroTokenResolverConfig} class provides the configuration for
|
||||
* the {@link AuthzeroTokenResolver}.
|
||||
* <p>
|
||||
* This configuration class is used to establish the mapping between the
|
||||
* standard TokenAlgorithm defined within the AuthzeroTokenResolver facade and
|
||||
* the specific algorithms used by the Auth0 Java JWT library, which is the
|
||||
* underlying library used by AuthzeroTokenResolver to handle JSON Web Tokens
|
||||
* (JWTs).
|
||||
* This configuration is used to establish the mapping between the standard
|
||||
* {@link TokenAlgorithm} defined within the {@link AuthzeroTokenResolver}
|
||||
* facade and the specific algorithms used by the {@code com.auth0:java-jwt}
|
||||
* library, which is the underlying library used by {@link
|
||||
* AuthzeroTokenResolver} to handle JSON Web Tokens (JWTs).
|
||||
* <p>
|
||||
* <b>Algorithm Mapping:</b>
|
||||
* The AuthzeroTokenResolverConfig class allows specifying the relationship
|
||||
* between the standard TokenAlgorithm instances supported by
|
||||
* AuthzeroTokenResolver and the corresponding algorithms used by the
|
||||
* com.auth0:java-jwt library. The mapping is achieved using a Map, where the
|
||||
* keys are the standard TokenAlgorithm instances, and the values represent the
|
||||
* algorithm functions used by Auth0 Java JWT library for each corresponding
|
||||
* key.
|
||||
* The {@code AuthzeroTokenResolverConfig} allows specifying the relationship
|
||||
* between the standard {@link TokenAlgorithm} instances supported by
|
||||
* {@link AuthzeroTokenResolver} and the corresponding algorithms used by the
|
||||
* {@code com.auth0:java-jwt} library. The mapping is achieved using a Map,
|
||||
* where the keys are the standard TokenAlgorithm instances, and the values
|
||||
* represent the algorithm functions used by Auth0 Java JWT library for each
|
||||
* corresponding key.
|
||||
* <p>
|
||||
* <b>Note:</b>
|
||||
* The provided algorithm mapping should be consistent with the actual
|
||||
* algorithms supported and used by the Auth0 Java JWT library. It is crucial
|
||||
* to ensure that the mapping is accurate to enable proper token validation
|
||||
* and processing within the AuthzeroTokenResolver.
|
||||
* algorithms supported and used by the {@code com.auth0:java-jwt} library. It
|
||||
* is crucial to ensure that the mapping is accurate to enable proper token
|
||||
* validation and processing within the {@link AuthzeroTokenResolver}.
|
||||
*
|
||||
* @author Zihlu Wang
|
||||
* @version 1.1.0
|
||||
@@ -60,39 +62,34 @@ import java.util.function.Function;
|
||||
public final class AuthzeroTokenResolverConfig implements TokenResolverConfig<Function<String, Algorithm>> {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructs a new instance of AuthzeroTokenResolverConfig.
|
||||
*
|
||||
* Constructs a new instance of {@code AuthzeroTokenResolverConfig}.
|
||||
* <p>
|
||||
* 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.
|
||||
* this configuration class. Instances of
|
||||
* {@code AuthzeroTokenResolverConfig} should be obtained through the
|
||||
* {@link #getInstance()} method.
|
||||
*/
|
||||
private AuthzeroTokenResolverConfig() {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The singleton instance of AuthzeroTokenResolverConfig.
|
||||
*
|
||||
* The singleton instance of {@code AuthzeroTokenResolverConfig}.
|
||||
* <p>
|
||||
* 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
|
||||
* {@code AuthzeroTokenResolverConfig} is created and shared throughout the
|
||||
* application. The singleton pattern is implemented to provide centralised
|
||||
* configuration and avoid redundant object creation.
|
||||
*/
|
||||
private static AuthzeroTokenResolverConfig instance;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The supported algorithms and their corresponding algorithm functions.
|
||||
*
|
||||
* <p>
|
||||
* This map stores the supported algorithms as keys and their corresponding
|
||||
* algorithm functions as values. The algorithm functions represent the
|
||||
* functions used by the Auth0 Java JWT library to handle the specific
|
||||
* algorithms. The mapping is used to provide proper algorithm resolution
|
||||
* and processing within the AuthzeroTokenResolver.
|
||||
* functions used by the {@code com.auth0:java-jwt} library to handle the
|
||||
* specific algorithms. The mapping is used to provide proper algorithm
|
||||
* resolution and processing within the {@link AuthzeroTokenResolver}.
|
||||
*/
|
||||
private static final Map<TokenAlgorithm, Function<String, Algorithm>> SUPPORTED_ALGORITHMS = new HashMap<>() {{
|
||||
put(TokenAlgorithm.HS256, Algorithm::HMAC256);
|
||||
@@ -101,14 +98,14 @@ public final class AuthzeroTokenResolverConfig implements TokenResolverConfig<Fu
|
||||
}};
|
||||
|
||||
/**
|
||||
* Gets the instance of AuthzeroTokenResolverConfig.
|
||||
* Gets the instance of {@code AuthzeroTokenResolverConfig}.
|
||||
* <p>
|
||||
* This method returns the singleton instance of
|
||||
* AuthzeroTokenResolverConfig. If the instance is not yet created, it will
|
||||
* create a new instance and return it. Otherwise, it returns the existing
|
||||
* instance.
|
||||
* {@code AuthzeroTokenResolverConfig}. If the instance is not yet created,
|
||||
* it will create a new instance and return it. Otherwise, it returns the
|
||||
* existing instance.
|
||||
*
|
||||
* @return the instance of AuthzeroTokenResolverConfig
|
||||
* @return the instance of {@code AuthzeroTokenResolverConfig}
|
||||
*/
|
||||
public static AuthzeroTokenResolverConfig getInstance() {
|
||||
if (Objects.isNull(instance)) {
|
||||
@@ -119,20 +116,20 @@ public final class AuthzeroTokenResolverConfig implements TokenResolverConfig<Fu
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gets the algorithm function corresponding to the specified
|
||||
* TokenAlgorithm.
|
||||
*
|
||||
* {@link TokenAlgorithm}.
|
||||
* <p>
|
||||
* 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.
|
||||
* {@link TokenAlgorithm}. The provided {@link TokenAlgorithm} represents
|
||||
* the specific algorithm for which the corresponding algorithm function
|
||||
* is required. The returned Algorithm Function represents the function
|
||||
* implementation that can be used by the {@link 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
|
||||
* @param algorithm the {@link TokenAlgorithm} for which the algorithm
|
||||
* function isrequired
|
||||
* @return the algorithm function associated with the given {@link
|
||||
* TokenAlgorithm}
|
||||
* @throws UnsupportedAlgorithmException if the given {@code algorithm} is
|
||||
* not supported by this
|
||||
* implementation
|
||||
|
||||
+14
-11
@@ -33,18 +33,21 @@
|
||||
* main token resolver in the Simple JWT project when integrating {@code
|
||||
* com.auth0:java-jwt} as the JWT management library.
|
||||
* <p>
|
||||
* The {@code AuthzeroTokenResolver} relies on the {@code com.auth0:java-jwt}
|
||||
* library to handle the underlying JWT operations, including token creation,
|
||||
* 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.
|
||||
* The {@link cn.org.codecrafters.simplejwt.authzero.AuthzeroTokenResolver}
|
||||
* relies on the {@code com.auth0:java-jwt} library to handle the underlying
|
||||
* JWT operations, including token creation, validation, and extraction. It
|
||||
* utilizes the {@code com.auth0:java-jwt} {@link
|
||||
* com.auth0.jwt.algorithms.Algorithm} class to define and use different
|
||||
* algorithms for JWT signing and verification.
|
||||
* <p>
|
||||
* To use the {@code AuthzeroTokenResolver}, developers must provide the
|
||||
* necessary configurations and dependencies, such as the {@code GuidCreator}
|
||||
* for generating unique JWT IDs (JTI), the supported algorithm function, the
|
||||
* issuer name, and the secret key used for token signing and validation. The
|
||||
* {@code AuthzeroTokenResolverConfig} class provides a convenient way to
|
||||
* configure these dependencies.
|
||||
* To use the {@link
|
||||
* cn.org.codecrafters.simplejwt.authzero.AuthzeroTokenResolver}, developers
|
||||
* must provide the necessary configurations and dependencies, such as the
|
||||
* {@link cn.org.codecrafters.guid.GuidCreator} for generating unique JWT IDs
|
||||
* (JTI), the supported algorithm function, the issuer name, and the secret key
|
||||
* used for token signing and validation. The {@link
|
||||
* cn.org.codecrafters.simplejwt.authzero.config.AuthzeroTokenResolverConfig}
|
||||
* class provides a convenient way to configure these dependencies.
|
||||
* <p>
|
||||
* Developers using the {@code com.auth0:java-jwt} integration should be
|
||||
* familiar with the concepts and usage of the {@code com.auth0:java-jwt}
|
||||
|
||||
Reference in New Issue
Block a user