refactor: change to MIT license and reformat codes
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
# Module `simple-jwt-facade`
|
||||
# JWT Toolbox :: Facade
|
||||
|
||||
## Introduction
|
||||
|
||||
The `simple-jwt-facade` module is a lightweight and easy-to-use façade for working with JSON Web Tokens (JWT) in Java applications. It provides a simplified interface and utilities to handle the creation, validation, renewal, and processing of JWTs without the need for complex configurations or third-party dependencies.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
This whole `JDevKit` is developed by **JDK 17**, which means you have to use JDK 17 for better experience.
|
||||
The JWT Toolbox Facade module is a lightweight and easy-to-use façade for working with JSON Web
|
||||
Tokens (JWT) in Java applications. It provides a simplified interface and utilities to handle the
|
||||
creation, validation, renewal, and processing of JWTs without the need for complex configurations or
|
||||
third-party dependencies.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -16,27 +15,36 @@ It is quite simple to install this module by `Maven`. The only thing you need to
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>cn.org.codecrafters</groupId>
|
||||
<artifactId>simple-jwt-facade</artifactId>
|
||||
<version>${simple-jwt-facade.version}</version>
|
||||
<groupId>com.onixbyte</groupId>
|
||||
<artifactId>jwt-toolkit-facade</artifactId>
|
||||
<version>${jwt-toolkit-facade.version}</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
And run `mvn dependency:get` in your project root folder(i.e., if your `pom.xml` is located at `/path/to/your/project/pom.xml`, then your current work folder should be `/path/to/your/project`), then `Maven` will automatically download the `jar` archive from `Maven Central Repository`. This could be **MUCH EASIER** if you are using IDE(i.e., IntelliJ IDEA), the only thing you need to do is click the refresh button of `Maven`.
|
||||
And run `mvn dependency:get` in your project root folder(i.e., if your `pom.xml` is located at
|
||||
`/path/to/your/project/pom.xml`, then your current work folder should be `/path/to/your/project`),
|
||||
then `Maven` will automatically download the `jar` archive from `Maven Central Repository`.
|
||||
|
||||
If you are restricted using the Internet, and have to make `Maven` offline, you could follow the following steps.
|
||||
This could be **MUCH EASIER** if you are using IDE(i.e., IntelliJ IDEA), the only thing you need to
|
||||
do is click the refresh button of `Maven`.
|
||||
|
||||
1. Download the `jar` file from any place you can get and transfer the `jar` files to your work computer.
|
||||
2. Move the `jar` files to your local `Maven` Repository as the path of `/path/to/maven_local_repo/cn/org/codecrafters/simple-jwt-facade/`.
|
||||
If you are restricted using the Internet, and have to make `Maven` offline, you could follow the
|
||||
following steps.
|
||||
|
||||
1. Download the `jar` file from any place you can get and transfer the `jar` files to your
|
||||
work computer.
|
||||
2. Move the `jar` files to your local `Maven` Repository as the path of
|
||||
`/path/to/maven_local_repo/com/onixbyte/jwt-toolbox-facade/`.
|
||||
|
||||
### If you are using `Gradle`
|
||||
|
||||
Add this module to your project with `Gradle` is much easier than doing so with `Maven`.
|
||||
|
||||
Find `build.gradle` in the needed project, and add the following code to the `dependencies` closure in the build script:
|
||||
Find `build.gradle` in the needed project, and add the following code to the `dependencies` closure
|
||||
in the build script:
|
||||
|
||||
```groovy
|
||||
implementation 'cn.org.codecrafters:simple-jwt-facade:${simple-jwt-facade.version}'
|
||||
implementation 'com.onixbyte:jwt-toolbox-facade:${jwt-toolbox-facade.version}'
|
||||
```
|
||||
|
||||
### If you are not using `Maven` or `Gradle`
|
||||
@@ -67,7 +75,7 @@ After doing all these, an implemented `TokenResolver` is ready to process JWTs.
|
||||
You will need an instance of the implementation to process JWTs.
|
||||
|
||||
```java
|
||||
var tokenResolver = new ImplementedTokenResolver(/* arguments you declared */)
|
||||
var tokenResolver = new ImplementedTokenResolver(/* arguments you declared */);
|
||||
```
|
||||
|
||||
## Create a JSON Web Token with `TokenResolver`
|
||||
@@ -124,4 +132,4 @@ This method allows you to pass new custom payload into the updated token. The ne
|
||||
|
||||
If you have any suggestions, ideas, don't hesitate contacting us via [GitHub Issues](https://github.com/CodeCraftersCN/jdevkit/issues/new) or [Discord Community](https://discord.gg/NQK9tjcBB8).
|
||||
|
||||
If you face any bugs while using our library and you are able to fix any bugs in our library, we would be happy to accept pull requests from you on [GitHub](https://github.com/CodeCraftersCN/jdevkit/compare).
|
||||
If you face any bugs while using our library and you are able to fix any bugs in our library, we would be happy to accept pull requests from you on [GitHub](https://github.com/CodeCraftersCN/jdevkit/compare).
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 OnixByte.
|
||||
* Copyright (c) 2024-2025 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
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import java.net.URI
|
||||
|
||||
plugins {
|
||||
@@ -86,8 +92,8 @@ publishing {
|
||||
}
|
||||
|
||||
scm {
|
||||
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
|
||||
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
|
||||
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
|
||||
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
|
||||
url = projectGithubUrl
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 OnixByte.
|
||||
* Copyright (c) 2024-2025 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
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.onixbyte.jwt;
|
||||
@@ -24,18 +29,16 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* {@code SecretCreator} is a utility class that provides methods to generate
|
||||
* secure secret strings. The generated secrets can be used as cryptographic
|
||||
* keys or passwords for various security-sensitive purposes.
|
||||
* {@code SecretCreator} is a utility class that provides methods to generate secure secret strings.
|
||||
* The generated secrets can be used as cryptographic keys or passwords for various
|
||||
* security-sensitive purposes.
|
||||
*
|
||||
* @author Zihlu Wang
|
||||
* @version 1.1.0
|
||||
* @author zihluwang
|
||||
* @version 3.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public final class SecretCreator {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(SecretCreator.class);
|
||||
|
||||
/**
|
||||
* Generates a secure secret with the specified length and character sets.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2025 OnixByte
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.onixbyte.jwt;
|
||||
|
||||
public interface TokenGenerator {
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2025 OnixByte
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.onixbyte.jwt;
|
||||
|
||||
public interface TokenParser {
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 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.jwt;
|
||||
|
||||
/**
|
||||
* {@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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* <b>Usage:</b>
|
||||
* To use a class as a JWT payload, simply implement the {@code TokenPayload}
|
||||
* interface in the data class:
|
||||
* <pre>
|
||||
* public class UserData implements TokenPayload {
|
||||
* // Class implementation with payload data...
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author Zihlu Wang
|
||||
* @version 1.1.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public interface TokenPayload {
|
||||
}
|
||||
@@ -1,184 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 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.jwt;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@code TokenResolver} 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 configurations, extract
|
||||
* payload from tokens, and renew expired tokens.
|
||||
* <p>
|
||||
* <b>Token Creation:</b>
|
||||
* 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.
|
||||
* <p>
|
||||
* <b>Token Extraction:</b>
|
||||
* 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.
|
||||
* <p>
|
||||
* <b>Token Renewal:</b>
|
||||
* 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 <ResolvedTokenType> the type of the result obtained by the
|
||||
* third-party library when parsing JWTs
|
||||
* @author Zihlu Wang
|
||||
* @version 1.1.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public interface TokenResolver<ResolvedTokenType> {
|
||||
|
||||
/**
|
||||
* Creates a new token with the specified expiration time, subject, and
|
||||
* audience.
|
||||
*
|
||||
* @param expireAfter the duration after which the token will expire
|
||||
* @param subject the subject of the token
|
||||
* @param audience the audience for which the token is intended
|
||||
* @return the generated token as a {@code String}
|
||||
*/
|
||||
String createToken(Duration expireAfter, String audience, String subject);
|
||||
|
||||
/**
|
||||
* Creates a new token with the specified expiration time, subject,
|
||||
* audience, and custom payload data.
|
||||
*
|
||||
* @param expireAfter the duration after which the token will expire
|
||||
* @param subject the subject of the token
|
||||
* @param audience the audience for which the token is intended
|
||||
* @param payload the custom payload data to be included in the token
|
||||
* @return the generated token as a {@code String}
|
||||
*/
|
||||
String createToken(Duration expireAfter, String audience, String subject, Map<String, Object> payload);
|
||||
|
||||
/**
|
||||
* Creates a new token with the specified expiration time, subject,
|
||||
* audience, and strongly-typed payload data.
|
||||
*
|
||||
* @param <T> the type of the payload data, must implement
|
||||
* {@link TokenPayload}
|
||||
* @param expireAfter the duration after which the token will expire
|
||||
* @param subject the subject of the token
|
||||
* @param audience the audience for which the token is intended
|
||||
* @param payload the strongly-typed payload data to be included in the
|
||||
* token
|
||||
* @return the generated token as a {@code String}
|
||||
*/
|
||||
<T extends TokenPayload> String createToken(Duration expireAfter, String audience, String subject, T payload);
|
||||
|
||||
/**
|
||||
* Resolves the given token into a ResolvedTokenType object.
|
||||
*
|
||||
* @param token the token to be resolved
|
||||
* @return a ResolvedTokenType object
|
||||
*/
|
||||
ResolvedTokenType resolve(String token);
|
||||
|
||||
/**
|
||||
* Extracts the payload information from the given token and maps it to the
|
||||
* specified target type.
|
||||
*
|
||||
* @param <T> the target type to which the payload data will be
|
||||
* mapped
|
||||
* @param token the token from which to extract the payload
|
||||
* @param targetType the target class representing the payload data type
|
||||
* @return an instance of the specified target type with the extracted
|
||||
* payload data
|
||||
*/
|
||||
<T extends TokenPayload> T extract(String token, Class<T> targetType);
|
||||
|
||||
/**
|
||||
* Re-generate a new token with the payload in the old one.
|
||||
*
|
||||
* @param oldToken the old token
|
||||
* @param expireAfter how long the new token can be valid for
|
||||
* @return re-generated token with the payload in the old one
|
||||
*/
|
||||
String renew(String oldToken, Duration expireAfter);
|
||||
|
||||
/**
|
||||
* Re-generate a new token with the payload in the old one.
|
||||
*
|
||||
* @param oldToken the old token
|
||||
* @return re-generated token with the payload in the old one
|
||||
* @see #renew(String, Duration)
|
||||
*/
|
||||
default String renew(String oldToken) {
|
||||
return renew(oldToken, Duration.ofMinutes(30));
|
||||
}
|
||||
|
||||
/**
|
||||
* Renews the given expired token with the specified custom payload data.
|
||||
*
|
||||
* @param oldToken the expired token to be renewed
|
||||
* @param expireAfter specify when does the new token invalid
|
||||
* @param payload the custom payload data to be included in the renewed
|
||||
* token
|
||||
* @return the renewed token as a {@code String}
|
||||
*/
|
||||
String renew(String oldToken, Duration expireAfter, Map<String, Object> payload);
|
||||
|
||||
/**
|
||||
* Renews the given expired token with the specified custom payload data.
|
||||
*
|
||||
* @param oldToken the expired 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}
|
||||
*/
|
||||
default String renew(String oldToken, Map<String, Object> payload) {
|
||||
return renew(oldToken, Duration.ofMinutes(30), payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renews the given expired token with the specified strongly-typed
|
||||
* payload data.
|
||||
*
|
||||
* @param <T> the type of the payload data, must implement
|
||||
* {@link TokenPayload}
|
||||
* @param oldToken the expired token to be renewed
|
||||
* @param expireAfter specify when does the new token invalid
|
||||
* @param payload the strongly-typed payload data to be included in the
|
||||
* renewed token
|
||||
* @return the renewed token as a {@code String}
|
||||
*/
|
||||
<T extends TokenPayload> String renew(String oldToken, Duration expireAfter, T payload);
|
||||
|
||||
/**
|
||||
* Renews the given expired token with the specified strongly-typed
|
||||
* payload data.
|
||||
*
|
||||
* @param <T> the type of the payload data, must implement
|
||||
* {@link TokenPayload}
|
||||
* @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}
|
||||
*/
|
||||
default <T extends TokenPayload> String renew(String oldToken, T payload) {
|
||||
return renew(oldToken, Duration.ofMinutes(30), payload);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 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.jwt.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation {@code ExcludeFromPayload} 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 by this annotation, it will not be included in the JWT payloads.
|
||||
* <p>
|
||||
* <b>Usage:</b>
|
||||
* To exclude a property from the JWT payload, annotate the property with
|
||||
* {@code @ExcludeFromPayload}:
|
||||
*
|
||||
* <pre>{@code
|
||||
* public class UserData implements TokenPayload {
|
||||
* private String username;
|
||||
*
|
||||
* // This property will not be included in the JWT payload
|
||||
* @ExcludeFromPayload
|
||||
* private String sensitiveData;
|
||||
*
|
||||
* // Getters and setters...
|
||||
* }
|
||||
* }</pre>
|
||||
* <p>
|
||||
* <b>Note:</b>
|
||||
* This annotation should be used on properties that are not intended to
|
||||
* be included in the JWT payload due to their sensitive nature or for other
|
||||
* reasons only. It is important to carefully choose which properties are
|
||||
* excluded from the payload to ensure the JWT remains secure and efficient.
|
||||
*
|
||||
* @author Zihlu Wang
|
||||
* @version 1.1.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD})
|
||||
public @interface ExcludeFromPayload {
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 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.jwt.annotations;
|
||||
|
||||
import com.onixbyte.jwt.constants.TokenDataType;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation marks the enum field declared in payload class will be handled as basic data
|
||||
* types in {@link TokenDataType}.
|
||||
*
|
||||
* @author Zihlu Wang
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD})
|
||||
public @interface TokenEnum {
|
||||
|
||||
/**
|
||||
* The name of the field of the base data corresponding to the enumeration data.
|
||||
*
|
||||
* @return the name of the property
|
||||
*/
|
||||
String propertyName();
|
||||
|
||||
/**
|
||||
* The attribute {@code dataType} specifies what base data type to treat this enum as.
|
||||
*
|
||||
* @return the data type of the token
|
||||
*/
|
||||
TokenDataType dataType();
|
||||
|
||||
}
|
||||
@@ -1,18 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 OnixByte.
|
||||
* Copyright (c) 2024-2025 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
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.onixbyte.jwt.constants;
|
||||
@@ -26,13 +31,13 @@ import java.util.List;
|
||||
* <p>
|
||||
* The class provides the following standard JWT claim constants:
|
||||
* <ul>
|
||||
* <li>{@link #ISSUER}: Represents the "iss" (Issuer) claim.</li>
|
||||
* <li>{@link #SUBJECT}: Represents the "sub" (Subject) claim.</li>
|
||||
* <li>{@link #AUDIENCE}: Represents the "aud" (Audience) claim.</li>
|
||||
* <li>{@link #EXPIRATION_TIME}: Represents the "exp" (Expiration Time) claim.</li>
|
||||
* <li>{@link #NOT_BEFORE}: Represents the "nbf" (Not Before) claim.</li>
|
||||
* <li>{@link #ISSUED_AT}: Represents the "iat" (Issued At) claim.</li>
|
||||
* <li>{@link #JWT_ID}: Represents the "jti" (JWT ID) claim.</li>
|
||||
* <li>{@link #ISSUER}: Represents the "iss" (Issuer) claim.</li>
|
||||
* <li>{@link #SUBJECT}: Represents the "sub" (Subject) claim.</li>
|
||||
* <li>{@link #AUDIENCE}: Represents the "aud" (Audience) claim.</li>
|
||||
* <li>{@link #EXPIRATION_TIME}: Represents the "exp" (Expiration Time) claim.</li>
|
||||
* <li>{@link #NOT_BEFORE}: Represents the "nbf" (Not Before) claim.</li>
|
||||
* <li>{@link #ISSUED_AT}: Represents the "iat" (Issued At) claim.</li>
|
||||
* <li>{@link #JWT_ID}: Represents the "jti" (JWT ID) claim.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* The class also contains a list of all the standard claim constants, accessible via the {@link
|
||||
@@ -43,7 +48,7 @@ import java.util.List;
|
||||
* the standard JWT claim constants.
|
||||
*
|
||||
* @author zihluwang
|
||||
* @version 1.1.0
|
||||
* @version 3.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public final class PredefinedKeys {
|
||||
@@ -86,8 +91,15 @@ public final class PredefinedKeys {
|
||||
/**
|
||||
* List containing all the standard JWT claim constants.
|
||||
*/
|
||||
public static final List<String> KEYS =
|
||||
List.of(ISSUER, SUBJECT, AUDIENCE, EXPIRATION_TIME, NOT_BEFORE, ISSUED_AT, JWT_ID);
|
||||
public static final List<String> KEYS = List.of(
|
||||
ISSUER,
|
||||
SUBJECT,
|
||||
AUDIENCE,
|
||||
EXPIRATION_TIME,
|
||||
NOT_BEFORE,
|
||||
ISSUED_AT,
|
||||
JWT_ID
|
||||
);
|
||||
|
||||
/**
|
||||
* Private constructor to prevent instantiation of this utility class.
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 OnixByte.
|
||||
* Copyright (c) 2024-2025 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
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.onixbyte.jwt.constants;
|
||||
|
||||
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
|
||||
@@ -28,19 +31,19 @@ import java.util.List;
|
||||
* <p>
|
||||
* <b>Supported Algorithms:</b>
|
||||
* <ul>
|
||||
* <li>{@link TokenAlgorithm#HS256}: HMAC SHA-256</li>
|
||||
* <li>{@link TokenAlgorithm#HS384}: HMAC SHA-384</li>
|
||||
* <li>{@link TokenAlgorithm#HS512}: HMAC SHA-512</li>
|
||||
* <li>{@link TokenAlgorithm#RS256}: RSA PKCS#1 v1.5 with SHA-256</li>
|
||||
* <li>{@link TokenAlgorithm#RS384}: RSA PKCS#1 v1.5 with SHA-384</li>
|
||||
* <li>{@link TokenAlgorithm#RS512}: RSA PKCS#1 v1.5 with SHA-512</li>
|
||||
* <li>{@link TokenAlgorithm#ES256}: ECDSA with SHA-256</li>
|
||||
* <li>{@link TokenAlgorithm#ES384}: ECDSA with SHA-384</li>
|
||||
* <li>{@link TokenAlgorithm#ES512}: ECDSA with SHA-512</li>
|
||||
* <li>{@link TokenAlgorithm#HS256}: HMAC SHA-256</li>
|
||||
* <li>{@link TokenAlgorithm#HS384}: HMAC SHA-384</li>
|
||||
* <li>{@link TokenAlgorithm#HS512}: HMAC SHA-512</li>
|
||||
* <li>{@link TokenAlgorithm#RS256}: RSA PKCS#1 v1.5 with SHA-256</li>
|
||||
* <li>{@link TokenAlgorithm#RS384}: RSA PKCS#1 v1.5 with SHA-384</li>
|
||||
* <li>{@link TokenAlgorithm#RS512}: RSA PKCS#1 v1.5 with SHA-512</li>
|
||||
* <li>{@link TokenAlgorithm#ES256}: ECDSA with SHA-256</li>
|
||||
* <li>{@link TokenAlgorithm#ES384}: ECDSA with SHA-384</li>
|
||||
* <li>{@link TokenAlgorithm#ES512}: ECDSA with SHA-512</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Zihlu Wang
|
||||
* @version 1.1.0
|
||||
* @author zihluwang
|
||||
* @version 3.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public enum TokenAlgorithm {
|
||||
@@ -91,18 +94,4 @@ 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
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 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.jwt.constants;
|
||||
|
||||
/**
|
||||
* The base data types used to process enum data.
|
||||
*
|
||||
* @author Zihlu Wang
|
||||
*/
|
||||
public enum TokenDataType {
|
||||
|
||||
/**
|
||||
* Marks enumeration being processed as Boolean.
|
||||
*/
|
||||
BOOLEAN(Boolean.class),
|
||||
|
||||
/**
|
||||
* Marks enumeration being processed as Double.
|
||||
*/
|
||||
DOUBLE(Long.class),
|
||||
|
||||
/**
|
||||
* Marks enumeration being processed as Float.
|
||||
*/
|
||||
FLOAT(Float.class),
|
||||
|
||||
/**
|
||||
* Marks enumeration being processed as Integer.
|
||||
*/
|
||||
INTEGER(Integer.class),
|
||||
|
||||
/**
|
||||
* Marks enumeration being processed as Long.
|
||||
*/
|
||||
LONG(Long.class),
|
||||
|
||||
/**
|
||||
* Marks enumeration being processed as String.
|
||||
*/
|
||||
STRING(String.class),
|
||||
;
|
||||
|
||||
/**
|
||||
* The mapped class to this mark.
|
||||
*/
|
||||
private final Class<?> mappedClass;
|
||||
|
||||
/**
|
||||
* Create a TokenDataType with a mapped class.
|
||||
*/
|
||||
TokenDataType(Class<?> mappedClass) {
|
||||
this.mappedClass = mappedClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the target mapped class.
|
||||
*
|
||||
* @return mapped class
|
||||
*/
|
||||
public Class<?> getMappedClass() {
|
||||
return mappedClass;
|
||||
}
|
||||
}
|
||||
+17
-12
@@ -1,18 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 OnixByte.
|
||||
* Copyright (c) 2024-2025 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
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.onixbyte.jwt.exceptions;
|
||||
@@ -21,7 +26,7 @@ package com.onixbyte.jwt.exceptions;
|
||||
* {@link IllegalKeyPairException} indicates an exception that the key pair is invalid.
|
||||
*
|
||||
* @author zihluwang
|
||||
* @version 1.6.0
|
||||
* @version 3.0.0
|
||||
*/
|
||||
public class IllegalKeyPairException extends RuntimeException {
|
||||
|
||||
|
||||
+17
-12
@@ -1,24 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 OnixByte.
|
||||
* Copyright (c) 2024-2025 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
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.onixbyte.jwt.exceptions;
|
||||
|
||||
/**
|
||||
* {@link IllegalKeyPairException} indicates the secret to sign a JWT is illegal.
|
||||
* {@code IllegalKeyPairException} indicates the secret to sign a JWT is illegal.
|
||||
*
|
||||
* @author zihluwang
|
||||
* @version 1.6.0
|
||||
|
||||
+47
-50
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 OnixByte.
|
||||
* Copyright (c) 2024-2025 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
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.onixbyte.jwt.exceptions;
|
||||
|
||||
import com.onixbyte.jwt.TokenResolver;
|
||||
|
||||
/**
|
||||
* This {@code UnsupportedAlgorithmException} represents the given
|
||||
* algorithm is not supported by {@link
|
||||
* TokenResolver} yet.
|
||||
* <p>
|
||||
* If you want the supports to an unsupported algorithm, you could
|
||||
* <ul>
|
||||
@@ -30,42 +30,39 @@ import com.onixbyte.jwt.TokenResolver;
|
||||
* <li>Communicate with us on Discord Community.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Zihlu Wang
|
||||
* @version 1.1.0
|
||||
* @since 1.0.0
|
||||
* @author zihluwang
|
||||
* @version 3.0.0
|
||||
*/
|
||||
public class UnsupportedAlgorithmException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructs a new {@code UnsupportedAlgorithmException} with {@code null}
|
||||
* as its detail message. The cause is not initialized, and may
|
||||
* subsequently be initialized by a call to {@link #initCause}.
|
||||
* Constructs a new {@code UnsupportedAlgorithmException} 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 {@code UnsupportedAlgorithmException} with the
|
||||
* specified detail message. The cause is not initialized, and may
|
||||
* subsequently be initialized by a call to {@link #initCause}.
|
||||
* Constructs a new {@code UnsupportedAlgorithmException} 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.
|
||||
* @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 {@code UnsupportedAlgorithmException} with the
|
||||
* specified detail message and cause.
|
||||
* Constructs a new {@code UnsupportedAlgorithmException} with the specified detail message
|
||||
* and cause.
|
||||
*
|
||||
* @param message the detail message (which is saved for later retrieval
|
||||
* by the {@link #getMessage()} method).
|
||||
* @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.)
|
||||
* {@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) {
|
||||
@@ -73,17 +70,14 @@ public class UnsupportedAlgorithmException extends RuntimeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code UnsupportedAlgorithmException} 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 throwable.
|
||||
* Constructs a new {@code UnsupportedAlgorithmException} 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 throwable.
|
||||
*
|
||||
* @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.)
|
||||
* {@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) {
|
||||
@@ -91,19 +85,22 @@ public class UnsupportedAlgorithmException extends RuntimeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code UnsupportedAlgorithmException} with the
|
||||
* specified detail message, cause, suppression enabled or disabled, and
|
||||
* writable stack trace enabled or disabled.
|
||||
* Constructs a new {@code UnsupportedAlgorithmException} 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 cause the cause (A {@code null} value is permitted, and indicates that
|
||||
* the cause is nonexistent or unknown.)
|
||||
* @param enableSuppression whether suppression is enabled or disabled
|
||||
* @param writableStackTrace whether the stack trace should be writable
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public UnsupportedAlgorithmException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
public UnsupportedAlgorithmException(
|
||||
String message,
|
||||
Throwable cause,
|
||||
boolean enableSuppression,
|
||||
boolean writableStackTrace
|
||||
) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
+51
-50
@@ -1,69 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 OnixByte.
|
||||
* Copyright (c) 2024-2025 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
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.onixbyte.jwt.exceptions;
|
||||
|
||||
/**
|
||||
* {@code WeakSecretException} represents that your secret is too weak to be
|
||||
* used in signing JWTs.
|
||||
* {@code WeakSecretException} represents that your secret is too weak to be used in signing JWTs.
|
||||
* <p>
|
||||
* {@code WeakSecretException} will only appears that if you are using the
|
||||
* implementation module {@code cn.org.codecrafters:simple-jwt-jjwt} due to
|
||||
* it is implemented by {@code io.jsonwebtoken:jjwt}.
|
||||
* {@code WeakSecretException} will only appears that if you are using the implementation module
|
||||
* {@code com.onixbyte:jwt-toolbox-auth0} due to it is implemented by {@code com.auth0:java-jwt}.
|
||||
*
|
||||
* @author Zihlu Wang
|
||||
* @version 1.1.0
|
||||
* @author zihluwang
|
||||
* @version 3.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class WeakSecretException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructs a new {@code WeakSecretException} with {@code null} as its
|
||||
* detail message. The cause is not initialized, and may subsequently be
|
||||
* initialized by a call to {@link #initCause}.
|
||||
* Constructs a new {@code WeakSecretException} with {@code null} as its detail message.
|
||||
* The cause is not initialized, and may subsequently be initialized by a call
|
||||
* to {@link #initCause}.
|
||||
*/
|
||||
public WeakSecretException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code WeakSecretException} with the specified detail
|
||||
* message. The cause is not initialized, and may subsequently be
|
||||
* initialized by a call to {@link #initCause}.
|
||||
* Constructs a new {@code WeakSecretException} with the specified detail message. The cause is
|
||||
* not initialised, 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.
|
||||
* @param message the detail message. The detail message is saved for later retrieval by the
|
||||
* {@link #getMessage()} method.
|
||||
*/
|
||||
public WeakSecretException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code WeakSecretException} with the specified detail
|
||||
* message and cause.
|
||||
* Constructs a new {@code WeakSecretException} with the specified detail message and cause.
|
||||
* <p>
|
||||
* Note that the detail message associated with {@code cause} is <i>not</i>
|
||||
* automatically incorporated in this runtime exception's detail message.
|
||||
* Note that the detail message associated with {@code cause} is <i>not</i> 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 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.)
|
||||
* {@link #getCause()} method). (A {@code null} value is permitted, and
|
||||
* indicates that the cause is nonexistent or unknown.)
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public WeakSecretException(String message, Throwable cause) {
|
||||
@@ -71,16 +71,14 @@ public class WeakSecretException extends RuntimeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code WeakSecretException} 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 throwable.
|
||||
* Constructs a new {@code WeakSecretException} 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 throwable.
|
||||
*
|
||||
* @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.)
|
||||
* {@link #getCause()} method). (A {@code null} value is permitted, and indicates
|
||||
* that the cause is nonexistent or unknown.)
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public WeakSecretException(Throwable cause) {
|
||||
@@ -88,19 +86,22 @@ public class WeakSecretException extends RuntimeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code WeakSecretException} with the specified detail
|
||||
* message, cause, suppression enabled or disabled, and writable
|
||||
* stack trace enabled or disabled.
|
||||
* Constructs a new {@code WeakSecretException} 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 cause the cause. (A {@code null} value is permitted, and indicates that
|
||||
* the cause is nonexistent or unknown.)
|
||||
* @param enableSuppression whether suppression is enabled or disabled
|
||||
* @param writableStackTrace whether the stack trace should be writable
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public WeakSecretException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
public WeakSecretException(
|
||||
String message,
|
||||
Throwable cause,
|
||||
boolean enableSuppression,
|
||||
boolean writableStackTrace
|
||||
) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2023-2024 OnixByte.
|
||||
~ Copyright (c) 2024-2025 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
|
||||
~ Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
~ of this software and associated documentation files (the "Software"), to deal
|
||||
~ in the Software without restriction, including without limitation the rights
|
||||
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
~ copies of the Software, and to permit persons to whom the Software is
|
||||
~ furnished to do so, subject to the following conditions:
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~ The above copyright notice and this permission notice shall be included in all
|
||||
~ copies or substantial portions of the Software.
|
||||
~
|
||||
~ 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
~ SOFTWARE.
|
||||
-->
|
||||
|
||||
<configuration>
|
||||
<property name="COLOURFUL_OUTPUT" value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
|
||||
<property name="STANDARD_OUTPUT" value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
|
||||
<property name="COLOURFUL_OUTPUT"
|
||||
value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
|
||||
<property name="STANDARD_OUTPUT"
|
||||
value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
|
||||
|
||||
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
|
||||
<statusListener class="ch.qos.logback.core.status.NopStatusListener"/>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${COLOURFUL_OUTPUT}</pattern>
|
||||
@@ -29,4 +36,4 @@
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
||||
Reference in New Issue
Block a user