feat: added predefined constants

This commit is contained in:
zihluwang
2025-04-02 20:55:46 +08:00
parent b1dbc1c0e9
commit 6814718f23
2 changed files with 126 additions and 0 deletions
@@ -0,0 +1,48 @@
/*
* 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.constant;
public final class HeaderClaims {
/**
* Private constructor to prevent instantiation of this utility class.
*/
private HeaderClaims() {
}
/**
* The algorithm used to sign a JWT.
*/
public static final String ALGORITHM = "alg";
/**
* The content type of the JWT.
*/
public static final String CONTENT_TYPE = "cty";
/**
* The media type of the JWT.
*/
public static final String TYPE = "typ";
/**
* The key ID of a JWT used to specify the key for signature validation.
*/
public static final String KEY_ID = "kid";
}
@@ -0,0 +1,78 @@
/*
* 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.constant;
import java.util.List;
/**
*
*/
public final class RegisteredClaims {
/**
* Private constructor to prevent instantiation of this utility class.
*/
private RegisteredClaims() {
}
/**
* The "iss" (issuer) claim identifies the principal that issued the JWT.
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.1">Section 4.1.1</a>
*/
public static final String ISSUER = "iss";
/**
* The "sub" (subject) claim identifies the principal that is the subject of the JWT.
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2">Section 4.1.2</a>
*/
public static final String SUBJECT = "sub";
/**
* The "aud" (audience) claim identifies the recipients that the JWT is intended for.
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3">Section 4.1.3</a>
*/
public static final String AUDIENCE = "aud";
/**
* The "exp" (expiration time) claim identifies the expiration time on or after which the JWT MUST NOT be
* accepted for processing.
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4">Section 4.1.4</a>
*/
public static final String EXPIRES_AT = "exp";
/**
* The "nbf" (not before) claim identifies the time before which the JWT MUST NOT be accepted for processing.
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5">Section 4.1.5</a>
*/
public static final String NOT_BEFORE = "nbf";
/**
* The "iat" (issued at) claim identifies the time at which the JWT was issued.
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.6">Section 4.1.6</a>
*/
public static final String ISSUED_AT = "iat";
/**
* The "jti" (JWT ID) claim provides a unique identifier for the JWT.
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7">Section 4.1.7</a>
*/
public static final String TOKEN_ID = "jti";
public static final List<String> VALUES = List.of(ISSUER, SUBJECT, AUDIENCE, EXPIRES_AT, NOT_BEFORE, ISSUED_AT, TOKEN_ID);
}