From f933ffba3fe9d3283ca4b4b8582f35c23314fa21 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Tue, 26 Nov 2013 13:53:57 +0000 Subject: [PATCH] User search returned users for all realms --- .../src/main/java/org/keycloak/models/jpa/RealmAdapter.java | 3 ++- services/src/test/java/org/keycloak/test/AdapterTest.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) 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);