Class Constraints
- java.lang.Object
- 
- org.forgerock.openig.tools.jwt.validation.Constraints
 
- 
- 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static JwtConstraintcanBeDecrypted(SecretsProvider secretsProvider, Purpose<DataDecryptionKey> purpose)Provides aJwtConstraintconfigured with the suppliedSecretsProviderthat contain a secret capable of decrypting and verifying a JWT's encryption.static <T> JwtClaimConstraint<Collection<T>>contains(T expected)Returnsemptyif the list contains the expected value.static <T> JwtClaimConstraint<Collection<T>>containsOnly(T expected)Returnsemptyif the list contains only the expected value.static <T> JwtClaimConstraint<T>equalsAttributeUsingKey()Returns aJwtClaimConstraintthat will succeed if the expected value is equal to the value looked up in the context attributes using the key, otherwise it will fail.static JwtConstrainthasClaims()Returnsemptyif the JWT does contain claims.static JwtConstrainthasValidSignature(JwsSignatureVerifier verifier)Validates the signature of thisSignedJwt.static JwtConstrainthasValidSignatureAndEncryption(JwtConstraint signatureConstraint, JwtConstraint decryptionConstraint)Provides aJwtConstraintconfigured with the suppliedJwtConstraints verifying both signature and encryption.static <T> JwtClaimConstraint<T>isEqualTo(T expected)Returnsemptyif the value is equal to the one expected and fulfill theViolationwith the custom error message.static <T extends Comparable<T>>
 JwtClaimConstraint<T>isGreaterOrEqualTo(Function<ValidatorConstraintContext,T> limitSupplier)Returns aJwtClaimConstraintthat will succeed if the value is greater than or equal to the given value, otherwise it will fail.static <T extends Comparable<T>>
 JwtClaimConstraint<T>isGreaterOrEqualTo(T limit)A shorter version of isGreaterOrEqualTo(constant(limit)).static <T extends Comparable<T>>
 JwtClaimConstraint<T>isGreaterThan(Function<ValidatorConstraintContext,T> limitSupplier)Returns aJwtClaimConstraintthat will succeed if the value is greater than the given value, otherwise it will fail.static <T extends Comparable<T>>
 JwtClaimConstraint<T>isGreaterThan(T limit)A shorter version of isGreaterThan(constant(limit)).static JwtClaimConstraint<Instant>isInTheFuture()Returns aJwtClaimConstraintthat will succeed if the timestamp is after the given date, otherwise it will fail.static JwtClaimConstraint<Instant>isInThePast()Returns aJwtClaimConstraintthat will succeed if the timestamp is before the given date, otherwise it will fail.static <T extends Comparable<T>>
 JwtClaimConstraint<T>isLessOrEqualTo(Function<ValidatorConstraintContext,T> limitSupplier)Returns aJwtClaimConstraintthat will succeed if the value is less than or equal to the given value, otherwise it will fail.static <T extends Comparable<T>>
 JwtClaimConstraint<T>isLessOrEqualTo(T limit)A shorter version of isLessOrEqualTo(constant(limit)).static <T extends Comparable<T>>
 JwtClaimConstraint<T>isLessThan(Function<ValidatorConstraintContext,T> limitSupplier)Returns aJwtClaimConstraintthat will succeed if the value is less than the given value, otherwise it will fail.static <T extends Comparable<T>>
 JwtClaimConstraint<T>isLessThan(T limit)A shorter version of isLessThan(constant(limit)).static JwtClaimConstraint<JsonValue>isNotNull()Returnsemptyif the value is present.static JwtClaimConstraint<String>matches(Pattern pattern)Build and returns a new `Constraint` that checks if the claim's value is matched (as perMatcher.matches()) by the givenregex.
 
- 
- 
- 
Method Detail- 
isEqualTopublic static <T> JwtClaimConstraint<T> isEqualTo(T expected) Returnsemptyif the value is equal to the one expected and fulfill theViolationwith the custom error message.- Type Parameters:
- T- The type on which the constraint applies.
- Parameters:
- expected- The expected value.
- Returns:
- emptyif the value is equal to the one expected or a- Violationcorresponding to this constraint.
 
 - 
containspublic static <T> JwtClaimConstraint<Collection<T>> contains(T expected) Returnsemptyif the list contains the expected value.- Type Parameters:
- T- The type on which the constraint applies.
- Parameters:
- expected- The expected value.
- Returns:
- emptyif the value is contained in the list or a- Violationcorresponding to this constraint.
 
 - 
containsOnlypublic static <T> JwtClaimConstraint<Collection<T>> containsOnly(T expected) Returnsemptyif the list contains only the expected value.- Type Parameters:
- T- The type on which the constraint applies.
- Parameters:
- expected- The expected value.
- Returns:
- emptyif the value is contained in the singletonlist or a- Violationcorresponding to this constraint.
 
 - 
isInTheFuturepublic static JwtClaimConstraint<Instant> isInTheFuture() Returns aJwtClaimConstraintthat will succeed if the timestamp is after the given date, otherwise it will fail. This method uses the skew allowance held on theValidatorConstraintContext.- Returns:
- a JwtClaimConstraintthat will succeed if the timestamp is after the given date, otherwise it will fail.
 
 - 
isInThePastpublic static JwtClaimConstraint<Instant> isInThePast() Returns aJwtClaimConstraintthat will succeed if the timestamp is before the given date, otherwise it will fail. This method uses the skew allowance held on theValidatorConstraintContext.- Returns:
- a JwtClaimConstraintthat will succeed if the timestamp is before the given date, otherwise it will fail.
 
 - 
isGreaterOrEqualTopublic static <T extends Comparable<T>> JwtClaimConstraint<T> isGreaterOrEqualTo(Function<ValidatorConstraintContext,T> limitSupplier) Returns aJwtClaimConstraintthat will succeed if the value is greater than or equal to the given value, otherwise it will fail.- Type Parameters:
- T- The type of the compared value.
- Parameters:
- limitSupplier- A supplier of the limit to be greater than or equal to.
- Returns:
- a JwtClaimConstraintthat will succeed if the value is greater than or equal to the given value, otherwise it will fail.
 
 - 
isGreaterOrEqualTopublic static <T extends Comparable<T>> JwtClaimConstraint<T> isGreaterOrEqualTo(T limit) A shorter version of isGreaterOrEqualTo(constant(limit)).- Type Parameters:
- T- The type of the compared value.
- Parameters:
- limit- The limit to be greater than or equal to.
- Returns:
- a JwtClaimConstraintthat will succeed if the value is greater than or equal to the given value, otherwise it will fail.
 
 - 
isGreaterThanpublic static <T extends Comparable<T>> JwtClaimConstraint<T> isGreaterThan(Function<ValidatorConstraintContext,T> limitSupplier) Returns aJwtClaimConstraintthat will succeed if the value is greater than the given value, otherwise it will fail.- Type Parameters:
- T- The type of the compared value.
- Parameters:
- limitSupplier- A supplier of the limit to be greater than.
- Returns:
- a JwtClaimConstraintthat will succeed if the value is greater than the given value, otherwise it will fail.
 
 - 
isGreaterThanpublic static <T extends Comparable<T>> JwtClaimConstraint<T> isGreaterThan(T limit) A shorter version of isGreaterThan(constant(limit)).- Type Parameters:
- T- The type of the compared value.
- Parameters:
- limit- The limit to be greater than.
- Returns:
- a JwtClaimConstraintthat will succeed if the value is greater than the given value, otherwise it will fail.
 
 - 
isLessOrEqualTopublic static <T extends Comparable<T>> JwtClaimConstraint<T> isLessOrEqualTo(Function<ValidatorConstraintContext,T> limitSupplier) Returns aJwtClaimConstraintthat will succeed if the value is less than or equal to the given value, otherwise it will fail.- Type Parameters:
- T- The type of the compared value.
- Parameters:
- limitSupplier- A supplier of the limit to be less than or equal to.
- Returns:
- a JwtClaimConstraintthat will succeed if the value is less than or equal to the given value, otherwise it will fail.
 
 - 
isLessOrEqualTopublic static <T extends Comparable<T>> JwtClaimConstraint<T> isLessOrEqualTo(T limit) A shorter version of isLessOrEqualTo(constant(limit)).- Type Parameters:
- T- The type of the compared value.
- Parameters:
- limit- The limit to be less than or equal to.
- Returns:
- a JwtClaimConstraintthat will succeed if the value is less than or equal to the given value, otherwise it will fail.
 
 - 
isLessThanpublic static <T extends Comparable<T>> JwtClaimConstraint<T> isLessThan(Function<ValidatorConstraintContext,T> limitSupplier) Returns aJwtClaimConstraintthat will succeed if the value is less than the given value, otherwise it will fail.- Type Parameters:
- T- The type of the compared value.
- Parameters:
- limitSupplier- A supplier of the limit to be less than.
- Returns:
- a JwtClaimConstraintthat will succeed if the value is less than the given value, otherwise it will fail.
 
 - 
isLessThanpublic static <T extends Comparable<T>> JwtClaimConstraint<T> isLessThan(T limit) A shorter version of isLessThan(constant(limit)).- Type Parameters:
- T- The type of the compared value.
- Parameters:
- limit- The limit to be less than.
- Returns:
- a JwtClaimConstraintthat will succeed if the value is less than the given value, otherwise it will fail.
 
 - 
isNotNullpublic static JwtClaimConstraint<JsonValue> isNotNull() Returnsemptyif the value is present.- Returns:
- emptyif the value is present in the list or a- Violationcorresponding to this constraint.
 
 - 
matchespublic static JwtClaimConstraint<String> matches(Pattern pattern) Build and returns a new `Constraint` that checks if the claim's value is matched (as perMatcher.matches()) by the givenregex.The Constraint fails with a Violation otherwise. - Parameters:
- pattern- The regex pattern to match.
- Returns:
- a new Constraint for Pattern matching
- See Also:
- for the supported pattern format
 
 - 
hasClaimspublic static JwtConstraint hasClaims() Returnsemptyif the JWT does contain claims.- Returns:
- emptyif the JWT does contain claims or a- Violationcorresponding to this constraint.
 
 - 
hasValidSignaturepublic static JwtConstraint hasValidSignature(JwsSignatureVerifier verifier) Validates the signature of thisSignedJwt.- Parameters:
- verifier- The- JwsSignatureVerifierused to verify the signature.
- Returns:
- emptyif the JWT has a valid signature or a- Violationcorresponding to this constraint.
 
 - 
canBeDecryptedpublic static JwtConstraint canBeDecrypted(SecretsProvider secretsProvider, Purpose<DataDecryptionKey> purpose) Provides aJwtConstraintconfigured with the suppliedSecretsProviderthat contain a secret capable of decrypting and verifying a JWT's encryption. Fails if the supplied JWT is not encrypted or cannot be decrypted with the secrets available in theSecretsProvider.
 - 
hasValidSignatureAndEncryptionpublic static JwtConstraint hasValidSignatureAndEncryption(JwtConstraint signatureConstraint, JwtConstraint decryptionConstraint) Provides aJwtConstraintconfigured with the suppliedJwtConstraints verifying both signature and encryption. Fails if the supplied JWT is either :- Not encrypted and signed (both orders are accepted)
- Not decipherable
- Signed with an invalid signature
 - Parameters:
- signatureConstraint- the constraint on signature.
- decryptionConstraint- the constraint on decryption.
- Returns:
- the combined JwtConstraint.
 
 - 
equalsAttributeUsingKeypublic static <T> JwtClaimConstraint<T> equalsAttributeUsingKey() Returns aJwtClaimConstraintthat will succeed if the expected value is equal to the value looked up in the context attributes using the key, otherwise it will fail.- Type Parameters:
- T- The type of the value being checked.
- Returns:
- a JwtClaimConstraintthat will succeed if the expected value is equal to the value looked up in the context attributes using the key, otherwise it will fail.
 
 
- 
 
-