Class ClaimValidationUtils

java.lang.Object
org.apache.kafka.common.security.oauthbearer.secured.ClaimValidationUtils

public class ClaimValidationUtils extends Object
Simple utility class to perform basic cleaning and validation on input values so that they're performed consistently throughout the code base.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Validates that the given claim name override is valid, where invalid means any of the following: null Zero length Whitespace only
    static long
    validateExpiration(String claimName, Long claimValue)
    Validates that the given lifetime is valid, where invalid means any of the following: null Negative
    static Long
    validateIssuedAt(String claimName, Long claimValue)
    Validates that the given issued at claim name is valid, where invalid means any of the following: Negative
    static Set<String>
    validateScopes(String scopeClaimName, Collection<String> scopes)
    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
    static 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 values
      scopes - 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 is null, contains duplicates, or if any of the values in the set are null, empty, or whitespace only
    • validateExpiration

      public static long validateExpiration(String claimName, Long claimValue) throws ValidateException
      Validates that the given lifetime is valid, where invalid means any of the following:
      • null
      • Negative
      Parameters:
      claimName - Name of the claim
      claimValue - Expiration time (in milliseconds)
      Returns:
      Input parameter, as provided
      Throws:
      ValidateException - Thrown if the value is null or negative
    • validateSubject

      public static String validateSubject(String claimName, String claimValue) throws ValidateException
      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 claim
      claimValue - Name of the subject
      Returns:
      Trimmed version of the claimValue parameter
      Throws:
      ValidateException - Thrown if the value is null, empty, or whitespace only
    • validateIssuedAt

      public static Long validateIssuedAt(String claimName, Long claimValue) throws ValidateException
      Validates that the given issued at claim name is valid, where invalid means any of the following:
      • Negative
      Parameters:
      claimName - Name of the claim
      claimValue - Start time (in milliseconds) or null if not used
      Returns:
      Input parameter, as provided
      Throws:
      ValidateException - Thrown if the value is negative
    • validateClaimNameOverride

      public static String validateClaimNameOverride(String name, String value) throws ValidateException
      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 is null, empty, or whitespace only