Package com.nimbusds.jose
Class JWSHeader.Builder
- java.lang.Object
-
- com.nimbusds.jose.JWSHeader.Builder
-
- Enclosing class:
- JWSHeader
public static class JWSHeader.Builder extends Object
Builder for constructing JSON Web Signature (JWS) headers.Example usage:
JWSHeader header = new JWSHeader.Builder(JWSAlgorithm.HS256) .contentType("text/plain") .customParam("exp", new Date().getTime()) .build();
-
-
Constructor Summary
Constructors Constructor Description Builder(JWSAlgorithm alg)Creates a new JWS header builder.Builder(JWSHeader jwsHeader)Creates a new JWS header builder with the parameters from the specified header.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description JWSHeader.Builderbase64URLEncodePayload(boolean b64)Sets the Base64URL encode payload (b64) parameter.JWSHeaderbuild()Builds a new JWS header.JWSHeader.BuildercontentType(String cty)Sets the content type (cty) parameter.JWSHeader.BuildercriticalParams(Set<String> crit)Sets the critical header parameters (crit) parameter.JWSHeader.BuildercustomParam(String name, Object value)Sets a custom (non-registered) parameter.JWSHeader.BuildercustomParams(Map<String,Object> customParameters)Sets the custom (non-registered) parameters.JWSHeader.Builderjwk(JWK jwk)Sets the public JSON Web Key (JWK) (jwk) parameter.JWSHeader.BuilderjwkURL(URI jku)Sets the public JSON Web Key (JWK) Set URL (jku) parameter.JWSHeader.BuilderkeyID(String kid)Sets the key ID (kid) parameter.JWSHeader.BuilderparsedBase64URL(Base64URL base64URL)Sets the parsed Base64URL.JWSHeader.Buildertype(JOSEObjectType typ)Sets the type (typ) parameter.JWSHeader.Builderx509CertChain(List<Base64> x5c)Sets the X.509 certificate chain parameter (x5c) corresponding to the key used to sign the JWS object.JWSHeader.Builderx509CertSHA256Thumbprint(Base64URL x5t256)Sets the X.509 certificate SHA-256 thumbprint (x5t#S256) parameter.JWSHeader.Builderx509CertThumbprint(Base64URL x5t)Deprecated.JWSHeader.Builderx509CertURL(URI x5u)Sets the X.509 certificate URL (x5u) parameter.
-
-
-
Constructor Detail
-
Builder
public Builder(JWSAlgorithm alg)
Creates a new JWS header builder.- Parameters:
alg- The JWS algorithm (alg) parameter. Must not be "none" ornull.
-
-
Method Detail
-
type
public JWSHeader.Builder type(JOSEObjectType typ)
Sets the type (typ) parameter.- Parameters:
typ- The type parameter,nullif not specified.- Returns:
- This builder.
-
contentType
public JWSHeader.Builder contentType(String cty)
Sets the content type (cty) parameter.- Parameters:
cty- The content type parameter,nullif not specified.- Returns:
- This builder.
-
criticalParams
public JWSHeader.Builder criticalParams(Set<String> crit)
Sets the critical header parameters (crit) parameter.- Parameters:
crit- The names of the critical header parameters, empty set ornullif none.- Returns:
- This builder.
-
jwkURL
public JWSHeader.Builder jwkURL(URI jku)
Sets the public JSON Web Key (JWK) Set URL (jku) parameter.- Parameters:
jku- The public JSON Web Key (JWK) Set URL parameter,nullif not specified.- Returns:
- This builder.
-
jwk
public JWSHeader.Builder jwk(JWK jwk)
Sets the public JSON Web Key (JWK) (jwk) parameter.- Parameters:
jwk- The public JSON Web Key (JWK) (jwk) parameter,nullif not specified.- Returns:
- This builder.
-
x509CertURL
public JWSHeader.Builder x509CertURL(URI x5u)
Sets the X.509 certificate URL (x5u) parameter.- Parameters:
x5u- The X.509 certificate URL parameter,nullif not specified.- Returns:
- This builder.
-
x509CertThumbprint
@Deprecated public JWSHeader.Builder x509CertThumbprint(Base64URL x5t)
Deprecated.Sets the X.509 certificate SHA-1 thumbprint (x5t) parameter.- Parameters:
x5t- The X.509 certificate SHA-1 thumbprint parameter,nullif not specified.- Returns:
- This builder.
-
x509CertSHA256Thumbprint
public JWSHeader.Builder x509CertSHA256Thumbprint(Base64URL x5t256)
Sets the X.509 certificate SHA-256 thumbprint (x5t#S256) parameter.- Parameters:
x5t256- The X.509 certificate SHA-256 thumbprint parameter,nullif not specified.- Returns:
- This builder.
-
x509CertChain
public JWSHeader.Builder x509CertChain(List<Base64> x5c)
Sets the X.509 certificate chain parameter (x5c) corresponding to the key used to sign the JWS object.- Parameters:
x5c- The X.509 certificate chain parameter,nullif not specified.- Returns:
- This builder.
-
keyID
public JWSHeader.Builder keyID(String kid)
Sets the key ID (kid) parameter.- Parameters:
kid- The key ID parameter,nullif not specified.- Returns:
- This builder.
-
base64URLEncodePayload
public JWSHeader.Builder base64URLEncodePayload(boolean b64)
Sets the Base64URL encode payload (b64) parameter.- Parameters:
b64-trueto Base64URL encode the payload for standard JWS serialisation,falsefor unencoded payload (RFC 7797).- Returns:
- This builder.
-
customParam
public JWSHeader.Builder customParam(String name, Object value)
Sets a custom (non-registered) parameter.- Parameters:
name- The name of the custom parameter. Must not match a registered parameter name and must not benull.value- The value of the custom parameter, should map to a valid JSON entity,nullif not specified.- Returns:
- This builder.
- Throws:
IllegalArgumentException- If the specified parameter name matches a registered parameter name.
-
customParams
public JWSHeader.Builder customParams(Map<String,Object> customParameters)
Sets the custom (non-registered) parameters. The values must be serialisable to a JSON entity, otherwise will be ignored.- Parameters:
customParameters- The custom parameters, empty map ornullif none.- Returns:
- This builder.
-
parsedBase64URL
public JWSHeader.Builder parsedBase64URL(Base64URL base64URL)
Sets the parsed Base64URL.- Parameters:
base64URL- The parsed Base64URL,nullif the header is created from scratch.- Returns:
- This builder.
-
-