From b1ba28e64e2205f20212e925e9911708ddfac7ee Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Wed, 11 Dec 2024 11:48:57 -0300 Subject: [PATCH] Exact searches should be the default when querying user by attributes Closes #35822 Signed-off-by: Pedro Igor --- .../main/java/org/keycloak/models/jpa/JpaUserProvider.java | 2 +- .../test/java/org/keycloak/testsuite/admin/UserTest.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java index 4e1691885fd4..5a2370edd30e 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java @@ -1012,7 +1012,7 @@ private List predicates(Map attributes, Root users = realm.users().searchByAttributes(mapToSearchQuery(Map.of("username", "user", "test", "test1", "attr", "common", "test1", "test1"))); assertThat(users, hasSize(1)); - //custom user attribute should use wildcard search by default + //custom user attribute should not use wildcard search by default users = realm.users().searchByAttributes(mapToSearchQuery(Map.of("username", "user", "test", "est", "attr", "mm", "test1", "test1"))); + assertThat(users, hasSize(0)); + + //custom user attribute should use wildcard + users = realm.users().searchByAttributes(mapToSearchQuery(Map.of("username", "user", "test", "est", "attr", "mm", "test1", "test1")), false); assertThat(users, hasSize(1)); //with exact=true the user shouldn't be returned