Package io.pravega.shared.security.token
Class JsonWebToken
- java.lang.Object
-
- io.pravega.shared.security.token.JsonWebToken
-
public class JsonWebToken extends java.lang.ObjectCreates 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.DurationdurationToExpiry()Returns the duration relative to the current instant in which the specified JWT is to expire.static JsonWebTokenemptyToken()java.lang.StringgetAudience()The value of the JWT "aud" (Sudience) claim (https://tools.ietf.org/html/rfc7519#section-4.1.3)java.util.DategetExpirationTime()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.StringgetSubject()The value of the JWT "sub" (Subject) claim (https://tools.ietf.org/html/rfc7519#section-4.1.2)java.lang.StringtoCompactString()Returns the 3 part JWT string representation.java.lang.StringtoString()
-
-
-
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 tokenaudience- the intended recipient of the tokensigningKey- 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 tokenaudience- the intended recipient of the tokensigningKey- the signing key to be used for generating the token signatureresourcePermissionClaims- aMapobject with entries comprising of Pravega resource representation as key and permission as valuetimeToLiveInSeconds- 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.
-
emptyToken
public static JsonWebToken emptyToken()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.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()
-
-