java.lang.Object
iu.crypt.Jwt
- All Implemented Interfaces:
WebToken
- Direct Known Subclasses:
SessionJwt
Immutable
WebToken
with JWT signing, signature verification, and
encryption methods.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final JsonObject
Parsed JWT claimsprotected static final IuJsonAdapter
<Instant> TranslatesInstant
values as seconds since epoch -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonObject
decryptAndVerify
(String jwt, WebKey issuerKey, WebKey audienceKey) Parses, decrypts, and verifies a JWT encoded withJWS compact serialization
.boolean
Gets the token audience URIs.Gets the time after which the JWT should not be accepted.Gets the time the JWT was issued.Gets the token issuer URI.getNonce()
Gets the nonce claim.Gets the time before which the JWT should not be accepted.Gets the subject of the JWT.Gets the token identifier.int
hashCode()
boolean
Determines if the token has expired.sign
(String type, WebKey.Algorithm algorithm, WebKey issuerKey) Signs thisJwt
signAndEncrypt
(String type, WebKey.Algorithm signAlgorithm, WebKey issuerKey, WebKey.Algorithm encryptAlgorithm, WebEncryption.Encryption encryption, WebKey audienceKey) Signs and encrypts thisJwt
toString()
protected void
validate()
Performs basic JWT validation logic.void
validateClaims
(URI expectedAudience, Duration ttl) Verify JWT registered claims are well-formed and within the allowed time window.static JsonObject
Parses and verifies a JWT encoded withJWS compact serialization
.
-
Field Details
-
NUMERIC_DATE
TranslatesInstant
values as seconds since epoch -
claims
Parsed JWT claims
-
-
Constructor Details
-
Jwt
JSON claims constructor- Parameters:
claims
-JsonObject
of token claims
-
-
Method Details
-
verify
Parses and verifies a JWT encoded withJWS compact serialization
.- Parameters:
jwt
-JWS compact serialization
issuerKey
- Issuer publicWebKey
- Returns:
JsonObject
of token claims
-
decryptAndVerify
Parses, decrypts, and verifies a JWT encoded withJWS compact serialization
.- Parameters:
jwt
-JWS
orJWE
compact serializationissuerKey
- Issuer publicWebKey
audienceKey
- Audience privateWebKey
, ignored if the JWT is not encrypted- Returns:
JsonObject
of token claims
-
validate
protected void validate()Performs basic JWT validation logic.- See Also:
-
validateClaims
Description copied from interface:WebToken
Verify JWT registered claims are well-formed and within the allowed time window.In addition to the rules outlined in RFC-7519 JWT Section 4.1, REQUIRES the following claim values to be present and not empty:
- Specified by:
validateClaims
in interfaceWebToken
- Parameters:
expectedAudience
- Expected audienceURI
ttl
- Maximum assertion time to live allowed by configuration
-
getTokenId
Description copied from interface:WebToken
Gets the token identifier.- Specified by:
getTokenId
in interfaceWebToken
- Returns:
- token identifier (jti claim);
-
getIssuer
Description copied from interface:WebToken
Gets the token issuer URI. -
getAudience
Description copied from interface:WebToken
Gets the token audience URIs.- Specified by:
getAudience
in interfaceWebToken
- Returns:
- at least one
URI
-
getSubject
Description copied from interface:WebToken
Gets the subject of the JWT.- Specified by:
getSubject
in interfaceWebToken
- Returns:
- subject (sub claim)
-
getIssuedAt
Description copied from interface:WebToken
Gets the time the JWT was issued.- Specified by:
getIssuedAt
in interfaceWebToken
- Returns:
- issued time (iat claim)
-
getNotBefore
Description copied from interface:WebToken
Gets the time before which the JWT should not be accepted.- Specified by:
getNotBefore
in interfaceWebToken
- Returns:
- not before time (nbf claim)
-
getExpires
Description copied from interface:WebToken
Gets the time after which the JWT should not be accepted.- Specified by:
getExpires
in interfaceWebToken
- Returns:
- token expiration time (exp claim)
-
getNonce
Description copied from interface:WebToken
Gets the nonce claim. -
isExpired
public boolean isExpired()Description copied from interface:WebToken
Determines if the token has expired.- Specified by:
isExpired
in interfaceWebToken
- Returns:
- true if
WebToken.getExpires()
is in the past
-
sign
Signs thisJwt
- Specified by:
sign
in interfaceWebToken
- Parameters:
type
- Token typealgorithm
-WebKey.Algorithm
issuerKey
- Issuer privateWebKey
- Returns:
JWS compact serialization
-
signAndEncrypt
public String signAndEncrypt(String type, WebKey.Algorithm signAlgorithm, WebKey issuerKey, WebKey.Algorithm encryptAlgorithm, WebEncryption.Encryption encryption, WebKey audienceKey) Signs and encrypts thisJwt
- Specified by:
signAndEncrypt
in interfaceWebToken
- Parameters:
type
- Token typesignAlgorithm
-WebKey.Algorithm
issuerKey
- Issuer privateWebKey
encryptAlgorithm
-WebKey.Algorithm
encryption
-WebEncryption.Encryption
audienceKey
- Audience publicWebKey
- Returns:
JWE compact serialization
-
hashCode
public int hashCode() -
equals
-
toString
-