KEYCLOAK-435 Added pagination support for users

This commit is contained in:
Stian Thorgersen committed 2014-07-16 17:54:11 +01:00
1 parent 1a5c2365a1
commit 72d240a57e
13 files changed
+163 -48

No files matched your search

@@ -343,8 +343,8 @@ public class ApplicationResource {
@Produces(MediaType.APPLICATION_JSON)
public List<UserSessionRepresentation> getUserSessions(@QueryParam("first") Integer firstResult, @QueryParam("max") Integer maxResults) {
auth.requireView();
firstResult = firstResult != null ? firstResult : 0;
maxResults = maxResults != null ? maxResults : Integer.MAX_VALUE;
firstResult = firstResult != null ? firstResult : -1;
maxResults = maxResults != null ? maxResults : -1;
List<UserSessionRepresentation> sessions = new ArrayList<UserSessionRepresentation>();
for (UserSessionModel userSession : session.sessions().getUserSessions(application.getRealm(), application, firstResult, maxResults)) {
UserSessionRepresentation rep = ModelToRepresentation.toRepresentation(userSession);
@@ -317,14 +317,18 @@ public class UsersResource {
@QueryParam("lastName") String last,
@QueryParam("firstName") String first,
@QueryParam("email") String email,
@QueryParam("username") String username) {
@QueryParam("username") String username,
@QueryParam("first") Integer firstResult,
@QueryParam("max") Integer maxResults) {
auth.requireView();
RealmManager manager = new RealmManager(session);
firstResult = firstResult != null ? firstResult : -1;
maxResults = maxResults != null ? maxResults : -1;
List<UserRepresentation> results = new ArrayList<UserRepresentation>();
List<UserModel> userModels;
if (search != null) {
userModels = manager.searchUsers(search, realm);
userModels = session.users().searchForUser(search.trim(), realm, firstResult, maxResults);
} else if (last != null || first != null || email != null || username != null) {
Map<String, String> attributes = new HashMap<String, String>();
if (last != null) {
@@ -339,12 +343,12 @@ public class UsersResource {
if (username != null) {
attributes.put(UserModel.LOGIN_NAME, username);
}
userModels = session.users().searchForUserByAttributes(attributes, realm);
userModels = session.users().searchForUserByAttributes(attributes, realm, firstResult, maxResults);
for (UserModel user : userModels) {
results.add(ModelToRepresentation.toRepresentation(user));
}
} else {
userModels = session.users().getUsers(realm);
userModels = session.users().getUsers(realm, firstResult, maxResults);
}
for (UserModel user : userModels) {