- java.lang.Object
-
- com.zerodeplibs.webpush.jwt.VAPIDJWTParam
-
public class VAPIDJWTParam extends Object
This class represents parameters for generating JSON Web Token (JWT) used for the Voluntary Application Server Identification (VAPID).
Example:VAPIDJWTParam param = VAPIDJWTParam.getBuilder() .resourceURLString(subscription.getEndpoint()) .expiresAfter(15, TimeUnit.MINUTES) .subject("mailto:example@example.com") .build();Thread Safety:An instance of this class is thread-safe(or immutable) only if each
valueof its additional claims is thread-safe(or immutable).- Author:
- Tomoki Sato
- See Also:
VAPIDJWTGenerator
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classVAPIDJWTParam.BuilderThe builder class forVAPIDJWTParam.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)Compares the given object with this object based on their properties.voidforEachAdditionalClaim(BiConsumer<String,Object> action)Performs the given action for each additional claim.<T> Optional<T>getAdditionalClaim(String name, Class<T> returnType)Gets one of the additional claims that is mapped to the given name and can be cast to the given type.Map<String,Object>getAdditionalClaims()Gets the additional claims.static VAPIDJWTParam.BuildergetBuilder()Gets a newVAPIDJWTParam.Builder.InstantgetExpirationTime()Gets the expiration time at which a JWT for VAPID expires.DategetExpiresAt()Gets the expiration time at which a JWT for VAPID expires.longgetExpiresAtInSeconds()Gets the number of seconds from January 1, 1970, 00:00:00 GMT to the expiration time.StringgetOrigin()Gets the origin extracted from the resource URL.Optional<String>getSubject()Gets the subject.inthashCode()Returns the hash code value for this object based on its properties.StringtoString()
-
-
-
Method Detail
-
getBuilder
public static VAPIDJWTParam.Builder getBuilder()
Gets a newVAPIDJWTParam.Builder.- Returns:
- a new
VAPIDJWTParam.Builder.
-
getAdditionalClaim
public <T> Optional<T> getAdditionalClaim(String name, Class<T> returnType)
Gets one of the additional claims that is mapped to the given name and can be cast to the given type.
Example:ArrayList<String> hogeList = new ArrayList<>(); VAPIDJWTParam param = VAPIDJWTParam.getBuilder() .resourceURLString(.....) .expiresAfter(.....) .additionalClaim("hoge", hogeList); .build(); param.getAdditionalClaim("fuga", Object.class); // -> Optional.empty(); param.getAdditionalClaim("hoge", String.class); // -> Optional.empty(); param.getAdditionalClaim("hoge", ArrayList.class).get(); // -> hogeList; param.getAdditionalClaim("hoge", List.class).get(); // -> hogeList;- Type Parameters:
T- the type of the additional claim.- Parameters:
name- the name of the additional claim.returnType- the type of the additional claim.- Returns:
- an
Optionalthat may or may not contain the additional claim. - See Also:
VAPIDJWTParam.Builder.additionalClaim(String, Object)
-
forEachAdditionalClaim
public void forEachAdditionalClaim(BiConsumer<String,Object> action)
Performs the given action for each additional claim.- Parameters:
action- the action to be performed for each additional claim.
-
getAdditionalClaims
public Map<String,Object> getAdditionalClaims()
Gets the additional claims. The returned map is unmodifiable.- Returns:
- the additional claims.
-
getOrigin
public String getOrigin()
Gets the origin extracted from the resource URL.
Typically, the returned value is used as an "aud" claim.
- Returns:
- the origin.
-
getExpiresAt
public Date getExpiresAt()
Gets the expiration time at which a JWT for VAPID expires.- Returns:
- the expiration time.
-
getExpirationTime
public Instant getExpirationTime()
Gets the expiration time at which a JWT for VAPID expires.- Returns:
- the expiration time.
-
getExpiresAtInSeconds
public long getExpiresAtInSeconds()
Gets the number of seconds from January 1, 1970, 00:00:00 GMT to the expiration time.
Typically, the returned value is used as an "exp" claim.
- Returns:
- the number of seconds.
-
getSubject
public Optional<String> getSubject()
Gets the subject. If a subject is specified at the time of the creation, an Optional containing the subject is returned.
Typically, the returned value is used as an "sub" claim.
- Returns:
- an
Optionalthat may or may not contain the subject.
-
equals
public boolean equals(Object o)
Compares the given object with this object based on their properties.
-
hashCode
public int hashCode()
Returns the hash code value for this object based on its properties.
-
-