Skip to content

Commit 7a8505f

Browse files
committed
Limit number of group memberships to be managed with "add" step to 10
In fact the limit seems to be 20 but documented is 10, so better be conservative here. Compare with https://adobe-apiplatform.github.io/umapi-documentation/en/api/ActionsCmds.html This closes #753
1 parent 0b7577f commit 7a8505f

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/ims/IMSUserManagement.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public class IMSUserManagement implements ExternalGroupManagement {
116116

117117
public static final Logger LOG = LoggerFactory.getLogger(IMSUserManagement.class);
118118
private static final int MAX_NUM_COMMANDS_PER_REQUEST = 10;
119+
private static final int MAX_NUM_GROUPS_PER_ADD_STEP = 10;
119120

120121
private final Configuration config;
121122
private final CloseableHttpClient client;
@@ -218,15 +219,20 @@ public void updateGroups(Collection<AuthorizableConfigBean> groupConfigs) throws
218219
}
219220
// optionally make users group administrators
220221
if (config.groupAdmins() != null && config.groupAdmins().length > 0) {
221-
Set<String> adminGroupNames = groupConfigs.stream()
222+
// at most 10 groups per add command
223+
AtomicInteger groupCounter = new AtomicInteger();
224+
Collection<List<String>> adminGroupNameBatches = groupConfigs.stream()
222225
.map(AuthorizableConfigBean::getAuthorizableId)
223226
.map(id -> "_admin_" + id) // https://adobe-apiplatform.github.io/umapi-documentation/en/api/ActionsCmds.html#addRemoveAttr
224-
.collect(Collectors.toSet());
225-
for (String groupAdmin : config.groupAdmins()) {
226-
ActionCommand actionCommand = new UserActionCommand(groupAdmin);
227-
AddGroupMembership addGroupMembership = new AddGroupMembership(adminGroupNames);
228-
actionCommand.addStep(addGroupMembership);
229-
actionCommands.add(actionCommand);
227+
.collect(Collectors.groupingBy
228+
(it->groupCounter.getAndIncrement() / MAX_NUM_GROUPS_PER_ADD_STEP)).values();
229+
for (List<String> adminGroupNames : adminGroupNameBatches) {
230+
for (String groupAdmin : config.groupAdmins()) {
231+
ActionCommand actionCommand = new UserActionCommand(groupAdmin);
232+
AddGroupMembership addGroupMembership = new AddGroupMembership(adminGroupNames);
233+
actionCommand.addStep(addGroupMembership);
234+
actionCommands.add(actionCommand);
235+
}
230236
}
231237
}
232238
// update in batches of 10 commands

accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/ims/IMSUserManagementIT.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.io.IOException;
2121
import java.util.Collections;
2222
import java.util.HashMap;
23+
import java.util.LinkedList;
24+
import java.util.List;
2325
import java.util.Map;
2426

2527
import org.apache.http.impl.client.HttpClientBuilder;
@@ -132,6 +134,26 @@ public HttpClientBuilder newBuilder() {
132134
imsUserManagement.updateGroups(Collections.singleton(group));
133135
}
134136

137+
@Test
138+
void test25GroupsWithAdmin() throws IOException {
139+
properties.put("groupAdmins", getMandatoryEnvironmentVariable("ACTOOL_IMS_IT_USERID"));
140+
Configuration config = Converters.standardConverter().convert(properties).to(Configuration.class);
141+
IMSUserManagement imsUserManagement = new IMSUserManagement(config, new HttpClientBuilderFactory() {
142+
@Override
143+
public HttpClientBuilder newBuilder() {
144+
return HttpClientBuilder.create();
145+
}
146+
});
147+
List<AuthorizableConfigBean> groups = new LinkedList<>();
148+
for (int n=0; n<25; n++) {
149+
AuthorizableConfigBean group = new AuthorizableConfigBean();
150+
group.setAuthorizableId("testGroup" + n);
151+
group.setDescription("my description" + n);
152+
groups.add(group);
153+
}
154+
imsUserManagement.updateGroups(groups);
155+
}
156+
135157
private static String getMandatoryEnvironmentVariable(String name) {
136158
String value = System.getenv(name);
137159
if (value == null) {

0 commit comments

Comments
 (0)