Merge pull request #3441 from stianst/KEYCLOAK-3733

KEYCLOAK-3733 Set default max results for paginated endpoints
This commit is contained in:
Stian Thorgersen 2016-10-28 10:36:24 +02:00 committed by GitHub
commit b6b567f948
8 changed files with 24 additions and 13 deletions

View file

@ -54,4 +54,6 @@ public interface Constants {
// Indication to admin-rest-endpoint that realm keys should be re-generated
String GENERATE = "GENERATE";
int DEFAULT_MAX_RESULTS = 100;
}

View file

@ -26,6 +26,7 @@ import org.keycloak.authorization.policy.provider.PolicyProviderAdminService;
import org.keycloak.authorization.policy.provider.PolicyProviderFactory;
import org.keycloak.authorization.store.PolicyStore;
import org.keycloak.authorization.store.StoreFactory;
import org.keycloak.models.Constants;
import org.keycloak.models.utils.ModelToRepresentation;
import org.keycloak.representations.idm.authorization.PolicyProviderRepresentation;
import org.keycloak.representations.idm.authorization.PolicyRepresentation;
@ -242,7 +243,7 @@ public class PolicyService {
}
return Response.ok(
storeFactory.getPolicyStore().findByResourceServer(search, resourceServer.getId(), firstResult != null ? firstResult : -1, maxResult != null ? maxResult : -1).stream()
storeFactory.getPolicyStore().findByResourceServer(search, resourceServer.getId(), firstResult != null ? firstResult : -1, maxResult != null ? maxResult : Constants.DEFAULT_MAX_RESULTS).stream()
.map(policy -> toRepresentation(policy, authorization))
.collect(Collectors.toList()))
.build();

View file

@ -27,6 +27,7 @@ import org.keycloak.authorization.store.PolicyStore;
import org.keycloak.authorization.store.ResourceStore;
import org.keycloak.authorization.store.StoreFactory;
import org.keycloak.models.ClientModel;
import org.keycloak.models.Constants;
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel;
import org.keycloak.representations.idm.authorization.ResourceRepresentation;
@ -233,7 +234,7 @@ public class ResourceSetService {
}
return Response.ok(
storeFactory.getResourceStore().findByResourceServer(search, this.resourceServer.getId(), firstResult != null ? firstResult : -1, maxResult != null ? maxResult : -1).stream()
storeFactory.getResourceStore().findByResourceServer(search, this.resourceServer.getId(), firstResult != null ? firstResult : -1, maxResult != null ? maxResult : Constants.DEFAULT_MAX_RESULTS).stream()
.map(resource -> toRepresentation(resource, this.resourceServer, authorization))
.collect(Collectors.toList()))
.build();

View file

@ -25,6 +25,7 @@ import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.model.Scope;
import org.keycloak.authorization.store.PolicyStore;
import org.keycloak.authorization.store.StoreFactory;
import org.keycloak.models.Constants;
import org.keycloak.representations.idm.authorization.ScopeRepresentation;
import org.keycloak.services.ErrorResponse;
import org.keycloak.services.resources.admin.RealmAuth;
@ -177,7 +178,7 @@ public class ScopeService {
}
return Response.ok(
this.authorization.getStoreFactory().getScopeStore().findByResourceServer(search, this.resourceServer.getId(), firstResult != null ? firstResult : -1, maxResult != null ? maxResult : -1).stream()
this.authorization.getStoreFactory().getScopeStore().findByResourceServer(search, this.resourceServer.getId(), firstResult != null ? firstResult : -1, maxResult != null ? maxResult : Constants.DEFAULT_MAX_RESULTS).stream()
.map(scope -> toRepresentation(scope, this.authorization))
.collect(Collectors.toList()))
.build();

View file

@ -27,6 +27,7 @@ import org.keycloak.events.admin.OperationType;
import org.keycloak.events.admin.ResourceType;
import org.keycloak.models.ClientModel;
import org.keycloak.models.ClientSessionModel;
import org.keycloak.models.Constants;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelDuplicateException;
import org.keycloak.models.RealmModel;
@ -403,7 +404,7 @@ public class ClientResource {
* Returns a list of user sessions associated with this client
*
* @param firstResult Paging offset
* @param maxResults Paging size
* @param maxResults Maximum results size (defaults to 100)
* @return
*/
@Path("user-sessions")
@ -418,7 +419,7 @@ public class ClientResource {
}
firstResult = firstResult != null ? firstResult : -1;
maxResults = maxResults != null ? maxResults : -1;
maxResults = maxResults != null ? maxResults : Constants.DEFAULT_MAX_RESULTS;
List<UserSessionRepresentation> sessions = new ArrayList<UserSessionRepresentation>();
for (UserSessionModel userSession : session.sessions().getUserSessions(client.getRealm(), client, firstResult, maxResults)) {
UserSessionRepresentation rep = ModelToRepresentation.toRepresentation(userSession);
@ -460,7 +461,7 @@ public class ClientResource {
* Returns a list of offline user sessions associated with this client
*
* @param firstResult Paging offset
* @param maxResults Paging size
* @param maxResults Maximum results size (defaults to 100)
* @return
*/
@Path("offline-sessions")
@ -475,7 +476,7 @@ public class ClientResource {
}
firstResult = firstResult != null ? firstResult : -1;
maxResults = maxResults != null ? maxResults : -1;
maxResults = maxResults != null ? maxResults : Constants.DEFAULT_MAX_RESULTS;
List<UserSessionRepresentation> sessions = new ArrayList<UserSessionRepresentation>();
List<UserSessionModel> userSessions = session.sessions().getOfflineUserSessions(client.getRealm(), client, firstResult, maxResults);
for (UserSessionModel userSession : userSessions) {

View file

@ -21,6 +21,7 @@ import org.jboss.resteasy.spi.NotFoundException;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.keycloak.events.admin.OperationType;
import org.keycloak.events.admin.ResourceType;
import org.keycloak.models.Constants;
import org.keycloak.models.GroupModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
@ -196,7 +197,7 @@ public class GroupResource {
* Returns a list of users, filtered according to query parameters
*
* @param firstResult Pagination offset
* @param maxResults Pagination size
* @param maxResults Maximum results size (defaults to 100)
* @return
*/
@GET
@ -212,7 +213,7 @@ public class GroupResource {
}
firstResult = firstResult != null ? firstResult : -1;
maxResults = maxResults != null ? maxResults : -1;
maxResults = maxResults != null ? maxResults : Constants.DEFAULT_MAX_RESULTS;
List<UserRepresentation> results = new ArrayList<UserRepresentation>();
List<UserModel> userModels = session.users().getGroupMembers(realm, group, firstResult, maxResults);

View file

@ -517,7 +517,7 @@ public class RealmAdminResource {
* @param dateTo To date
* @param dateFrom From date
* @param firstResult Paging offset
* @param maxResults Paging size
* @param maxResults Maximum results size (defaults to 100)
* @return
*/
@Path("events")
@ -579,6 +579,8 @@ public class RealmAdminResource {
}
if (maxResults != null) {
query.maxResults(maxResults);
} else {
query.maxResults(Constants.DEFAULT_MAX_RESULTS);
}
return toEventListRep(query.getResultList());
@ -606,7 +608,7 @@ public class RealmAdminResource {
* @param dateTo
* @param dateFrom
* @param firstResult
* @param maxResults
* @param maxResults Maximum results size (defaults to 100)
* @return
*/
@Path("admin-events")
@ -689,6 +691,8 @@ public class RealmAdminResource {
}
if (maxResults != null) {
query.maxResults(maxResults);
} else {
query.maxResults(Constants.DEFAULT_MAX_RESULTS);
}
return toAdminEventRep(query.getResultList());

View file

@ -650,7 +650,7 @@ public class UsersResource {
* @param email
* @param username
* @param first Pagination offset
* @param maxResults Pagination size
* @param maxResults Maximum results size (defaults to 100)
* @return
*/
@GET
@ -666,7 +666,7 @@ public class UsersResource {
auth.requireView();
firstResult = firstResult != null ? firstResult : -1;
maxResults = maxResults != null ? maxResults : -1;
maxResults = maxResults != null ? maxResults : Constants.DEFAULT_MAX_RESULTS;
List<UserRepresentation> results = new ArrayList<UserRepresentation>();
List<UserModel> userModels;