KEYCLOAK-197 Fix search for users returns users for all realms

This commit is contained in:
Stian Thorgersen 2013-12-06 19:22:55 +00:00
parent a423c38e42
commit c514e6c152
3 changed files with 8 additions and 4 deletions

View file

@ -28,6 +28,7 @@
</button> </button>
</div> </div>
<div class="actions"> <div class="actions">
<button ng-click="search = null; searchQuery()">View all</button>
<a class="button" href="#/create/user/{{realm.id}}">Add User</a> <a class="button" href="#/create/user/{{realm.id}}">Add User</a>
</div> </div>
</th> </th>

View file

@ -672,7 +672,8 @@ public class RealmAdapter implements RealmModel {
@Override @Override
public List<UserModel> getUsers() { public List<UserModel> getUsers() {
TypedQuery<UserEntity> query = em.createQuery("select u from UserEntity u", UserEntity.class); TypedQuery<UserEntity> query = em.createQuery("select u from UserEntity u where u.realm = :realm", UserEntity.class);
query.setParameter("realm", realm);
List<UserEntity> results = query.getResultList(); List<UserEntity> results = query.getResultList();
List<UserModel> users = new ArrayList<UserModel>(); List<UserModel> users = new ArrayList<UserModel>();
for (UserEntity entity : results) users.add(new UserAdapter(entity)); for (UserEntity entity : results) users.add(new UserAdapter(entity));
@ -681,7 +682,7 @@ public class RealmAdapter implements RealmModel {
@Override @Override
public List<UserModel> searchForUser(String search) { public List<UserModel> searchForUser(String search) {
TypedQuery<UserEntity> 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); TypedQuery<UserEntity> 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("realm", realm);
query.setParameter("search", "%" + search.toLowerCase() + "%"); query.setParameter("search", "%" + search.toLowerCase() + "%");
List<UserEntity> results = query.getResultList(); List<UserEntity> results = query.getResultList();

View file

@ -303,7 +303,6 @@ public class AdapterTest extends AbstractKeycloakTest {
} }
RealmManager adapter = getRealmManager(); RealmManager adapter = getRealmManager();
adapter.createRealm("other").addUser("bburke");
{ {
List<UserModel> userModels = adapter.searchUsers("total junk query", realmModel); List<UserModel> userModels = adapter.searchUsers("total junk query", realmModel);
@ -438,8 +437,11 @@ public class AdapterTest extends AbstractKeycloakTest {
} }
} }
RealmModel otherRealm = adapter.createRealm("other");
otherRealm.addUser("bburke");
Assert.assertEquals(1, otherRealm.getUsers().size());
Assert.assertEquals(1, otherRealm.searchForUser("u").size());
} }