| Modifier and Type | Field and Description |
|---|---|
static java.time.Instant |
NO_EXPIRE_DATE |
| Modifier and Type | Method and Description |
|---|---|
Token |
createToken()
Builds and signs the token using the the algorithm set via
withSignatureAlgorithm(JwtSignatureAlgorithm) and the given key. |
static JwtGenerator |
getInstance(Service service,
String clientId) |
JwtGenerator |
withAppId(String appId)
This method does not actually set data on the token itself but sets the appId
that is used by
withLocalScopes(String...) to create the local
scopes. |
JwtGenerator |
withClaimsFromFile(String claimsJsonResource)
This method will fill the token with all the claims that are defined inside
the given file.
|
JwtGenerator |
withClaimValue(String claimName,
JsonObject object)
Sets the claim with the given name to the given string value.
|
JwtGenerator |
withClaimValue(String claimName,
String value)
Sets the claim with the given name to the given string value.
|
JwtGenerator |
withClaimValues(String claimName,
String... values)
Sets the claim with the given name to the given string values.
|
JwtGenerator |
withExpiration(java.time.Instant expiration)
Sets the expiration claim (exp) of the token to the given moment in time.
|
JwtGenerator |
withHeaderParameter(String parameterName,
String value)
Sets the header parameter with the given name to the given string value.
|
JwtGenerator |
withLocalScopes(String... scopes)
Works like
withScopes(String...)} but prefixes the scopes with
"appId.". |
JwtGenerator |
withPrivateKey(PrivateKey privateKey)
Sets the private key that is used to sign the token.
|
JwtGenerator |
withScopes(String... scopes)
Sets the roles as claim "scope" to the jwt.
|
JwtGenerator |
withSignatureAlgorithm(JwtSignatureAlgorithm signatureAlgorithm)
Sets the signature algorithm that is used to create the signature of the
token.
|
public static JwtGenerator getInstance(Service service, String clientId)
public JwtGenerator withHeaderParameter(String parameterName, String value)
parameterName - the name of the header parameter to be set.value - the string value of the header parameter to be set.public JwtGenerator withClaimValue(String claimName, String value)
claimName - the name of the claim to be set.value - the string value of the claim to be set.public JwtGenerator withClaimValue(String claimName, JsonObject object)
claimName - the name of the claim to be set.object - the string value of the claim to be set.JsonParsingException - if the given object does not contain valid json.public JwtGenerator withClaimValues(String claimName, String... values)
claimName - the name of the claim to be set.values - the string values of the claims to be set.public JwtGenerator withClaimsFromFile(String claimsJsonResource) throws IOException
claimsJsonResource - the resource path to the file containing the claims in json
format, e.g. "/claims.json"JsonParsingException - if the file does not contain a valid json object.IOException - when the file cannot be read or does not exist.public JwtGenerator withExpiration(@Nonnull java.time.Instant expiration)
expiration - the moment in time when the token will be expired.public JwtGenerator withSignatureAlgorithm(JwtSignatureAlgorithm signatureAlgorithm)
signatureAlgorithm - the signature algorithm.public JwtGenerator withPrivateKey(PrivateKey privateKey)
privateKey - the private key.public JwtGenerator withScopes(String... scopes)
withLocalScopes(String...)}. Note that this is specific to tokens of
service type Service.XSUAA.scopes - the scopes that should be part of the tokenIllegalArgumentException - if service is not Service.XSUAApublic JwtGenerator withLocalScopes(String... scopes)
withScopes(String...)} but prefixes the scopes with
"appId.". For example if the appId is "xsapp", the scope "Read" will be
converted to "xsapp.Read". Make sure the appId has been set via
withAppId(String) before calling this method. Consecutive calls of
this method will overwrite the data that has previously been set. Calls of
this method however do not overwrite the data set via
withScopes(String...)}. Note that this is specific to tokens of
service type Service.XSUAA.scopes - IllegalStateException - if the appId has not been set via withAppId(String)public JwtGenerator withAppId(String appId)
withLocalScopes(String...) to create the local
scopes.appId - the appId to be used for local scopes creationpublic Token createToken()
withSignatureAlgorithm(JwtSignatureAlgorithm) and the given key. By
defaultJwtSignatureAlgorithm.RS256 is used.Copyright © 2020. All rights reserved.