/users/count endpoint with search field has different behavior than /users query endpoint #17620
closes #17620
This commit is contained in:
parent
24ecfcb5aa
commit
bd0a23a865
2 changed files with 21 additions and 3 deletions
|
@ -619,7 +619,10 @@ public class JpaUserProvider implements UserProvider, UserCredentialStore {
|
|||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
||||
predicates.add(builder.equal(root.get("realmId"), realm.getId()));
|
||||
predicates.add(builder.or(getSearchOptionPredicateArray(search, builder, root)));
|
||||
|
||||
for (String stringToSearch : search.trim().split("\\s+")) {
|
||||
predicates.add(builder.or(getSearchOptionPredicateArray(stringToSearch, builder, root)));
|
||||
}
|
||||
|
||||
queryBuilder.where(predicates.toArray(new Predicate[0]));
|
||||
|
||||
|
@ -643,7 +646,11 @@ public class JpaUserProvider implements UserProvider, UserCredentialStore {
|
|||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
||||
predicates.add(builder.equal(userJoin.get("realmId"), realm.getId()));
|
||||
predicates.add(builder.or(getSearchOptionPredicateArray(search, builder, userJoin)));
|
||||
|
||||
for (String stringToSearch : search.trim().split("\\s+")) {
|
||||
predicates.add(builder.or(getSearchOptionPredicateArray(stringToSearch, builder, userJoin)));
|
||||
}
|
||||
|
||||
predicates.add(groupMembership.get("groupId").in(groupIds));
|
||||
|
||||
queryBuilder.where(predicates.toArray(new Predicate[0]));
|
||||
|
|
|
@ -75,6 +75,17 @@ public class UsersTest extends AbstractAdminTest {
|
|||
assertCaseInsensitiveSearch();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchUserMatchUsersCount() {
|
||||
createUser(REALM_NAME, "john.doe", "password", "John", "Doe Smith", "john.doe@keycloak.org");
|
||||
String search = "jo do";
|
||||
|
||||
assertThat(adminClient.realm(REALM_NAME).users().count(search), is(1));
|
||||
List<UserRepresentation> users = adminClient.realm(REALM_NAME).users().search(search, null, null);
|
||||
assertThat(users, hasSize(1));
|
||||
assertThat(users.get(0).getUsername(), is("john.doe"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchUserCaseSensitiveFirst() throws Exception {
|
||||
Assume.assumeFalse(isJpaRealmProvider());
|
||||
|
|
Loading…
Reference in a new issue