feat: added ECDSA-based algorithm support
make the simple-jwt auth0 implementation can use ECDSA-based algorithms BREAKING CHANGE: the io.jsonwebtoken:jjwt implementation was discontinued since its design made a big challenge to encapsulation
This commit is contained in:
-65
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2024 OnixByte.
|
||||
*
|
||||
* 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 com.onixbyte.simplejwt.config;
|
||||
|
||||
import com.onixbyte.simplejwt.TokenResolver;
|
||||
import com.onixbyte.simplejwt.constants.TokenAlgorithm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The {@code TokenResolverConfig} provides a mechanism to configure an
|
||||
* implementation of {@link TokenResolver} with algorithm functions.
|
||||
* <p>
|
||||
* This generic interface is used to define the configuration details for a
|
||||
* {@link TokenResolver} that utilizes algorithm functions. The interface
|
||||
* allows for specifying algorithm functions corresponding to different {@link
|
||||
* TokenAlgorithm} instances supported by the {@link TokenResolver}
|
||||
* implementation.
|
||||
*
|
||||
* @param <Algo> the type representing algorithm functions used by the
|
||||
* {@link TokenResolver}
|
||||
* @author Zihlu Wang
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public interface TokenResolverConfig<Algo> {
|
||||
|
||||
/**
|
||||
* Gets the algorithm function corresponding to the specified {@link
|
||||
* TokenAlgorithm}.
|
||||
* <p>
|
||||
* This method returns the algorithm function associated with the given
|
||||
* {@link TokenAlgorithm}. The provided TokenAlgorithm represents the
|
||||
* specific algorithm for which the corresponding algorithm function is
|
||||
* required. The returned {@code Algo} represents the function
|
||||
* implementation that can be used by the {@link TokenResolver} to handle
|
||||
* the specific algorithm.
|
||||
*
|
||||
* @param algorithm the {@link TokenAlgorithm} for which the algorithm function is required
|
||||
* @return the algorithm function associated with the given {@link TokenAlgorithm}
|
||||
*/
|
||||
Algo getAlgorithm(TokenAlgorithm algorithm);
|
||||
|
||||
List<TokenAlgorithm> ECDSA_ALGORITHMS =
|
||||
List.of(TokenAlgorithm.ES256, TokenAlgorithm.ES384, TokenAlgorithm.ES512);
|
||||
|
||||
List<TokenAlgorithm> HMAC_ALGORITHMS =
|
||||
List.of(TokenAlgorithm.HS256, TokenAlgorithm.HS384, TokenAlgorithm.HS512);
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2024 OnixByte.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The classes in this package provide configuration options and settings for
|
||||
* the {@code cn.org.codecrafters:simple-jwt-facade} library. They are used
|
||||
* to customize the behavior of the library and allow developers to fine-tune
|
||||
* various aspects of JWT generation and validation.
|
||||
* <p>
|
||||
* Other configuration classes may be added in the future to support additional
|
||||
* customisation options and features. Developers using the
|
||||
* {@code cn.org.codecrafters:simple-jwt-facade} library should be familiar
|
||||
* with the available configuration options to ensure proper integration and
|
||||
* usage of the library.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
package com.onixbyte.simplejwt.config;
|
||||
@@ -19,6 +19,8 @@ package com.onixbyte.simplejwt.constants;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The {@code TokenAlgorithm} enum class defines the algorithms that can be
|
||||
* used for signing and verifying JSON Web Tokens (JWT). JWT allows various
|
||||
@@ -92,4 +94,18 @@ public enum TokenAlgorithm {
|
||||
ES512,
|
||||
;
|
||||
|
||||
/**
|
||||
* HMAC-based algorithms.
|
||||
*/
|
||||
public static final List<TokenAlgorithm> HMAC_ALGORITHMS = List.of(
|
||||
TokenAlgorithm.HS256, TokenAlgorithm.HS384, TokenAlgorithm.HS512
|
||||
);
|
||||
|
||||
/**
|
||||
* ECDSA-based algorithms.
|
||||
*/
|
||||
public static final List<TokenAlgorithm> ECDSA_ALGORITHMS = List.of(
|
||||
TokenAlgorithm.ES256, TokenAlgorithm.ES384, TokenAlgorithm.ES512
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2024 OnixByte.
|
||||
*
|
||||
* 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 com.onixbyte.simplejwt.exceptions;
|
||||
|
||||
/**
|
||||
* {@link IllegalKeyPairException} indicates an exception that the key pair is invalid.
|
||||
*
|
||||
* @author zihluwang
|
||||
* @version 1.6.0
|
||||
*/
|
||||
public class IllegalKeyPairException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Create a default exception instance.
|
||||
*/
|
||||
public IllegalKeyPairException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an exception instance with specific message.
|
||||
*
|
||||
* @param message the message of the exception
|
||||
*/
|
||||
public IllegalKeyPairException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an exception instance with specific message and cause.
|
||||
*
|
||||
* @param message the message of the exception
|
||||
* @param cause the cause of the exception
|
||||
*/
|
||||
public IllegalKeyPairException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2024 OnixByte.
|
||||
*
|
||||
* 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 com.onixbyte.simplejwt.exceptions;
|
||||
|
||||
/**
|
||||
* {@link IllegalKeyPairException} indicates the secret to sign a JWT is illegal.
|
||||
*
|
||||
* @author zihluwang
|
||||
* @version 1.6.0
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class IllegalSecretException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Create a default exception instance.
|
||||
*/
|
||||
public IllegalSecretException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an exception instance with specific message.
|
||||
*
|
||||
* @param message the message of the exception
|
||||
*/
|
||||
public IllegalSecretException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an exception instance with specific message and the cause of this exception.
|
||||
*
|
||||
* @param message the message of the exception
|
||||
* @param cause the cause of the exception
|
||||
*/
|
||||
public IllegalSecretException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user