io.github.nichetoolkit.rest.worker.jwt.JwtWorker Maven / Gradle / Ivy
Show all versions of rest-toolkit-utils Show documentation
package io.github.nichetoolkit.rest.worker.jwt;
import io.fusionauth.jwt.Signer;
import io.fusionauth.jwt.Verifier;
import io.fusionauth.jwt.domain.JWT;
import io.fusionauth.security.CryptoProvider;
import io.github.nichetoolkit.rest.configure.RestJwtProperties;
import io.github.nichetoolkit.rest.util.GeneralUtils;
import io.github.nichetoolkit.rest.util.JsonUtils;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.PostConstruct;
import java.nio.file.Path;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.time.ZonedDateTime;
import java.util.Map;
import java.util.UUID;
/**
* JwtWorker
* The jwt worker class.
* @author Cyan ([email protected])
* @see lombok.Getter
* @see lombok.Setter
* @see lombok.extern.slf4j.Slf4j
* @since Jdk1.8
*/
@Getter
@Setter
@Slf4j
public class JwtWorker {
/**
* jwtBuilder
* {@link io.github.nichetoolkit.rest.worker.jwt.JwtBuilder} The jwtBuilder
field.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtBuilder
*/
private JwtBuilder jwtBuilder;
/**
* signer
* {@link io.fusionauth.jwt.Signer} The signer
field.
* @see io.fusionauth.jwt.Signer
*/
private Signer signer;
/**
* algorithm
* {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm
field.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
*/
private JwtAlgorithm algorithm;
/**
* verifier
* {@link io.fusionauth.jwt.Verifier} The verifier
field.
* @see io.fusionauth.jwt.Verifier
*/
private Verifier verifier;
/**
* INSTANCE
* {@link io.github.nichetoolkit.rest.worker.jwt.JwtWorker} The constant INSTANCE
field.
*/
private static JwtWorker INSTANCE = null;
/**
* getInstance
* The get instance getter method.
* @return {@link io.github.nichetoolkit.rest.worker.jwt.JwtWorker} The get instance return object is JwtWorker
type.
*/
public static JwtWorker getInstance() {
return INSTANCE;
}
/**
* jwtProperties
* {@link io.github.nichetoolkit.rest.configure.RestJwtProperties} The jwtProperties
field.
* @see io.github.nichetoolkit.rest.configure.RestJwtProperties
*/
private final RestJwtProperties jwtProperties;
/**
* JwtWorker
* Instantiates a new jwt worker.
* @param jwtProperties {@link io.github.nichetoolkit.rest.configure.RestJwtProperties} The jwt properties parameter is RestJwtProperties
type.
* @see io.github.nichetoolkit.rest.configure.RestJwtProperties
* @see org.springframework.beans.factory.annotation.Autowired
*/
@Autowired
public JwtWorker(RestJwtProperties jwtProperties) {
this.jwtProperties = jwtProperties;
this.jwtBuilder = jwtProperties.toBuilder();
this.algorithm = jwtProperties.getAlgorithm();
this.signer = jwtProperties.getAlgorithm().getSigner();
this.verifier = jwtProperties.getAlgorithm().getVerifier();
}
/**
* jwtWorkerInit
* The jwt worker init method.
* @see javax.annotation.PostConstruct
*/
@PostConstruct
public void jwtWorkerInit() {
log.debug("The jwt properties: {}", JsonUtils.parseJson(this.jwtProperties));
INSTANCE = this;
}
/**
* generate
* The generate method.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @return {@link java.lang.String} The generate return object is String
type.
* @see java.lang.String
*/
public String generate(String subject) {
this.jwtBuilder.subject(subject);
return token(this.jwtBuilder,this.signer);
}
/**
* generate
* The generate method.
* @param uniqueId {@link java.lang.String} The unique id parameter is String
type.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @return {@link java.lang.String} The generate return object is String
type.
* @see java.lang.String
*/
public String generate(String uniqueId,String subject) {
this.jwtBuilder.uniqueId(uniqueId).subject(subject);
return token(this.jwtBuilder,this.signer);
}
/**
* generate
* The generate method.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @param claimsMap {@link java.util.Map} The claims map parameter is Map
type.
* @return {@link java.lang.String} The generate return object is String
type.
* @see java.lang.String
* @see java.util.Map
*/
public String generate(String subject, Map claimsMap) {
this.jwtBuilder.subject(subject).addClaim(claimsMap);
return token(this.jwtBuilder,this.signer);
}
/**
* generate
* The generate method.
* @param uniqueId {@link java.lang.String} The unique id parameter is String
type.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @param claimsMap {@link java.util.Map} The claims map parameter is Map
type.
* @return {@link java.lang.String} The generate return object is String
type.
* @see java.lang.String
* @see java.util.Map
*/
public String generate(String uniqueId, String subject, Map claimsMap) {
this.jwtBuilder.uniqueId(uniqueId).subject(subject).addClaim(claimsMap);
return token(this.jwtBuilder,this.signer);
}
/**
* parser
* The parser method.
* @param token {@link java.lang.String} The token parameter is String
type.
* @return {@link io.fusionauth.jwt.domain.JWT} The parser return object is JWT
type.
* @see java.lang.String
* @see io.fusionauth.jwt.domain.JWT
*/
public JWT parser(String token) {
return parse(token,this.verifier);
}
/**
* builder
* The builder method.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @return {@link io.github.nichetoolkit.rest.worker.jwt.JwtBuilder} The builder return object is JwtBuilder
type.
* @see java.lang.String
* @see io.github.nichetoolkit.rest.worker.jwt.JwtBuilder
*/
public static JwtBuilder builder(String subject) {
return JwtBuilder.builder().uniqueId(UUID.randomUUID().toString())
.issuedAt(ZonedDateTime.now()).subject(subject);
}
/**
* builder
* The builder method.
* @param uniqueId {@link java.lang.String} The unique id parameter is String
type.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @return {@link io.github.nichetoolkit.rest.worker.jwt.JwtBuilder} The builder return object is JwtBuilder
type.
* @see java.lang.String
* @see io.github.nichetoolkit.rest.worker.jwt.JwtBuilder
*/
public static JwtBuilder builder(String uniqueId, String subject) {
return JwtBuilder.builder().uniqueId(uniqueId)
.issuedAt(ZonedDateTime.now()).subject(subject);
}
/**
* builder
* The builder method.
* @param uniqueId {@link java.lang.String} The unique id parameter is String
type.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @param claimsMap {@link java.util.Map} The claims map parameter is Map
type.
* @return {@link io.github.nichetoolkit.rest.worker.jwt.JwtBuilder} The builder return object is JwtBuilder
type.
* @see java.lang.String
* @see java.util.Map
* @see io.github.nichetoolkit.rest.worker.jwt.JwtBuilder
*/
public static JwtBuilder builder(String uniqueId, String subject, Map claimsMap) {
return JwtBuilder.builder().addClaim(claimsMap).uniqueId(uniqueId)
.issuedAt(ZonedDateTime.now()).subject(subject);
}
/**
* builder
* The builder method.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @param claimsMap {@link java.util.Map} The claims map parameter is Map
type.
* @return {@link io.github.nichetoolkit.rest.worker.jwt.JwtBuilder} The builder return object is JwtBuilder
type.
* @see java.lang.String
* @see java.util.Map
* @see io.github.nichetoolkit.rest.worker.jwt.JwtBuilder
*/
public static JwtBuilder builder(String subject, Map claimsMap) {
return JwtBuilder.builder().addClaim(claimsMap).uniqueId(UUID.randomUUID().toString())
.issuedAt(ZonedDateTime.now()).subject(subject);
}
/**
* token
* The token method.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see java.lang.String
*/
public static String token(String subject) {
JwtBuilder jwtBuilder = builder(subject);
return token(jwtBuilder,INSTANCE.signer);
}
/**
* token
* The token method.
* @param uniqueId {@link java.lang.String} The unique id parameter is String
type.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see java.lang.String
*/
public static String token(String uniqueId,String subject) {
JwtBuilder jwtBuilder = builder(uniqueId,subject);
return token(jwtBuilder,INSTANCE.signer);
}
/**
* token
* The token method.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @param claimsMap {@link java.util.Map} The claims map parameter is Map
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see java.lang.String
* @see java.util.Map
*/
public static String token(String subject, Map claimsMap) {
JwtBuilder jwtBuilder = builder(subject, claimsMap);
return token(jwtBuilder,INSTANCE.signer);
}
/**
* token
* The token method.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param privateKey {@link java.security.PrivateKey} The private key parameter is PrivateKey
type.
* @param kid {@link java.lang.String} The kid parameter is String
type.
* @param cryptoProvider {@link io.fusionauth.security.CryptoProvider} The crypto provider parameter is CryptoProvider
type.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @param claimsMap {@link java.util.Map} The claims map parameter is Map
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.security.PrivateKey
* @see java.lang.String
* @see io.fusionauth.security.CryptoProvider
* @see java.util.Map
*/
public static String token(JwtAlgorithm algorithm, PrivateKey privateKey, String kid, CryptoProvider cryptoProvider, String subject, Map claimsMap) {
return token(builder(subject,claimsMap),algorithm.signer(privateKey,kid,cryptoProvider));
}
/**
* token
* The token method.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param privateKey {@link java.security.PrivateKey} The private key parameter is PrivateKey
type.
* @param cryptoProvider {@link io.fusionauth.security.CryptoProvider} The crypto provider parameter is CryptoProvider
type.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @param claimsMap {@link java.util.Map} The claims map parameter is Map
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.security.PrivateKey
* @see io.fusionauth.security.CryptoProvider
* @see java.lang.String
* @see java.util.Map
*/
public static String token(JwtAlgorithm algorithm, PrivateKey privateKey, CryptoProvider cryptoProvider, String subject, Map claimsMap) {
return token(builder(subject,claimsMap),algorithm.signer(privateKey,cryptoProvider));
}
/**
* token
* The token method.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param privateKey {@link java.security.PrivateKey} The private key parameter is PrivateKey
type.
* @param kid {@link java.lang.String} The kid parameter is String
type.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @param claimsMap {@link java.util.Map} The claims map parameter is Map
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.security.PrivateKey
* @see java.lang.String
* @see java.util.Map
*/
public static String token(JwtAlgorithm algorithm, PrivateKey privateKey, String kid, String subject, Map claimsMap) {
return token(builder(subject,claimsMap),algorithm.signer(privateKey,kid));
}
/**
* token
* The token method.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param privateKey {@link java.security.PrivateKey} The private key parameter is PrivateKey
type.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @param claimsMap {@link java.util.Map} The claims map parameter is Map
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.security.PrivateKey
* @see java.lang.String
* @see java.util.Map
*/
public static String token(JwtAlgorithm algorithm, PrivateKey privateKey, String subject, Map claimsMap) {
return token(builder(subject,claimsMap),algorithm.signer(privateKey));
}
/**
* token
* The token method.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param secretKey {@link java.lang.String} The secret key parameter is String
type.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @param claimsMap {@link java.util.Map} The claims map parameter is Map
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.lang.String
* @see java.util.Map
*/
public static String token(JwtAlgorithm algorithm, String secretKey, String subject, Map claimsMap) {
return token(builder(subject,claimsMap),algorithm.signer(secretKey));
}
/**
* token
* The token method.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param secretKey {@link java.lang.String} The secret key parameter is String
type.
* @param kid {@link java.lang.String} The kid parameter is String
type.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @param claimsMap {@link java.util.Map} The claims map parameter is Map
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.lang.String
* @see java.util.Map
*/
public static String token(JwtAlgorithm algorithm, String secretKey, String kid, String subject, Map claimsMap) {
return token(builder(subject,claimsMap),algorithm.signer(secretKey,kid));
}
/**
* token
* The token method.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param secretKey {@link java.lang.String} The secret key parameter is String
type.
* @param cryptoProvider {@link io.fusionauth.security.CryptoProvider} The crypto provider parameter is CryptoProvider
type.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @param claimsMap {@link java.util.Map} The claims map parameter is Map
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.lang.String
* @see io.fusionauth.security.CryptoProvider
* @see java.util.Map
*/
public static String token(JwtAlgorithm algorithm, String secretKey, CryptoProvider cryptoProvider, String subject, Map claimsMap) {
return token(builder(subject,claimsMap),algorithm.signer(secretKey,cryptoProvider));
}
/**
* token
* The token method.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param secretKey {@link java.lang.String} The secret key parameter is String
type.
* @param kid {@link java.lang.String} The kid parameter is String
type.
* @param cryptoProvider {@link io.fusionauth.security.CryptoProvider} The crypto provider parameter is CryptoProvider
type.
* @param subject {@link java.lang.String} The subject parameter is String
type.
* @param claimsMap {@link java.util.Map} The claims map parameter is Map
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.lang.String
* @see io.fusionauth.security.CryptoProvider
* @see java.util.Map
*/
public static String token(JwtAlgorithm algorithm, String secretKey, String kid, CryptoProvider cryptoProvider, String subject, Map claimsMap) {
return token(builder(subject,claimsMap),algorithm.signer(secretKey,kid,cryptoProvider));
}
/**
* token
* The token method.
* @param jwtBuilder {@link io.github.nichetoolkit.rest.worker.jwt.JwtBuilder} The jwt builder parameter is JwtBuilder
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param privateKey {@link java.security.PrivateKey} The private key parameter is PrivateKey
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtBuilder
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.security.PrivateKey
* @see java.lang.String
*/
public static String token(JwtBuilder jwtBuilder, JwtAlgorithm algorithm, PrivateKey privateKey) {
return JWT.getEncoder().encode(jwtBuilder.build(), algorithm.signer(privateKey));
}
/**
* token
* The token method.
* @param jwtBuilder {@link io.github.nichetoolkit.rest.worker.jwt.JwtBuilder} The jwt builder parameter is JwtBuilder
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param privateKey {@link java.security.PrivateKey} The private key parameter is PrivateKey
type.
* @param kid {@link java.lang.String} The kid parameter is String
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtBuilder
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.security.PrivateKey
* @see java.lang.String
*/
public static String token(JwtBuilder jwtBuilder, JwtAlgorithm algorithm, PrivateKey privateKey, String kid) {
return JWT.getEncoder().encode(jwtBuilder.build(), algorithm.signer(privateKey,kid));
}
/**
* token
* The token method.
* @param jwtBuilder {@link io.github.nichetoolkit.rest.worker.jwt.JwtBuilder} The jwt builder parameter is JwtBuilder
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param privateKey {@link java.security.PrivateKey} The private key parameter is PrivateKey
type.
* @param cryptoProvider {@link io.fusionauth.security.CryptoProvider} The crypto provider parameter is CryptoProvider
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtBuilder
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.security.PrivateKey
* @see io.fusionauth.security.CryptoProvider
* @see java.lang.String
*/
public static String token(JwtBuilder jwtBuilder, JwtAlgorithm algorithm, PrivateKey privateKey, CryptoProvider cryptoProvider) {
return JWT.getEncoder().encode(jwtBuilder.build(), algorithm.signer(privateKey, cryptoProvider));
}
/**
* token
* The token method.
* @param jwtBuilder {@link io.github.nichetoolkit.rest.worker.jwt.JwtBuilder} The jwt builder parameter is JwtBuilder
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param privateKey {@link java.security.PrivateKey} The private key parameter is PrivateKey
type.
* @param kid {@link java.lang.String} The kid parameter is String
type.
* @param cryptoProvider {@link io.fusionauth.security.CryptoProvider} The crypto provider parameter is CryptoProvider
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtBuilder
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.security.PrivateKey
* @see java.lang.String
* @see io.fusionauth.security.CryptoProvider
*/
public static String token(JwtBuilder jwtBuilder, JwtAlgorithm algorithm, PrivateKey privateKey, String kid, CryptoProvider cryptoProvider) {
return JWT.getEncoder().encode(jwtBuilder.build(), algorithm.signer(privateKey,kid, cryptoProvider));
}
/**
* token
* The token method.
* @param jwtBuilder {@link io.github.nichetoolkit.rest.worker.jwt.JwtBuilder} The jwt builder parameter is JwtBuilder
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param secretKey {@link java.lang.String} The secret key parameter is String
type.
* @param kid {@link java.lang.String} The kid parameter is String
type.
* @param cryptoProvider {@link io.fusionauth.security.CryptoProvider} The crypto provider parameter is CryptoProvider
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtBuilder
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.lang.String
* @see io.fusionauth.security.CryptoProvider
*/
public static String token(JwtBuilder jwtBuilder, JwtAlgorithm algorithm, String secretKey, String kid, CryptoProvider cryptoProvider) {
return JWT.getEncoder().encode(jwtBuilder.build(), algorithm.signer(secretKey,kid, cryptoProvider));
}
/**
* token
* The token method.
* @param jwtBuilder {@link io.github.nichetoolkit.rest.worker.jwt.JwtBuilder} The jwt builder parameter is JwtBuilder
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param secretKey {@link java.lang.String} The secret key parameter is String
type.
* @param kid {@link java.lang.String} The kid parameter is String
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtBuilder
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.lang.String
*/
public static String token(JwtBuilder jwtBuilder, JwtAlgorithm algorithm, String secretKey, String kid) {
return JWT.getEncoder().encode(jwtBuilder.build(), algorithm.signer(secretKey,kid));
}
/**
* token
* The token method.
* @param jwtBuilder {@link io.github.nichetoolkit.rest.worker.jwt.JwtBuilder} The jwt builder parameter is JwtBuilder
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param secretKey {@link java.lang.String} The secret key parameter is String
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtBuilder
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.lang.String
*/
public static String token(JwtBuilder jwtBuilder, JwtAlgorithm algorithm, String secretKey) {
return JWT.getEncoder().encode(jwtBuilder.build(), algorithm.signer(secretKey));
}
/**
* token
* The token method.
* @param jwtBuilder {@link io.github.nichetoolkit.rest.worker.jwt.JwtBuilder} The jwt builder parameter is JwtBuilder
type.
* @param signer {@link io.fusionauth.jwt.Signer} The signer parameter is Signer
type.
* @return {@link java.lang.String} The token return object is String
type.
* @see io.github.nichetoolkit.rest.worker.jwt.JwtBuilder
* @see io.fusionauth.jwt.Signer
* @see java.lang.String
*/
public static String token(JwtBuilder jwtBuilder, Signer signer) {
return JWT.getEncoder().encode(jwtBuilder.build(), signer);
}
/**
* parse
* The parse method.
* @param token {@link java.lang.String} The token parameter is String
type.
* @return {@link io.fusionauth.jwt.domain.JWT} The parse return object is JWT
type.
* @see java.lang.String
* @see io.fusionauth.jwt.domain.JWT
*/
public static JWT parse(String token) {
return parse(token,INSTANCE.verifier);
}
/**
* parse
* The parse method.
* @param token {@link java.lang.String} The token parameter is String
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param bytes byte The bytes parameter is byte
type.
* @return {@link io.fusionauth.jwt.domain.JWT} The parse return object is JWT
type.
* @see java.lang.String
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see io.fusionauth.jwt.domain.JWT
*/
public static JWT parse(String token, JwtAlgorithm algorithm, byte[] bytes) {
return JWT.getDecoder().decode(token, algorithm.verifier(bytes));
}
/**
* parse
* The parse method.
* @param token {@link java.lang.String} The token parameter is String
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param path {@link java.nio.file.Path} The path parameter is Path
type.
* @return {@link io.fusionauth.jwt.domain.JWT} The parse return object is JWT
type.
* @see java.lang.String
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.nio.file.Path
* @see io.fusionauth.jwt.domain.JWT
*/
public static JWT parse(String token, JwtAlgorithm algorithm, Path path) {
return JWT.getDecoder().decode(token, algorithm.verifier(path));
}
/**
* parse
* The parse method.
* @param token {@link java.lang.String} The token parameter is String
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param publicKey {@link java.security.PublicKey} The public key parameter is PublicKey
type.
* @return {@link io.fusionauth.jwt.domain.JWT} The parse return object is JWT
type.
* @see java.lang.String
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.security.PublicKey
* @see io.fusionauth.jwt.domain.JWT
*/
public static JWT parse(String token, JwtAlgorithm algorithm, PublicKey publicKey) {
return parse(token, algorithm.verifier(publicKey));
}
/**
* parse
* The parse method.
* @param token {@link java.lang.String} The token parameter is String
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param secretKey {@link java.lang.String} The secret key parameter is String
type.
* @return {@link io.fusionauth.jwt.domain.JWT} The parse return object is JWT
type.
* @see java.lang.String
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see io.fusionauth.jwt.domain.JWT
*/
public static JWT parse(String token, JwtAlgorithm algorithm, String secretKey) {
return parse(token, algorithm.verifier(secretKey));
}
/**
* parse
* The parse method.
* @param token {@link java.lang.String} The token parameter is String
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param secret {@link java.lang.String} The secret parameter is String
type.
* @param cryptoProvider {@link io.fusionauth.security.CryptoProvider} The crypto provider parameter is CryptoProvider
type.
* @return {@link io.fusionauth.jwt.domain.JWT} The parse return object is JWT
type.
* @see java.lang.String
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see io.fusionauth.security.CryptoProvider
* @see io.fusionauth.jwt.domain.JWT
*/
public static JWT parse(String token, JwtAlgorithm algorithm, String secret, CryptoProvider cryptoProvider) {
return JWT.getDecoder().decode(token, algorithm.verifier(secret, cryptoProvider));
}
/**
* parse
* The parse method.
* @param token {@link java.lang.String} The token parameter is String
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param publicKey {@link java.security.PublicKey} The public key parameter is PublicKey
type.
* @param cryptoProvider {@link io.fusionauth.security.CryptoProvider} The crypto provider parameter is CryptoProvider
type.
* @return {@link io.fusionauth.jwt.domain.JWT} The parse return object is JWT
type.
* @see java.lang.String
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.security.PublicKey
* @see io.fusionauth.security.CryptoProvider
* @see io.fusionauth.jwt.domain.JWT
*/
public static JWT parse(String token, JwtAlgorithm algorithm, PublicKey publicKey, CryptoProvider cryptoProvider) {
return JWT.getDecoder().decode(token, algorithm.verifier(publicKey, cryptoProvider));
}
/**
* parse
* The parse method.
* @param token {@link java.lang.String} The token parameter is String
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param path {@link java.nio.file.Path} The path parameter is Path
type.
* @param cryptoProvider {@link io.fusionauth.security.CryptoProvider} The crypto provider parameter is CryptoProvider
type.
* @return {@link io.fusionauth.jwt.domain.JWT} The parse return object is JWT
type.
* @see java.lang.String
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see java.nio.file.Path
* @see io.fusionauth.security.CryptoProvider
* @see io.fusionauth.jwt.domain.JWT
*/
public static JWT parse(String token, JwtAlgorithm algorithm, Path path, CryptoProvider cryptoProvider) {
return JWT.getDecoder().decode(token, algorithm.verifier(path, cryptoProvider));
}
/**
* parse
* The parse method.
* @param token {@link java.lang.String} The token parameter is String
type.
* @param algorithm {@link io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm} The algorithm parameter is JwtAlgorithm
type.
* @param bytes byte The bytes parameter is byte
type.
* @param cryptoProvider {@link io.fusionauth.security.CryptoProvider} The crypto provider parameter is CryptoProvider
type.
* @return {@link io.fusionauth.jwt.domain.JWT} The parse return object is JWT
type.
* @see java.lang.String
* @see io.github.nichetoolkit.rest.worker.jwt.JwtAlgorithm
* @see io.fusionauth.security.CryptoProvider
* @see io.fusionauth.jwt.domain.JWT
*/
public static JWT parse(String token, JwtAlgorithm algorithm, byte[] bytes, CryptoProvider cryptoProvider) {
return JWT.getDecoder().decode(token, algorithm.verifier(bytes, cryptoProvider));
}
/**
* parse
* The parse method.
* @param token {@link java.lang.String} The token parameter is String
type.
* @param verifier {@link io.fusionauth.jwt.Verifier} The verifier parameter is Verifier
type.
* @return {@link io.fusionauth.jwt.domain.JWT} The parse return object is JWT
type.
* @see java.lang.String
* @see io.fusionauth.jwt.Verifier
* @see io.fusionauth.jwt.domain.JWT
*/
public static JWT parse(String token, Verifier verifier) {
JWT jwt;
if (GeneralUtils.isEmpty(verifier)) {
jwt = JWT.getDecoder().decode(token);
} else {
jwt = JWT.getDecoder().decode(token, verifier);
}
return jwt;
}
}