Class JsonWebToken


  • public class JsonWebToken
    extends java.lang.Object
    Creates Json Web Tokens (JWT). Also, parses a JWT.
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonWebToken​(@NonNull java.lang.String subject, @NonNull java.lang.String audience, @lombok.NonNull byte[] signingKey, java.util.Date expiry, java.util.Map<java.lang.String,​java.lang.Object> resourcePermissionClaims)  
      JsonWebToken​(@NonNull java.lang.String subject, @NonNull java.lang.String audience, @lombok.NonNull byte[] signingKey, java.util.Map<java.lang.String,​java.lang.Object> resourcePermissionClaims, java.lang.Integer timeToLiveInSeconds)
      Creates a new instance of this class.
      JsonWebToken​(java.lang.String subject, java.lang.String audience, byte[] signingKey)
      Creates a new instance of this class.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.time.Duration durationToExpiry()
      Returns the duration relative to the current instant in which the specified JWT is to expire.
      static JsonWebToken emptyToken()  
      java.lang.String getAudience()
      The value of the JWT "aud" (Sudience) claim (https://tools.ietf.org/html/rfc7519#section-4.1.3)
      java.util.Date getExpirationTime()
      The value of the JWT "exp" (Expiration Time) claim (https://tools.ietf.org/html/rfc7519#section-4.1.4).
      java.util.Map<java.lang.String,​java.lang.Object> getPermissionsByResource()  
      java.lang.String getSubject()
      The value of the JWT "sub" (Subject) claim (https://tools.ietf.org/html/rfc7519#section-4.1.2)
      java.lang.String toCompactString()
      Returns the 3 part JWT string representation.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • JsonWebToken

        public JsonWebToken​(java.lang.String subject,
                            java.lang.String audience,
                            byte[] signingKey)
        Creates a new instance of this class.
        Parameters:
        subject - the subject of the token
        audience - the intended recipient of the token
        signingKey - the signing key to be used for generating the token signature
      • JsonWebToken

        public JsonWebToken​(@NonNull
                            @NonNull java.lang.String subject,
                            @NonNull
                            @NonNull java.lang.String audience,
                            @NonNull
                            @lombok.NonNull byte[] signingKey,
                            java.util.Map<java.lang.String,​java.lang.Object> resourcePermissionClaims,
                            java.lang.Integer timeToLiveInSeconds)
        Creates a new instance of this class.
        Parameters:
        subject - the subject of the token
        audience - the intended recipient of the token
        signingKey - the signing key to be used for generating the token signature
        resourcePermissionClaims - a Map object with entries comprising of Pravega resource representation as key and permission as value
        timeToLiveInSeconds - number of seconds relating to the current time after which the token should expire
      • JsonWebToken

        public JsonWebToken​(@NonNull
                            @NonNull java.lang.String subject,
                            @NonNull
                            @NonNull java.lang.String audience,
                            @NonNull
                            @lombok.NonNull byte[] signingKey,
                            java.util.Date expiry,
                            java.util.Map<java.lang.String,​java.lang.Object> resourcePermissionClaims)
    • Method Detail

      • toCompactString

        public java.lang.String toCompactString()
        Returns the 3 part JWT string representation. Example JWT: - Compact representation: eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjM3MDc2MjUyMjgsInMxIjoiUkVBRF9VUERBVEUifQ.j6xbFRIIZxv3GEedqKcZVy-49Y7U1710q-gjY43-UMgO_kwCH_9kJRuZ7Am589kg5TJewmGhGB9SPblES78pEg - Decoded parts: - header: {alg=HS512} - body/payload: {exp=3707625228, s1=READ_UPDATE}, - signature: j6xbFRIIZxv3GEedqKcZVy-49Y7U1710q-gjY43-UMgO_kwCH_9kJRuZ7Am589kg5TJewmGhGB9SPblES78pEg
        Returns:
        compact representation of JWT
      • durationToExpiry

        public java.time.Duration durationToExpiry()
        Returns the duration relative to the current instant in which the specified JWT is to expire.
        Returns:
        the duration relative to the current instant. Returns null if a) the specified token is blank, or b) the specified token is of invalid format, or c) expiration time is missing from the token, or d) expiration time is not a number.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getSubject

        public java.lang.String getSubject()
        The value of the JWT "sub" (Subject) claim (https://tools.ietf.org/html/rfc7519#section-4.1.2)
      • getAudience

        public java.lang.String getAudience()
        The value of the JWT "aud" (Sudience) claim (https://tools.ietf.org/html/rfc7519#section-4.1.3)
      • getExpirationTime

        public java.util.Date getExpirationTime()
        The value of the JWT "exp" (Expiration Time) claim (https://tools.ietf.org/html/rfc7519#section-4.1.4).
      • getPermissionsByResource

        public java.util.Map<java.lang.String,​java.lang.Object> getPermissionsByResource()