public abstract class JwtUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
NATS_USER_JWT_FORMAT
Format string with `%s` place holder for the JWT token followed
by the user NKey seed.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
issueUserJWT(NKey signingKey,
java.lang.String accountId,
java.lang.String publicUserKey)
Issue a user JWT from a scoped signing key.
|
static java.lang.String |
issueUserJWT(NKey signingKey,
java.lang.String accountId,
java.lang.String publicUserKey,
java.lang.String name)
Issue a user JWT from a scoped signing key.
|
static java.lang.String |
issueUserJWT(NKey signingKey,
java.lang.String accountId,
java.lang.String publicUserKey,
java.lang.String name,
java.time.Duration expiration,
java.lang.String... tags)
Issue a user JWT from a scoped signing key.
|
protected static java.lang.String |
issueUserJWT(NKey signingKey,
java.lang.String accountId,
java.lang.String publicUserKey,
java.lang.String name,
java.time.Duration expiration,
java.lang.String[] tags,
long issuedAt)
Method used for testing.
|
public static final java.lang.String NATS_USER_JWT_FORMAT
NKey userKey = NKey.createUser(new SecureRandom()); NKey signingKey = loadFromSecretStore(); String jwt = issueUserJWT(signingKey, accountId, new String(userKey.getPublicKey())); String.format(JwtUtils.NATS_USER_JWT_FORMAT, jwt, new String(userKey.getSeed()));
public static java.lang.String issueUserJWT(NKey signingKey, java.lang.String accountId, java.lang.String publicUserKey) throws java.security.GeneralSecurityException, java.io.IOException
signingKey - a mandatory account nkey pair to sign the generated jwt.accountId - a mandatory public account nkey. Will throw error when not set or not account nkey.publicUserKey - a mandatory public user nkey. Will throw error when not set or not user nkey.java.lang.IllegalArgumentException - if the accountId or publicUserKey is not a valid public key of the proper typejava.lang.NullPointerException - if signingKey, accountId, or publicUserKey are null.java.security.GeneralSecurityException - if SHA-256 MessageDigest is missing, or if the signingKey can not be used for signing.java.io.IOException - if signingKey sign method throws this exception.public static java.lang.String issueUserJWT(NKey signingKey, java.lang.String accountId, java.lang.String publicUserKey, java.lang.String name) throws java.security.GeneralSecurityException, java.io.IOException
signingKey - a mandatory account nkey pair to sign the generated jwt.accountId - a mandatory public account nkey. Will throw error when not set or not account nkey.publicUserKey - a mandatory public user nkey. Will throw error when not set or not user nkey.name - optional human readable name. When absent, default to publicUserKey.java.lang.IllegalArgumentException - if the accountId or publicUserKey is not a valid public key of the proper typejava.lang.NullPointerException - if signingKey, accountId, or publicUserKey are null.java.security.GeneralSecurityException - if SHA-256 MessageDigest is missing, or if the signingKey can not be used for signing.java.io.IOException - if signingKey sign method throws this exception.public static java.lang.String issueUserJWT(NKey signingKey, java.lang.String accountId, java.lang.String publicUserKey, java.lang.String name, java.time.Duration expiration, java.lang.String... tags) throws java.security.GeneralSecurityException, java.io.IOException
signingKey - a mandatory account nkey pair to sign the generated jwt.accountId - a mandatory public account nkey. Will throw error when not set or not account nkey.publicUserKey - a mandatory public user nkey. Will throw error when not set or not user nkey.name - optional human readable name. When absent, default to publicUserKey.expiration - optional but recommended duration, when the generated jwt needs to expire. If not set, JWT will not expire.tags - optional list of tags to be included in the JWT.java.lang.IllegalArgumentException - if the accountId or publicUserKey is not a valid public key of the proper typejava.lang.NullPointerException - if signingKey, accountId, or publicUserKey are null.java.security.GeneralSecurityException - if SHA-256 MessageDigest is missing, or if the signingKey can not be used for signing.java.io.IOException - if signingKey sign method throws this exception.protected static java.lang.String issueUserJWT(NKey signingKey, java.lang.String accountId, java.lang.String publicUserKey, java.lang.String name, java.time.Duration expiration, java.lang.String[] tags, long issuedAt) throws java.security.GeneralSecurityException, java.io.IOException
signingKey - a mandatory account nkey pair to sign the generated jwt.accountId - a mandatory public account nkey. Will throw error when not set or not account nkey.publicUserKey - a mandatory public user nkey. Will throw error when not set or not user nkey.name - optional human readable name. When absent, default to publicUserKey.expiration - optional but recommended duration, when the generated jwt needs to expire. If not set, JWT will not expire.tags - optional list of tags to be included in the JWT.issuedAt - the current epoch seconds.java.lang.IllegalArgumentException - if the accountId or publicUserKey is not a valid public key of the proper typejava.lang.NullPointerException - if signingKey, accountId, or publicUserKey are null.java.security.GeneralSecurityException - if SHA-256 MessageDigest is missing, or if the signingKey can not be used for signing.java.io.IOException - if signingKey sign method throws this exception.