Class 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 value of its additional claims is thread-safe(or immutable).

    Author:
    Tomoki Sato
    See Also:
    VAPIDJWTGenerator
    • Method Detail

      • 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 Optional that 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 Optional that may or may not contain the subject.
      • equals

        public boolean equals​(Object o)
        Compares the given object with this object based on their properties.
        Overrides:
        equals in class Object
        Parameters:
        o - an object.
        Returns:
        true if the given object is equal to this object
      • hashCode

        public int hashCode()
        Returns the hash code value for this object based on its properties.
        Overrides:
        hashCode in class Object
        Returns:
        the hash code value for this object.