Class JpaHashUtils

java.lang.Object
org.keycloak.storage.jpa.JpaHashUtils

public class JpaHashUtils extends Object
Create hashes for long values stored in the database. Offers different variants for exact and lowercase search. Keycloak uses lowercase search to approximate a case-insensitive search.

The lowercase function always uses the English locale to avoid changing hashes due to changing locales which can be surprising and would be expensive to fix as all hashes would need to be re-calculated.

Author:
Alexander Schwartz
  • Constructor Details

    • JpaHashUtils

      public JpaHashUtils()
  • Method Details

    • hashForAttributeValue

      public static byte[] hashForAttributeValue(String value)
    • hashForAttributeValueLowerCase

      public static byte[] hashForAttributeValueLowerCase(String value)
    • compareSourceValueLowerCase

      public static boolean compareSourceValueLowerCase(String value1, String value2)
    • compareSourceValue

      public static boolean compareSourceValue(String value1, String value2)
    • predicateForFilteringUsersByAttributes

      public static Predicate<UserEntity> predicateForFilteringUsersByAttributes(Map<String,String> customLongValueSearchAttributes, BiPredicate<String,String> valueComparator)
      This method returns a predicate that returns true when user has all attributes specified in customLongValueSearchAttributes map

      The check is performed by exact comparison on attribute name the value

      This is necessary because database can return users without the searched attribute when a hash collision on long user attribute value occurs

      Parameters:
      customLongValueSearchAttributes - required attributes
      valueComparator - comparator for comparing attribute values
      Returns:
      predicate for filtering users based on attributes map