Exact searches should be the default when querying user by attributes (#35869)

Closes #35822

Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
This commit is contained in:
Pedro Igor 2024-12-13 04:45:38 -03:00 committed by GitHub
parent 5061ca4a99
commit 125f66e7d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -1012,7 +1012,7 @@ public class JpaUserProvider implements UserProvider, UserCredentialStore {
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())));

View File

@ -916,8 +916,12 @@ public class UserTest extends AbstractAdminTest {
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