Class JsonWebToken

    • Constructor Detail

      • JsonWebToken

        public JsonWebToken​(org.jose4j.jwt.JwtClaims jwtClaims)
        Construct a new instance.
        Parameters:
        jwtClaims - the JWT claims for this instance (may not be null)
    • Method Detail

      • getIssuer

        public String getIssuer()
        Get the issuer claim.
        Returns:
        the issuer claim
        Throws:
        IllegalArgumentException - if the issuer claim is malformed
      • getSubject

        public String getSubject()
        Get the subject claim.
        Returns:
        the subject claim
        Throws:
        IllegalArgumentException - if the subject claim is malformed
      • getAudience

        public List<String> getAudience()
        Get the audience claim.
        Returns:
        the audience claim
        Throws:
        IllegalArgumentException - if the audience claim is malformed
      • getExpiration

        public Long getExpiration()
        Get the expiration claim.
        Returns:
        the expiration claim
        Throws:
        IllegalArgumentException - if the expiration claim is malformed
      • isExpired

        public boolean isExpired()
        Return whether this JWT is expired.
        Returns:
        true if this JWT is expired and false otherwise
        Throws:
        IllegalArgumentException - if the issuer claim is malformed
      • getNotBefore

        public Long getNotBefore()
        Get the not before claim.
        Returns:
        the not before claim
        Throws:
        IllegalArgumentException - if the not before claim is malformed
      • isNotBefore

        public boolean isNotBefore()
        Return whether the current time is greater than or equal to the value of the not before claim.
        Returns:
        true if the not before claim is null or if the current time is greater than or equal to the value of the not before claim and false otherwise
        Throws:
        IllegalArgumentException - if the not before claim is malformed
      • isActive

        public boolean isActive()
        Checks that the token is not expired and isn't prior to the not before time.
        Returns:
        true if the token is active and false otherwise
      • getIssuedAt

        public Long getIssuedAt()
        Get the issued at claim.
        Returns:
        the issued at claim
        Throws:
        IllegalArgumentException - if the issued at claim is malformed
      • getClaimNames

        public Set<String> getClaimNames()
        Get the claim names.
        Returns:
        the claim names
      • hasClaim

        public boolean hasClaim​(String claimName)
        Return whether this token has the given claim.
        Parameters:
        claimName - the claim name to check
        Returns:
        true if this token has the given claim and false otherwise
      • getClaimValue

        public Object getClaimValue​(String claimName)
        Get the value of the given claim.
        Parameters:
        claimName - the claim to retrieve
        Returns:
        the value of the given claim
      • getClaimValue

        public <T> T getClaimValue​(String claimName,
                                   Class<T> type)
        Get the value of the given claim.
        Type Parameters:
        T - the type of the value
        Parameters:
        claimName - the claim to retrieve
        type - the type that should be returned
        Returns:
        the value of the given claim
        Throws:
        IllegalArgumentException - if the claim is malformed
      • getClaimValueAsString

        public String getClaimValueAsString​(String claimName)
        Get the value of the given claim.
        Parameters:
        claimName - the claim to retrieve
        Returns:
        the value of the given claim as a string
      • getStringListClaimValue

        public List<String> getStringListClaimValue​(String claimName)
        Get the value of the given claim as a string list.
        Parameters:
        claimName - the claim to retrieve
        Returns:
        the value of the given claim as a string list
      • getCurrentTimeInSeconds

        private static int getCurrentTimeInSeconds()
      • getClaimValueAsLong

        Long getClaimValueAsLong​(String claimName)
      • wrapValue

        public static javax.json.JsonValue wrapValue​(Object value)
      • replaceMap

        public static javax.json.JsonObject replaceMap​(Map<String,​Object> map)
      • toJsonArray

        private static javax.json.JsonArray toJsonArray​(Collection<?> collection)