T
- the generic typeB
- the generic typepublic class JWTBuilder<T extends JWT,B extends JWTBuilder<?,?>> extends Object
A JWTBuilder
is used to construct JWT
instances. It provides a fluent API with methods to populate the claims
for a given JWT
type.
JWT
instances may also be built from a String
representing the token in a JSON format.
The default implementation builds JWT
instances.
Constructor and Description |
---|
JWTBuilder()
Instantiates a new JWT builder.
|
JWTBuilder(Class<T> tokenType)
Instantiates a new JWT builder with the token value.
|
Modifier and Type | Method and Description |
---|---|
B |
audience(String... audience)
Sets the audience that the JWT is intended for.
|
T |
build()
Builds a
JWT instance using the provided claims. |
protected T |
build(javax.json.JsonObject headersObject,
javax.json.JsonObject claimsObject)
Builds the
JsonObject of headers and claims set. |
T |
build(String json)
Builds a
JWT instance from its JSON representation. |
B |
claim(String name,
int... value)
Updates the claims set with the specified claim int value(s).
|
B |
claim(String name,
String... value)
Updates the claims set with the specified claim string value(s).
|
B |
contentType(String contentType)
Sets the Content type used by this specification to convey structural information about the JWT.
|
B |
expiration(int expirationTime)
Sets the expiration time on or after which the token MUST NOT be accepted for processing.
|
protected javax.json.JsonObjectBuilder |
getClaimsBuilder()
Subclasses can use this method to obtain a reference to the
JsonObjectBuilder being used to manage the
claims set. |
protected javax.json.JsonObjectBuilder |
getHeadersBuilder()
Gets the JSON Web Token headers builder.
|
protected Class<T> |
getTokenType()
Gets the token type.
|
B |
header(String name,
int... value)
Updates the headers set with the specified header int value(s).
|
B |
header(String name,
javax.json.JsonArray value)
Updates the headers set with the specified header
JsonArray value. |
B |
header(String name,
List<javax.json.JsonObject> value)
Populates the headers set with the specified header
JsonObject collection. |
B |
header(String name,
String... value)
Updates the headers set with the specified header string value(s).
|
B |
id(String id)
Sets the unique identifier for a JWT.
|
B |
issuedAt(int issuedAt)
Sets the time at which the JWT was issued.
|
B |
issuer(String issuer)
Sets the principal that issued the JWT.
|
B |
notBefore(int notBefore)
Sets the time before which the token MUST NOT be accepted for processing
|
B |
subject(String subject)
Sets the principal that is the subject of the JWT.
|
B |
type(String type)
Sets the MIME Media Type [IANA.MediaTypes] of this complete JWT in contexts where this is useful to the application.
|
protected javax.json.JsonObjectBuilder getHeadersBuilder()
Gets the JSON Web Token headers builder.
protected javax.json.JsonObjectBuilder getClaimsBuilder()
Subclasses can use this method to obtain a reference to the JsonObjectBuilder
being used to manage the
claims set.
public B type(String type)
Sets the MIME Media Type [IANA.MediaTypes] of this complete JWT in contexts where this is useful to the application.
type
- the typepublic B contentType(String contentType)
Sets the Content type used by this specification to convey structural information about the JWT.
contentType
- the content typepublic B id(String id)
Sets the unique identifier for a JWT.
id
- the idpublic B issuer(String issuer)
Sets the principal that issued the JWT.
issuer
- the issuerpublic B audience(String... audience)
Sets the audience that the JWT is intended for.
audience
- the audiencepublic B subject(String subject)
Sets the principal that is the subject of the JWT.
subject
- the subjectpublic B issuedAt(int issuedAt)
Sets the time at which the JWT was issued.
issuedAt
- the issued atpublic B expiration(int expirationTime)
Sets the expiration time on or after which the token MUST NOT be accepted for processing.
expirationTime
- the expiration timepublic B notBefore(int notBefore)
Sets the time before which the token MUST NOT be accepted for processing
notBefore
- the not beforepublic B claim(String name, String... value)
Updates the claims set with the specified claim string value(s).
name
- the name of the claimvalue
- the value(s) of the claimpublic B claim(String name, int... value)
Updates the claims set with the specified claim int value(s).
name
- the name of the claimvalue
- the value(s) of the claimpublic B header(String name, String... value)
Updates the headers set with the specified header string value(s).
name
- the name of the headervalue
- the value(s) of the headerpublic B header(String name, int... value)
Updates the headers set with the specified header int value(s).
name
- the name of the headervalue
- the value(s) of the headerpublic B header(String name, List<javax.json.JsonObject> value)
Populates the headers set with the specified header JsonObject
collection.
name
- the name of the headervalue
- the value(s) of the headerpublic B header(String name, javax.json.JsonArray value)
Updates the headers set with the specified header JsonArray
value.
name
- the name of the headervalue
- the value(s) of the headerpublic T build(String json)
Builds a JWT
instance from its JSON representation.
json
- the jwt encoded json stringprotected T build(javax.json.JsonObject headersObject, javax.json.JsonObject claimsObject)
Builds the JsonObject
of headers and claims set.
headersObject
- the headers objectclaimsObject
- the claims objectCopyright © 2015. All rights reserved.