Skip to content

Commit

Permalink
Exact searches should be the default when querying user by attributes
Browse files Browse the repository at this point in the history
Closes keycloak#35822

Signed-off-by: Pedro Igor <[email protected]>
  • Loading branch information
pedroigor committed Dec 12, 2024
1 parent 5061ca4 commit b1ba28e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ private List<Predicate> predicates(Map<String, String> attributes, Root<UserEnti
builder.equal(attributesJoin.get("name"), key),
builder.equal(attributesJoin.get("longValueHashLowerCase"), JpaHashUtils.hashForAttributeValueLowerCase(value))));
} else {
if (Boolean.parseBoolean(attributes.get(UserModel.EXACT))) {
if (Boolean.parseBoolean(attributes.getOrDefault(UserModel.EXACT, Boolean.TRUE.toString()))) {
attributePredicates.add(builder.and(
builder.equal(attributesJoin.get("name"), key),
builder.equal(builder.lower(attributesJoin.get("value")), value.toLowerCase())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,12 @@ public void searchByMultipleAttributes() {
List<UserRepresentation> 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
Expand Down

0 comments on commit b1ba28e

Please sign in to comment.