KEYCLOAK-214 view all users in a realm through admin console
This commit is contained in:
parent
36a20d15e1
commit
a423c38e42
6 changed files with 44 additions and 24 deletions
|
@ -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;
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
</ol>
|
||||
<h2><span>{{realm.realm}}</span> Users</h2>
|
||||
<table>
|
||||
<caption data-ng-show="users && search" class="hidden">Table of realm users</caption>
|
||||
<caption data-ng-show="users" class="hidden">Table of realm users</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="rcue-table-actions" colspan="4">
|
||||
|
@ -66,7 +66,7 @@
|
|||
<div class="feedback warning inline" data-ng-show="searchLoaded && users.length == 0">
|
||||
<p><strong>Your search returned no results.</strong><br>Try modifying the query and try again.</p>
|
||||
</div>
|
||||
<div class="feedback info inline" data-ng-show="!currentSearch">
|
||||
<div class="feedback info inline" data-ng-show="!users">
|
||||
<br/>
|
||||
<p><strong>Search for users.</strong><br>Please enter a search to display users.</p>
|
||||
</div>
|
||||
|
|
|
@ -137,6 +137,8 @@ public interface RealmModel extends RoleContainerModel, RoleMapperModel, ScopeMa
|
|||
|
||||
public void setAutomaticRegistrationAfterSocialLogin(boolean automaticRegistrationAfterSocialLogin);
|
||||
|
||||
List<UserModel> getUsers();
|
||||
|
||||
List<UserModel> searchForUser(String search);
|
||||
|
||||
List<UserModel> searchForUserByAttributes(Map<String, String> attributes);
|
||||
|
|
|
@ -670,6 +670,15 @@ public class RealmAdapter implements RealmModel {
|
|||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserModel> getUsers() {
|
||||
TypedQuery<UserEntity> query = em.createQuery("select u from UserEntity u", UserEntity.class);
|
||||
List<UserEntity> results = query.getResultList();
|
||||
List<UserModel> users = new ArrayList<UserModel>();
|
||||
for (UserEntity entity : results) users.add(new UserAdapter(entity));
|
||||
return users;
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
|
|
|
@ -914,23 +914,28 @@ public class RealmAdapter implements RealmModel {
|
|||
getRelationshipManager().remove(relationship);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserModel> getUsers() {
|
||||
List<UserModel> userModels = new ArrayList<UserModel>();
|
||||
IdentityQuery<User> query = getIdm().createIdentityQuery(User.class);
|
||||
for (User u : query.getResultList()) {
|
||||
userModels.add(new UserAdapter(u, idm));
|
||||
}
|
||||
return userModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserModel> searchForUser(String search) {
|
||||
QueryParameter[] params = new QueryParameter[] { User.LOGIN_NAME, User.FIRST_NAME, User.LAST_NAME, User.EMAIL };
|
||||
|
||||
Map<String, User> users = new HashMap<String, User>();
|
||||
List<UserModel> userModels = new ArrayList<UserModel>();
|
||||
for (QueryParameter p : params) {
|
||||
IdentityQuery<User> 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<UserModel> userModels = new ArrayList<UserModel>();
|
||||
for (User user : users.values()) {
|
||||
userModels.add(new UserAdapter(user, idm));
|
||||
}
|
||||
return userModels;
|
||||
}
|
||||
|
||||
|
|
|
@ -135,14 +135,10 @@ public class UsersResource {
|
|||
@QueryParam("username") String username) {
|
||||
RealmManager manager = new RealmManager(session);
|
||||
List<UserRepresentation> results = new ArrayList<UserRepresentation>();
|
||||
List<UserModel> userModels;
|
||||
if (search != null) {
|
||||
List<UserModel> 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<String, String> attributes = new HashMap<String, String>();
|
||||
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<UserModel> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue