loading all users in batches
@@ -535,12 +535,20 @@ public class TenantManagementKeycloakImpl implements TenantManagementInterface {
try{
client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), tenantId, realmAdminCreds);
// FIXME: this only searches through the most recent 100 users for the given role (assuming there are no more than 10,000 users in the gateway)
- logger.debug("getUsersWithRole: fetching all users...");
- List<UserRepresentation> allUsers = client.realm(tenantId).users().search(null,
+ int totalUserCount = client.realm(tenantId).users().count();
+ logger.debug("getUsersWithRole: totalUserCount=" + totalUserCount);
+ // Load all users in batches
+ List<UserRepresentation> allUsers = new ArrayList<>();
+ int userBatchSize = 100;
+ for (int start = 0; start < totalUserCount; start=start+userBatchSize) {
+
+ logger.debug("getUsersWithRole: fetching " + userBatchSize + " users...");
+ allUsers.addAll(client.realm(tenantId).users().search(null,
null,
null,
null,
- 0, 100);
+ start, userBatchSize));
+ }
logger.debug("getUsersWithRole: all users count=" + allUsers.size());
allUsers.sort((a, b) -> a.getCreatedTimestamp() - b.getCreatedTimestamp() > 0 ? -1 : 1);
// The 100 most recently created users
