style(simple-jwt): Upgraded method to get Algorithm declared in third-party implementation.
This commit is contained in:
+1
-1
@@ -140,7 +140,7 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
|||||||
throw new IllegalArgumentException("A secret is required to build a JSON Web Token.");
|
throw new IllegalArgumentException("A secret is required to build a JSON Web Token.");
|
||||||
}
|
}
|
||||||
this.jtiCreator = jtiCreator;
|
this.jtiCreator = jtiCreator;
|
||||||
this.algorithm = AuthzeroTokenResolverConfig.getInstance().getFunction(algorithm).apply(secret);
|
this.algorithm = AuthzeroTokenResolverConfig.getInstance().getAlgorithm(algorithm).apply(secret);
|
||||||
this.issuer = issuer;
|
this.issuer = issuer;
|
||||||
this.verifier = JWT.require(this.algorithm).build();
|
this.verifier = JWT.require(this.algorithm).build();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -140,7 +140,7 @@ public final class AuthzeroTokenResolverConfig implements TokenResolverConfig<Fu
|
|||||||
* implementation
|
* implementation
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Function<String, Algorithm> getFunction(TokenAlgorithm algorithm) {
|
public Function<String, Algorithm> getAlgorithm(TokenAlgorithm algorithm) {
|
||||||
return Optional.of(SUPPORTED_ALGORITHMS).map((entry) -> entry.get(algorithm))
|
return Optional.of(SUPPORTED_ALGORITHMS).map((entry) -> entry.get(algorithm))
|
||||||
.orElseThrow(() -> new UnsupportedAlgorithmException("The specified algorithm is not supported yet."));
|
.orElseThrow(() -> new UnsupportedAlgorithmException("The specified algorithm is not supported yet."));
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-6
@@ -23,21 +23,20 @@ import cn.org.codecrafters.simplejwt.constants.TokenAlgorithm;
|
|||||||
* <p>
|
* <p>
|
||||||
* The TokenResolverConfig interface provides a mechanism to configure a
|
* The TokenResolverConfig interface provides a mechanism to configure a
|
||||||
* TokenResolver with algorithm functions.
|
* TokenResolver with algorithm functions.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* This generic interface is used to define the configuration details for a
|
* This generic interface is used to define the configuration details for a
|
||||||
* TokenResolver that utilizes algorithm functions. The interface allows for
|
* TokenResolver that utilizes algorithm functions. The interface allows for
|
||||||
* specifying algorithm functions corresponding to different TokenAlgorithm
|
* specifying algorithm functions corresponding to different TokenAlgorithm
|
||||||
* instances supported by the TokenResolver implementation.
|
* instances supported by the TokenResolver implementation.
|
||||||
*
|
|
||||||
*
|
*
|
||||||
* @param <AlgorithmFunction> the type representing algorithm functions used by
|
* @param <Algo> the type representing algorithm functions used by the
|
||||||
* the TokenResolver
|
* {@code TokenResolver}
|
||||||
* @author Zihlu Wang
|
* @author Zihlu Wang
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public interface TokenResolverConfig<AlgorithmFunction> {
|
public interface TokenResolverConfig<Algo> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the algorithm function corresponding to the specified
|
* Gets the algorithm function corresponding to the specified
|
||||||
@@ -53,6 +52,6 @@ public interface TokenResolverConfig<AlgorithmFunction> {
|
|||||||
* required
|
* required
|
||||||
* @return the algorithm function associated with the given TokenAlgorithm
|
* @return the algorithm function associated with the given TokenAlgorithm
|
||||||
*/
|
*/
|
||||||
AlgorithmFunction getFunction(TokenAlgorithm algorithm);
|
Algo getAlgorithm(TokenAlgorithm algorithm);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user