mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-09 15:02:05 -03:30
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:
parent
5061ca4a99
commit
125f66e7d0
@ -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())));
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user