use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class GroupITCase method unassign.
@Test
public void unassign() {
GroupTO groupTO = null;
try {
groupTO = createGroup(getSampleTO("unassign")).getEntity();
assertNotNull(groupTO);
assertNotNull(resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey()));
DeassociationPatch deassociationPatch = new DeassociationPatch();
deassociationPatch.setKey(groupTO.getKey());
deassociationPatch.setAction(ResourceDeassociationAction.UNASSIGN);
deassociationPatch.getResources().add(RESOURCE_NAME_LDAP);
assertNotNull(groupService.deassociate(deassociationPatch).readEntity(BulkActionResult.class));
groupTO = groupService.read(groupTO.getKey());
assertNotNull(groupTO);
assertTrue(groupTO.getResources().isEmpty());
try {
resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey());
fail("This should not happen");
} catch (Exception e) {
assertNotNull(e);
}
} finally {
if (groupTO != null) {
groupService.delete(groupTO.getKey());
}
}
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class GroupITCase method capabilitiesOverride.
@Test
public void capabilitiesOverride() {
// resource with no capability override
ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
assertNotNull(ldap);
assertFalse(ldap.isOverrideCapabilities());
assertTrue(ldap.getCapabilitiesOverride().isEmpty());
// connector with all required for create and update
ConnInstanceTO conn = connectorService.read(ldap.getConnector(), null);
assertNotNull(conn);
assertTrue(conn.getCapabilities().contains(ConnectorCapability.CREATE));
assertTrue(conn.getCapabilities().contains(ConnectorCapability.UPDATE));
try {
// 1. create succeeds
GroupTO group = getSampleTO("syncope714");
group.getPlainAttrs().add(attrTO("title", "first"));
group.getResources().add(RESOURCE_NAME_LDAP);
ProvisioningResult<GroupTO> result = createGroup(group);
assertNotNull(result);
assertEquals(1, result.getPropagationStatuses().size());
assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
group = result.getEntity();
// 2. update succeeds
GroupPatch patch = new GroupPatch();
patch.setKey(group.getKey());
patch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("title", "second")).build());
result = updateGroup(patch);
assertNotNull(result);
assertEquals(1, result.getPropagationStatuses().size());
assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
group = result.getEntity();
// 3. set capability override with only search allowed, but not enable
ldap.getCapabilitiesOverride().add(ConnectorCapability.SEARCH);
resourceService.update(ldap);
ldap = resourceService.read(RESOURCE_NAME_LDAP);
assertNotNull(ldap);
assertFalse(ldap.isOverrideCapabilities());
assertEquals(1, ldap.getCapabilitiesOverride().size());
assertTrue(ldap.getCapabilitiesOverride().contains(ConnectorCapability.SEARCH));
// 4. update succeeds again
patch = new GroupPatch();
patch.setKey(group.getKey());
patch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("title", "third")).build());
result = updateGroup(patch);
assertNotNull(result);
assertEquals(1, result.getPropagationStatuses().size());
assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
group = result.getEntity();
// 5. enable capability override
ldap.setOverrideCapabilities(true);
resourceService.update(ldap);
ldap = resourceService.read(RESOURCE_NAME_LDAP);
assertNotNull(ldap);
assertTrue(ldap.isOverrideCapabilities());
assertEquals(1, ldap.getCapabilitiesOverride().size());
assertTrue(ldap.getCapabilitiesOverride().contains(ConnectorCapability.SEARCH));
// 6. update now fails
patch = new GroupPatch();
patch.setKey(group.getKey());
patch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("title", "fourth")).build());
result = updateGroup(patch);
assertNotNull(result);
assertEquals(1, result.getPropagationStatuses().size());
assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
assertEquals(PropagationTaskExecStatus.NOT_ATTEMPTED, result.getPropagationStatuses().get(0).getStatus());
} finally {
ldap.getCapabilitiesOverride().clear();
ldap.setOverrideCapabilities(false);
resourceService.update(ldap);
}
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class RESTITCase method noContent.
@Test
public void noContent() throws IOException {
SyncopeClient noContentclient = clientFactory.create(ADMIN_UNAME, ADMIN_PWD);
GroupService noContentService = noContentclient.prefer(noContentclient.getService(GroupService.class), Preference.RETURN_NO_CONTENT);
GroupTO group = GroupITCase.getSampleTO("noContent");
Response response = noContentService.create(group);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
assertEquals(Preference.RETURN_NO_CONTENT.toString(), response.getHeaderString(RESTHeaders.PREFERENCE_APPLIED));
assertEquals(StringUtils.EMPTY, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
group = getObject(response.getLocation(), GroupService.class, GroupTO.class);
assertNotNull(group);
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(group.getKey());
groupPatch.getPlainAttrs().add(attrAddReplacePatch("badge", "xxxxxxxxxx"));
response = noContentService.update(groupPatch);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
assertEquals(Preference.RETURN_NO_CONTENT.toString(), response.getHeaderString(RESTHeaders.PREFERENCE_APPLIED));
assertEquals(StringUtils.EMPTY, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
response = noContentService.delete(group.getKey());
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
assertEquals(Preference.RETURN_NO_CONTENT.toString(), response.getHeaderString(RESTHeaders.PREFERENCE_APPLIED));
assertEquals(StringUtils.EMPTY, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class ResourceITCase method listConnObjects.
@Test
public void listConnObjects() {
List<String> groupKeys = new ArrayList<>();
for (int i = 0; i < 10; i++) {
GroupTO group = GroupITCase.getSampleTO("group");
group.getResources().add(RESOURCE_NAME_LDAP);
group = createGroup(group).getEntity();
groupKeys.add(group.getKey());
}
int totalRead = 0;
Set<String> read = new HashSet<>();
try {
ConnObjectTOListQuery.Builder builder = new ConnObjectTOListQuery.Builder().size(10);
PagedConnObjectTOResult list;
do {
list = null;
boolean succeeded = false;
// needed because ApacheDS seems to randomly fail when searching with cookie
for (int i = 0; i < 5 && !succeeded; i++) {
try {
list = resourceService.listConnObjects(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), builder.build());
succeeded = true;
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.ConnectorException, e.getType());
}
}
assertNotNull(list);
totalRead += list.getResult().size();
read.addAll(list.getResult().stream().map(input -> input.getAttr(ConnIdSpecialName.NAME).get().getValues().get(0)).collect(Collectors.toList()));
if (list.getPagedResultsCookie() != null) {
builder.pagedResultsCookie(list.getPagedResultsCookie());
}
} while (list.getPagedResultsCookie() != null);
assertEquals(totalRead, read.size());
assertTrue(totalRead >= 10);
} finally {
groupKeys.forEach(key -> {
groupService.delete(key);
});
}
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class CreateProducer method process.
@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
Object actual = exchange.getProperty("actual");
Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
if (actual instanceof UserTO) {
WorkflowResult<Pair<String, Boolean>> created = (WorkflowResult<Pair<String, Boolean>>) exchange.getIn().getBody();
List<PropagationTaskTO> tasks = getPropagationManager().getUserCreateTasks(created.getResult().getKey(), ((UserTO) actual).getPassword(), created.getResult().getValue(), created.getPropByRes(), ((UserTO) actual).getVirAttrs(), excludedResources);
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(created.getResult().getKey(), propagationReporter.getStatuses()));
} else if (actual instanceof AnyTO) {
WorkflowResult<String> created = (WorkflowResult<String>) exchange.getIn().getBody();
if (actual instanceof GroupTO && isPull()) {
Map<String, String> groupOwnerMap = exchange.getProperty("groupOwnerMap", Map.class);
Optional<AttrTO> groupOwner = ((GroupTO) actual).getPlainAttr(StringUtils.EMPTY);
if (groupOwner.isPresent()) {
groupOwnerMap.put(created.getResult(), groupOwner.get().getValues().iterator().next());
}
List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(created.getResult(), null));
} else {
List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(actual instanceof AnyObjectTO ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(created.getResult(), propagationReporter.getStatuses()));
}
}
}
}
Aggregations