public final class Jwt extends Object
JwtClaimsBuilder
which produces
signed, encrypted or signed first and then encrypted JWT tokens.
The following example shows how to initialize a JwtClaimsBuilder
from an existing resource
containing the claims in a JSON format and produce a signed JWT token with a configured signing key:
String = Jwt.claims("/tokenClaims.json").sign();
The next example shows how to use JwtClaimsBuilder
to add the claims and encrypt a JSON
representation of these claims with a configured encrypting key:
String = Jwt.claims().issuer("https://issuer.org").claim("custom-claim", "custom-value").encrypt();
The final example shows how to initialize a JwtClaimsBuilder
from an existing resource
containing the claims in a JSON format, produce an inner signed JWT token with a configured signing key
and encrypt it with a configured encrypting key.
String = Jwt.claims("/tokenClaims.json").innerSign().encrypt();
Constructor and Description |
---|
Jwt() |
Modifier and Type | Method and Description |
---|---|
static JwtClaimsBuilder |
audience(Set<String> audiences)
Creates a new instance of
JwtClaimsBuilder with a specified 'audience' claim. |
static JwtClaimsBuilder |
audience(String audience)
Creates a new instance of
JwtClaimsBuilder with a specified 'audience' claim. |
static JwtClaimsBuilder |
claim(String name,
Object value)
Creates a new instance of
JwtClaimsBuilder with a specified claim. |
static JwtClaimsBuilder |
claims()
Creates a new instance of
JwtClaimsBuilder |
static JwtClaimsBuilder |
claims(javax.json.JsonObject jsonObject)
Creates a new instance of
JwtClaimsBuilder from JsonObject |
static JwtClaimsBuilder |
claims(org.eclipse.microprofile.jwt.JsonWebToken jwt)
Creates a new instance of
JwtClaimsBuilder from JsonWebToken . |
static JwtClaimsBuilder |
claims(Map<String,Object> claims)
Creates a new instance of
JwtClaimsBuilder from a map of claims. |
static JwtClaimsBuilder |
claims(String jsonLocation)
Creates a new instance of
JwtClaimsBuilder from a JSON resource. |
static String |
encrypt(javax.json.JsonObject jsonObject)
Encrypt the claims loaded from
JsonObject using 'RSA-OAEP-256' algorithm with a public RSA key
loaded from the location set with the "smallrye.jwt.encrypt.key-location". |
static String |
encrypt(Map<String,Object> claims)
Encrypt the claims using 'RSA-OAEP-256' algorithm with a public RSA key
loaded from the location set with the "smallrye.jwt.encrypt.key-location".
|
static String |
encrypt(String jsonLocation)
Encrypt the claims loaded from a JSON resource using 'RSA-OAEP-256' algorithm with a public RSA key
loaded from the location set with the "smallrye.jwt.encrypt.key-location".
|
static JwtClaimsBuilder |
groups(Set<String> groups)
Creates a new instance of
JwtClaimsBuilder with a specified 'groups' claim. |
static JwtClaimsBuilder |
groups(String groups)
Creates a new instance of
JwtClaimsBuilder with a specified 'groups' claim. |
static String |
innerSignAndEncrypt(javax.json.JsonObject jsonObject)
Sign the claims loaded from
JsonObject using 'RS256' algorithm with a private RSA key
loaded from the location set with the "smallrye.jwt.sign.key-location" and encrypt the inner JWT using
'RSA-OAEP-256' algorithm with a public RSA key loaded from the location set with the "smallrye.jwt.encrypt.key-location". |
static String |
innerSignAndEncrypt(Map<String,Object> claims)
Sign the claims using 'RS256' algorithm with a private RSA key
loaded from the location set with the "smallrye.jwt.sign.key-location" and encrypt the inner JWT using
'RSA-OAEP-256' algorithm with a public RSA key loaded from the location set with the "smallrye.jwt.encrypt.key-location".
|
static String |
innerSignAndEncrypt(String jsonLocation)
Sign the claims loaded from a JSON resource using 'RS256' algorithm with a private RSA key
loaded from the location set with the "smallrye.jwt.sign.key-location" and encrypt the inner JWT using
'RSA-OAEP-256' algorithm with a public RSA key loaded from the location set with the "smallrye.jwt.encrypt.key-location".
|
static JwtClaimsBuilder |
issuer(String issuer)
Creates a new instance of
JwtClaimsBuilder with a specified issuer. |
static JwtClaimsBuilder |
preferredUserName(String preferredUserName)
Creates a new instance of
JwtClaimsBuilder with a specified 'preferred_username' claim. |
static String |
sign(javax.json.JsonObject jsonObject)
Sign the claims loaded from
JsonObject using 'RS256' algorithm with a private RSA key
loaded from the location set with the "smallrye.jwt.sign.key-location". |
static String |
sign(Map<String,Object> claims)
Sign the claims using 'RS256' algorithm with a private RSA key
loaded from the location set with the "smallrye.jwt.sign.key-location".
|
static String |
sign(String jsonLocation)
Sign the claims loaded from a JSON resource using 'RS256' algorithm with a private RSA key
loaded from the location set with the "smallrye.jwt.sign.key-location".
|
static JwtClaimsBuilder |
subject(String subject)
Creates a new instance of
JwtClaimsBuilder with a specified subject. |
static JwtClaimsBuilder |
upn(String upn)
Creates a new instance of
JwtClaimsBuilder with a specified 'upn' claim. |
public static JwtClaimsBuilder claims()
JwtClaimsBuilder
JwtClaimsBuilder
public static JwtClaimsBuilder claims(Map<String,Object> claims)
JwtClaimsBuilder
from a map of claims.claims
- the map with the claim name and value pairs. Claim value is converted to String unless it is
an instance of Boolean
, Number
, Collection
, Map
,
JsonObject
or JsonArray
.JwtClaimsBuilder
public static JwtClaimsBuilder claims(javax.json.JsonObject jsonObject)
JwtClaimsBuilder
from JsonObject
jsonObject
- JsonObject
containing the claims.JwtClaimsBuilder
public static JwtClaimsBuilder claims(String jsonLocation)
JwtClaimsBuilder
from a JSON resource.jsonLocation
- JSON resource locationJwtClaimsBuilder
public static JwtClaimsBuilder claims(org.eclipse.microprofile.jwt.JsonWebToken jwt)
JwtClaimsBuilder
from JsonWebToken
.jwt
- JsonWebToken token.JwtClaimsBuilder
public static JwtClaimsBuilder claim(String name, Object value)
JwtClaimsBuilder
with a specified claim.name
- the claim namevalue
- the claim valueJwtClaimsBuilder
public static JwtClaimsBuilder issuer(String issuer)
JwtClaimsBuilder
with a specified issuer.issuer
- the issuerJwtClaimsBuilder
public static JwtClaimsBuilder subject(String subject)
JwtClaimsBuilder
with a specified subject.subject
- the subjectJwtClaimsBuilder
public static JwtClaimsBuilder groups(String groups)
JwtClaimsBuilder
with a specified 'groups' claim.groups
- the groupsJwtClaimsBuilder
public static JwtClaimsBuilder groups(Set<String> groups)
JwtClaimsBuilder
with a specified 'groups' claim.groups
- the groupsJwtClaimsBuilder
public static JwtClaimsBuilder audience(String audience)
JwtClaimsBuilder
with a specified 'audience' claim.audience
- the audienceJwtClaimsBuilder
public static JwtClaimsBuilder audience(Set<String> audiences)
JwtClaimsBuilder
with a specified 'audience' claim.audiences
- the audienceJwtClaimsBuilder
public static JwtClaimsBuilder upn(String upn)
JwtClaimsBuilder
with a specified 'upn' claim.upn
- the upnJwtClaimsBuilder
public static JwtClaimsBuilder preferredUserName(String preferredUserName)
JwtClaimsBuilder
with a specified 'preferred_username' claim.preferredUserName
- the preferred user nameJwtClaimsBuilder
public static String sign(String jsonLocation)
JwtClaimsBuilder
description for more information.jsonLocation
- JSON resource locationJwtSignatureException
- the exception if the signing operation has failedpublic static String sign(Map<String,Object> claims)
JwtClaimsBuilder
description for more information.claims
- the map with the claim name and value pairs. Claim value is converted to String unless it is
an instance of Boolean
, Number
, Collection
, Map
,
JsonObject
or JsonArray
JwtSignatureException
- the exception if the signing operation has failedpublic static String sign(javax.json.JsonObject jsonObject)
JsonObject
using 'RS256' algorithm with a private RSA key
loaded from the location set with the "smallrye.jwt.sign.key-location".
Private RSA key of size 2048 bits or larger MUST be used.
The 'iat' (issued at time), 'exp' (expiration time) and 'jit' (unique token identifier) claims
will be and the `iss` issuer claim may be set by the implementation unless they have already been set.
See JwtClaimsBuilder
description for more information.jsonObject
- JsonObject
containing the claims.JwtSignatureException
- the exception if the signing operation has failedpublic static String encrypt(String jsonLocation)
JwtClaimsBuilder
description for more information.jsonLocation
- JSON resource locationJwtEncryptionException
- the exception if the encryption operation has failedpublic static String encrypt(Map<String,Object> claims)
JwtClaimsBuilder
description for more information.claims
- the map with the claim name and value pairs. Claim value is converted to String unless it is
an instance of Boolean
, Number
, Collection
, Map
,
JsonObject
or JsonArray
JwtEncryptionException
- the exception if the encryption operation has failedpublic static String encrypt(javax.json.JsonObject jsonObject)
JsonObject
using 'RSA-OAEP-256' algorithm with a public RSA key
loaded from the location set with the "smallrye.jwt.encrypt.key-location".
Public RSA key of size 2048 bits or larger MUST be used.
The 'iat' (issued at time), 'exp' (expiration time) and 'jit' (unique token identifier) claims
will be and the `iss` issuer claim may be set by the implementation unless they have already been set.
See JwtClaimsBuilder
description for more information.jsonObject
- JsonObject
containing the claims.JwtEncryptionException
- the exception if the encryption operation has failedpublic static String innerSignAndEncrypt(String jsonLocation)
JwtClaimsBuilder
description for more information.jsonLocation
- JSON resource locationJwtEncryptionException
- the exception if the encryption operation has failedpublic static String innerSignAndEncrypt(Map<String,Object> claims)
JwtClaimsBuilder
description for more information.claims
- the map with the claim name and value pairs. Claim value is converted to String unless it is
an instance of Boolean
, Number
, Collection
, Map
,
JsonObject
or JsonArray
JwtEncryptionException
- the exception if the encryption operation has failedpublic static String innerSignAndEncrypt(javax.json.JsonObject jsonObject)
JsonObject
using 'RS256' algorithm with a private RSA key
loaded from the location set with the "smallrye.jwt.sign.key-location" and encrypt the inner JWT using
'RSA-OAEP-256' algorithm with a public RSA key loaded from the location set with the "smallrye.jwt.encrypt.key-location".
Public RSA key of size 2048 bits or larger MUST be used.
The 'iat' (issued at time), 'exp' (expiration time) and 'jit' (unique token identifier) claims
will be and the `iss` issuer claim may be set by the implementation unless they have already been set.
See JwtClaimsBuilder
description for more information.jsonObject
- JsonObject
containing the claims.JwtEncryptionException
- the exception if the encryption operation has failedCopyright © 2018–2020. All rights reserved.