diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/users.js b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/users.js
index de73f6333a..f2c6b7c1fc 100755
--- a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/users.js
+++ b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/users.js
@@ -120,15 +120,16 @@ module.controller('UserListCtrl', function($scope, realm, User) {
$scope.realm = realm;
$scope.searchQuery = function() {
$scope.searchLoaded = false;
+ $scope.currentSearch = $scope.search;
+
+ var params = { realm: realm.id };
if ($scope.search) {
- $scope.currentSearch = $scope.search;
- $scope.users = User.query({ realm: realm.id, search : $scope.search }, function() {
- $scope.searchLoaded = true;
- });
- } else {
- $scope.currentSearch = null;
- $scope.users = null;
+ params.search = $scope.search;
}
+
+ $scope.users = User.query(params, function() {
+ $scope.searchLoaded = true;
+ });
};
});
diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-list.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-list.html
index 16a16972e1..a3b193671a 100755
--- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-list.html
+++ b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-list.html
@@ -21,7 +21,7 @@
-
|
-
+
{{app.name}} |
{{app.enabled}} |
{{app.baseUrl || "Not defined"}} |
diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/user-list.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/user-list.html
index c79b243125..96cee2177c 100755
--- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/user-list.html
+++ b/admin-ui/src/main/resources/META-INF/resources/admin/partials/user-list.html
@@ -14,7 +14,7 @@
{{realm.realm}} Users
- Table of realm users
+ Table of realm users
@@ -28,6 +28,7 @@
|
@@ -66,7 +67,7 @@
Your search returned no results.
Try modifying the query and try again.
-
+
Search for users.
Please enter a search to display users.
diff --git a/model/api/src/main/java/org/keycloak/models/RealmModel.java b/model/api/src/main/java/org/keycloak/models/RealmModel.java
index a4527ae1aa..ce76dcb45a 100755
--- a/model/api/src/main/java/org/keycloak/models/RealmModel.java
+++ b/model/api/src/main/java/org/keycloak/models/RealmModel.java
@@ -137,6 +137,8 @@ public interface RealmModel extends RoleContainerModel, RoleMapperModel, ScopeMa
public void setAutomaticRegistrationAfterSocialLogin(boolean automaticRegistrationAfterSocialLogin);
+ List
getUsers();
+
List searchForUser(String search);
List searchForUserByAttributes(Map attributes);
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 6e6c8f1186..201f286dca 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
@@ -670,9 +670,19 @@ public class RealmAdapter implements RealmModel {
em.flush();
}
+ @Override
+ public List getUsers() {
+ TypedQuery query = em.createQuery("select u from UserEntity u where u.realm = :realm", UserEntity.class);
+ query.setParameter("realm", realm);
+ List results = query.getResultList();
+ List users = new ArrayList();
+ for (UserEntity entity : results) users.add(new UserAdapter(entity));
+ return users;
+ }
+
@Override
public List searchForUser(String search) {
- 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);
+ 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();
diff --git a/model/picketlink/src/main/java/org/keycloak/models/picketlink/RealmAdapter.java b/model/picketlink/src/main/java/org/keycloak/models/picketlink/RealmAdapter.java
index 798643e815..fb2dca68f1 100755
--- a/model/picketlink/src/main/java/org/keycloak/models/picketlink/RealmAdapter.java
+++ b/model/picketlink/src/main/java/org/keycloak/models/picketlink/RealmAdapter.java
@@ -914,23 +914,28 @@ public class RealmAdapter implements RealmModel {
getRelationshipManager().remove(relationship);
}
+ @Override
+ public List getUsers() {
+ List userModels = new ArrayList();
+ IdentityQuery query = getIdm().createIdentityQuery(User.class);
+ for (User u : query.getResultList()) {
+ userModels.add(new UserAdapter(u, idm));
+ }
+ return userModels;
+ }
+
@Override
public List searchForUser(String search) {
QueryParameter[] params = new QueryParameter[] { User.LOGIN_NAME, User.FIRST_NAME, User.LAST_NAME, User.EMAIL };
- Map users = new HashMap();
+ List userModels = new ArrayList();
for (QueryParameter p : params) {
IdentityQuery query = getIdm().createIdentityQuery(User.class);
query.setParameter(p, search.toLowerCase());
for (User u : query.getResultList()) {
- users.put(u.getLoginName(), u);
+ userModels.add(new UserAdapter(u, idm));
}
}
-
- List userModels = new ArrayList();
- for (User user : users.values()) {
- userModels.add(new UserAdapter(user, idm));
- }
return userModels;
}
diff --git a/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java b/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java
index 61e70bf682..e8e34c76e1 100755
--- a/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java
+++ b/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java
@@ -135,14 +135,10 @@ public class UsersResource {
@QueryParam("username") String username) {
RealmManager manager = new RealmManager(session);
List results = new ArrayList();
+ List userModels;
if (search != null) {
- List userModels = manager.searchUsers(search, realm);
- for (UserModel user : userModels) {
- if (isUser(user)) {
- results.add(manager.toRepresentation(user));
- }
- }
- } else {
+ userModels = manager.searchUsers(search, realm);
+ } else if (last != null || first != null || email != null || username != null) {
Map attributes = new HashMap();
if (last != null) {
attributes.put(UserModel.LAST_NAME, last);
@@ -156,11 +152,18 @@ public class UsersResource {
if (username != null) {
attributes.put(UserModel.LOGIN_NAME, username);
}
- List userModels = realm.searchForUserByAttributes(attributes);
+ userModels = realm.searchForUserByAttributes(attributes);
for (UserModel user : userModels) {
results.add(manager.toRepresentation(user));
}
+ } else {
+ userModels = realm.getUsers();
+ }
+ for (UserModel user : userModels) {
+ if (isUser(user)) {
+ results.add(manager.toRepresentation(user));
+ }
}
return results;
}
diff --git a/services/src/test/java/org/keycloak/test/AdapterTest.java b/services/src/test/java/org/keycloak/test/AdapterTest.java
index a600f6f67e..0bcfbc5bdb 100755
--- a/services/src/test/java/org/keycloak/test/AdapterTest.java
+++ b/services/src/test/java/org/keycloak/test/AdapterTest.java
@@ -303,7 +303,6 @@ public class AdapterTest extends AbstractKeycloakTest {
}
RealmManager adapter = getRealmManager();
- adapter.createRealm("other").addUser("bburke");
{
List 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());
}