Class ClaimValidationUtils
java.lang.Object
org.apache.kafka.common.security.oauthbearer.secured.ClaimValidationUtils
Simple utility class to perform basic cleaning and validation on input values so that they're
performed consistently throughout the code base.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
validateClaimNameOverride
(String name, String value) Validates that the given claim name override is valid, where invalid means any of the following:null
Zero length Whitespace onlystatic long
validateExpiration
(String claimName, Long claimValue) Validates that the given lifetime is valid, where invalid means any of the following:null
Negativestatic Long
validateIssuedAt
(String claimName, Long claimValue) Validates that the given issued at claim name is valid, where invalid means any of the following: NegativevalidateScopes
(String scopeClaimName, Collection<String> scopes) Validates that the scopes are valid, where invalid means any of the following: Collection isnull
Collection has duplicates Any of the elements in the collection arenull
Any of the elements in the collection are zero length Any of the elements in the collection are whitespace onlystatic String
validateSubject
(String claimName, String claimValue) Validates that the given claim value is valid, where invalid means any of the following:null
Zero length Whitespace only
-
Constructor Details
-
ClaimValidationUtils
public ClaimValidationUtils()
-
-
Method Details
-
validateScopes
public static Set<String> validateScopes(String scopeClaimName, Collection<String> scopes) throws ValidateException Validates that the scopes are valid, where invalid means any of the following:- Collection is
null
- Collection has duplicates
- Any of the elements in the collection are
null
- Any of the elements in the collection are zero length
- Any of the elements in the collection are whitespace only
- Parameters:
scopeClaimName
- Name of the claim used for the scope valuesscopes
- Collection of String scopes- Returns:
- Unmodifiable
Set
that includes the values of the original set, but with each value trimmed - Throws:
ValidateException
- Thrown if the value isnull
, contains duplicates, or if any of the values in the set arenull
, empty, or whitespace only
- Collection is
-
validateExpiration
Validates that the given lifetime is valid, where invalid means any of the following:null
- Negative
- Parameters:
claimName
- Name of the claimclaimValue
- Expiration time (in milliseconds)- Returns:
- Input parameter, as provided
- Throws:
ValidateException
- Thrown if the value isnull
or negative
-
validateSubject
Validates that the given claim value is valid, where invalid means any of the following:null
- Zero length
- Whitespace only
- Parameters:
claimName
- Name of the claimclaimValue
- Name of the subject- Returns:
- Trimmed version of the
claimValue
parameter - Throws:
ValidateException
- Thrown if the value isnull
, empty, or whitespace only
-
validateIssuedAt
Validates that the given issued at claim name is valid, where invalid means any of the following:- Negative
- Parameters:
claimName
- Name of the claimclaimValue
- Start time (in milliseconds) ornull
if not used- Returns:
- Input parameter, as provided
- Throws:
ValidateException
- Thrown if the value is negative
-
validateClaimNameOverride
Validates that the given claim name override is valid, where invalid means any of the following:null
- Zero length
- Whitespace only
- Parameters:
name
- "Standard" name of the claim, e.g.sub
value
- "Override" name of the claim, e.g.email
- Returns:
- Trimmed version of the
value
parameter - Throws:
ValidateException
- Thrown if the value isnull
, empty, or whitespace only
-