diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java index 7f98fd0fdb..96e539a460 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java @@ -666,7 +666,8 @@ public class RealmAdapter implements RealmModel { @Override public List searchForUser(String search) { - TypedQuery query = em.createQuery("select u from UserEntity u where lower(u.loginName) like :search or lower(concat(u.firstName, ' ', u.lastName)) like :search or u.email like :search", UserEntity.class); + TypedQuery query = em.createQuery("select u from UserEntity u where u.realm = :realm and lower(u.loginName) like :search or lower(concat(u.firstName, ' ', u.lastName)) like :search or u.email like :search", UserEntity.class); + query.setParameter("realm", realm); query.setParameter("search", "%" + search.toLowerCase() + "%"); List results = query.getResultList(); List users = new ArrayList(); diff --git a/services/src/test/java/org/keycloak/test/AdapterTest.java b/services/src/test/java/org/keycloak/test/AdapterTest.java index c0c13824d5..a600f6f67e 100755 --- a/services/src/test/java/org/keycloak/test/AdapterTest.java +++ b/services/src/test/java/org/keycloak/test/AdapterTest.java @@ -303,6 +303,7 @@ public class AdapterTest extends AbstractKeycloakTest { } RealmManager adapter = getRealmManager(); + adapter.createRealm("other").addUser("bburke"); { List userModels = adapter.searchUsers("total junk query", realmModel);