- java.lang.Object
-
- com.zerodeplibs.webpush.jwt.VAPIDJWTParam.Builder
-
- Enclosing class:
- VAPIDJWTParam
public static class VAPIDJWTParam.Builder extends Object
The builder class forVAPIDJWTParam.- Author:
- Tomoki Sato
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description VAPIDJWTParam.BuilderadditionalClaim(String name, Object value)Specifies an additional claim.VAPIDJWTParambuild()Creates a newVAPIDJWTParam.VAPIDJWTParambuildWithDefault()Creates a newVAPIDJWTParam.VAPIDJWTParam.BuilderexpirationTime(Instant expirationTime)Specifies the time at which a JWT for VAPID expires.VAPIDJWTParam.BuilderexpiresAfter(int expiresAfter, TimeUnit timeUnit)Specifies the time after which a JWT for VAPID expires.VAPIDJWTParam.BuilderresourceURL(URL resourceURL)Specifies a push resource URL from which the origin is extracted.VAPIDJWTParam.BuilderresourceURLString(String resourceURLString)Specifies a push resource URL from which the origin is extracted.VAPIDJWTParam.Buildersubject(String subject)Specifies a subject.
-
-
-
Method Detail
-
resourceURLString
public VAPIDJWTParam.Builder resourceURLString(String resourceURLString)
Specifies a push resource URL from which the origin is extracted.
Typically,
- the resource URL is the value obtained from an endpoint field of a push subscription.
- the extracted origin is used as an "aud"(Audience) claim.
- Parameters:
resourceURLString- the string representation of a push resource URL.- Returns:
- this object.
- Throws:
MalformedURLRuntimeException- if the underlyingURL(String)throwsMalformedURLException.IllegalStateException- if the methods for specifying a resource URL are called more than once.
-
resourceURL
public VAPIDJWTParam.Builder resourceURL(URL resourceURL)
Specifies a push resource URL from which the origin is extracted.
Typically,
- the resource URL is the value obtained from an endpoint field of a push subscription.
- the extracted origin is used as an "aud"(Audience) claim.
- Parameters:
resourceURL- a push resource URL.- Returns:
- this object.
- Throws:
IllegalStateException- if the methods for specifying a resource URL are called more than once.
-
expiresAfter
public VAPIDJWTParam.Builder expiresAfter(int expiresAfter, TimeUnit timeUnit)
Specifies the time after which a JWT for VAPID expires.
Typically, the specified expiration time is used as an "exp" (Expiry) claim.
- Parameters:
expiresAfter- the time after which a JWT for VAPID expires.timeUnit- the unit of the givenexpiresAfter.- Returns:
- this object.
- Throws:
IllegalStateException- if the methods for specifying expiration time are called more than once.
-
expirationTime
public VAPIDJWTParam.Builder expirationTime(Instant expirationTime)
Specifies the time at which a JWT for VAPID expires.
Typically, the specified expiration time is used as an "exp" (Expiry) claim.
- Parameters:
expirationTime- the time at which a JWT for VAPID expires.- Returns:
- this object.
- Throws:
IllegalStateException- if the methods for specifying expiration time are called more than once.
-
subject
public VAPIDJWTParam.Builder subject(String subject)
Specifies a subject.
Typically, the specified subject is used as a "sub" (Subject) claim.
- Parameters:
subject- a subject.- Returns:
- this object.
-
additionalClaim
public VAPIDJWTParam.Builder additionalClaim(String name, Object value)
Specifies an additional claim.
Typically, the specified entry is used as a claim in a token's payload.
The following names are "reserved". So if one of these names is given, an
IllegalArgumentExceptionis thrown.- "aud" - this claim should be specified
via
resourceURL(URL)orresourceURLString(String). - "exp" - this claim should be specified
via
expirationTime(Instant)orexpiresAfter(int, TimeUnit). - "sub" - this claim should be specified
via
subject(String)
- Parameters:
name- the name of an additional claim.value- the value of an additional claim.- Returns:
- this object.
- Throws:
IllegalArgumentException- if one of the "reserved" names is given.
- "aud" - this claim should be specified
via
-
build
public VAPIDJWTParam build()
Creates a newVAPIDJWTParam.- Returns:
- a new
VAPIDJWTParam. - Throws:
IllegalStateException- if the resource URL and the expiration time aren't specified.
-
buildWithDefault
public VAPIDJWTParam buildWithDefault()
Creates a newVAPIDJWTParam. If the expiration time isn't specified, the value is set to 3 minutes.- Returns:
- a new
VAPIDJWTParam. - Throws:
IllegalStateException- if the resource URL isn't specified.
-
-