use of com.sequenceiq.freeipa.client.model.Group in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testAddUsersToGroupsSingle.
@Test
public void testAddUsersToGroupsSingle() throws Exception {
Multimap<String, String> groupMapping = setupGroupMapping(5, MAX_SUBJECTS_PER_REQUEST * 2);
Multimap<String, String> warnings = ArrayListMultimap.create();
ArgumentCaptor<List<Object>> flagsCaptor = ArgumentCaptor.forClass(List.class);
ArgumentCaptor<Map<String, Object>> paramsCaptor = ArgumentCaptor.forClass(Map.class);
RPCResponse<Object> response = new RPCResponse<>();
Group result = new Group();
result.setMemberUser(List.copyOf(groupMapping.values()));
response.setResult(result);
when(freeIpaClient.invoke(eq("group_add_member"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Group.class))).thenReturn(response);
underTest.addUsersToGroups(false, freeIpaClient, groupMapping, warnings::put);
assertTrue(warnings.isEmpty());
verifyNoInteractions(batchPartitionSizeProperties);
verify(freeIpaClient, never()).callBatch(any(), any(), any(), any(), any());
List<List<Object>> flagsList = flagsCaptor.getAllValues();
Map<String, Long> flagCount = flagsList.stream().flatMap(Collection::stream).map(o -> (String) o).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
assertEquals(5, flagCount.size());
assertTrue(flagCount.keySet().containsAll(Set.of("group1", "group2", "group3", "group4", "group0")));
flagCount.forEach((flag, count) -> assertEquals(2, count, flag + " size should be 2"));
List<Map<String, Object>> paramsList = paramsCaptor.getAllValues();
assertEquals(10, paramsList.size());
paramsList.forEach(map -> {
assertEquals(10, ((List<String>) map.get("user")).size());
assertTrue(((List<String>) map.get("user")).stream().allMatch(user -> user.startsWith("user")));
});
verify(interruptChecker, times(20)).throwTimeoutExIfInterrupted();
}
use of com.sequenceiq.freeipa.client.model.Group in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testAddGroupsSingle.
@Test
public void testAddGroupsSingle() throws FreeIpaClientException, TimeoutException {
Multimap<String, String> warnings = ArrayListMultimap.create();
FmsGroup group1 = new FmsGroup().withName(UserSyncConstants.CDP_USERSYNC_INTERNAL_GROUP);
FmsGroup group2 = new FmsGroup().withName("group2");
Set<FmsGroup> groups = Set.of(group1, group2);
ArgumentCaptor<List<Object>> flagsCaptor = ArgumentCaptor.forClass(List.class);
ArgumentCaptor<Map<String, Object>> paramsCaptor = ArgumentCaptor.forClass(Map.class);
RPCResponse<Object> response1 = new RPCResponse<>();
response1.setResult(new Group());
RPCResponse<Object> response2 = new RPCResponse<>();
response2.setResult(new Group());
when(freeIpaClient.invoke(eq("group_add"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Group.class))).thenReturn(response1, response2);
underTest.addGroups(false, freeIpaClient, groups, warnings::put);
assertTrue(warnings.isEmpty());
verifyNoInteractions(batchPartitionSizeProperties);
verify(freeIpaClient, never()).callBatch(any(), any(), any(), any(), any());
List<List<Object>> flagsList = flagsCaptor.getAllValues();
assertThat(flagsList, allOf(hasItem(hasItem(UserSyncConstants.CDP_USERSYNC_INTERNAL_GROUP)), hasItem(hasItem("group2"))));
List<Map<String, Object>> paramsList = paramsCaptor.getAllValues();
assertTrue(paramsList.get(0).isEmpty());
assertEquals(true, paramsList.get(1).get("nonposix"));
verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
use of com.sequenceiq.freeipa.client.model.Group in project cloudbreak by hortonworks.
the class FreeipaClientTestServiceTest method createGroup.
private Group createGroup(String group, String user) {
Group ipaGroup = new Group();
ipaGroup.setCn(group);
ipaGroup.setMemberUser(Lists.newArrayList(user));
return ipaGroup;
}
use of com.sequenceiq.freeipa.client.model.Group in project cloudbreak by hortonworks.
the class GroupAddOperation method invoke.
@Override
public Optional<Group> invoke(FreeIpaClient freeIpaClient) throws FreeIpaClientException {
FreeIpaChecks.checkGroupNotProtected(group, () -> String.format("Group '%s' is protected and cannot be added to FreeIPA", group));
try {
LOGGER.debug("adding group {}", group);
Group groupAdded = invoke(freeIpaClient, Group.class);
LOGGER.debug("Success: {}", groupAdded);
return Optional.of(groupAdded);
} catch (FreeIpaClientException e) {
if (FreeIpaClientExceptionUtil.isDuplicateEntryException(e)) {
LOGGER.debug("group '{}' already exists", group);
} else {
LOGGER.warn("Failed to add group {}", group, e);
warnings.accept(group, "Failed to add group:" + e.getMessage());
freeIpaClient.checkIfClientStillUsable(e);
}
}
return Optional.empty();
}
use of com.sequenceiq.freeipa.client.model.Group in project cloudbreak by hortonworks.
the class GroupRemoveOperation method invoke.
@Override
public Optional<Group> invoke(FreeIpaClient freeIpaClient) throws FreeIpaClientException {
FreeIpaChecks.checkGroupNotProtected(group, () -> String.format("Group '%s' is protected and cannot be deleted from FreeIPA", group));
try {
LOGGER.debug("Removing group {}", group);
Group groupRemoved = invoke(freeIpaClient, Group.class);
LOGGER.debug("Success: {}", groupRemoved);
return Optional.of(groupRemoved);
} catch (FreeIpaClientException e) {
if (FreeIpaClientExceptionUtil.isNotFoundException(e)) {
LOGGER.debug("group '{}' already does not exists", group);
} else {
LOGGER.error("Failed to delete {}", group, e);
warnings.accept(group, "Failed to remove group: " + e.getMessage());
freeIpaClient.checkIfClientStillUsable(e);
}
}
return Optional.empty();
}
Aggregations