use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.
the class GroupITCase method update.
@Test
public void update() {
GroupTO groupTO = getSampleTO("latestGroup" + getUUIDString());
groupTO = createGroup(groupTO).getEntity();
assertEquals(1, groupTO.getPlainAttrs().size());
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(groupTO.getKey());
String modName = "finalGroup" + getUUIDString();
groupPatch.setName(new StringReplacePatchItem.Builder().value(modName).build());
groupPatch.getPlainAttrs().add(attrAddReplacePatch("show", "FALSE"));
groupTO = updateGroup(groupPatch).getEntity();
assertEquals(modName, groupTO.getName());
assertEquals(2, groupTO.getPlainAttrs().size());
groupTO.getPlainAttr("show").get().getValues().clear();
groupTO = groupService.update(groupTO).readEntity(new GenericType<ProvisioningResult<GroupTO>>() {
}).getEntity();
assertFalse(groupTO.getPlainAttr("show").isPresent());
}
use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.
the class GroupITCase method uDynMembership.
@Test
public void uDynMembership() {
assertTrue(userService.read("c9b2dec2-00a7-4855-97c0-d854842b4b24").getDynMemberships().isEmpty());
GroupTO group = getBasicSampleTO("uDynMembership");
group.setUDynMembershipCond("cool==true");
group = createGroup(group).getEntity();
assertNotNull(group);
final String groupKey = group.getKey();
List<MembershipTO> memberships = userService.read("c9b2dec2-00a7-4855-97c0-d854842b4b24").getDynMemberships();
assertTrue(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
assertEquals(1, groupService.read(group.getKey()).getDynamicUserMembershipCount());
GroupPatch patch = new GroupPatch();
patch.setKey(group.getKey());
patch.setUDynMembershipCond("cool==false");
groupService.update(patch);
assertTrue(userService.read("c9b2dec2-00a7-4855-97c0-d854842b4b24").getDynMemberships().isEmpty());
assertEquals(0, groupService.read(group.getKey()).getDynamicUserMembershipCount());
}
use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.
the class GroupITCase method aDynMembership.
@Test
public void aDynMembership() {
String fiql = SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").notNullValue().query();
// 1. create group with a given aDynMembership condition
GroupTO group = getBasicSampleTO("aDynMembership");
group.getADynMembershipConds().put("PRINTER", fiql);
group = createGroup(group).getEntity();
assertEquals(fiql, group.getADynMembershipConds().get("PRINTER"));
group = groupService.read(group.getKey());
final String groupKey = group.getKey();
assertEquals(fiql, group.getADynMembershipConds().get("PRINTER"));
// verify that the condition is dynamically applied
AnyObjectTO newAny = AnyObjectITCase.getSampleTO("aDynMembership");
newAny.getResources().clear();
newAny = createAnyObject(newAny).getEntity();
assertNotNull(newAny.getPlainAttr("location"));
List<MembershipTO> memberships = anyObjectService.read("fc6dbc3a-6c07-4965-8781-921e7401a4a5").getDynMemberships();
assertTrue(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
memberships = anyObjectService.read("8559d14d-58c2-46eb-a2d4-a7d35161e8f8").getDynMemberships();
assertTrue(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
memberships = anyObjectService.read(newAny.getKey()).getDynMemberships();
assertTrue(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
// 2. update group and change aDynMembership condition
fiql = SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").nullValue().query();
GroupPatch patch = new GroupPatch();
patch.setKey(group.getKey());
patch.getADynMembershipConds().put("PRINTER", fiql);
group = updateGroup(patch).getEntity();
assertEquals(fiql, group.getADynMembershipConds().get("PRINTER"));
group = groupService.read(group.getKey());
assertEquals(fiql, group.getADynMembershipConds().get("PRINTER"));
// verify that the condition is dynamically applied
AnyObjectPatch anyPatch = new AnyObjectPatch();
anyPatch.setKey(newAny.getKey());
anyPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.DELETE).attrTO(new AttrTO.Builder().schema("location").build()).build());
newAny = updateAnyObject(anyPatch).getEntity();
assertFalse(newAny.getPlainAttr("location").isPresent());
memberships = anyObjectService.read("fc6dbc3a-6c07-4965-8781-921e7401a4a5").getDynMemberships();
assertFalse(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
memberships = anyObjectService.read("8559d14d-58c2-46eb-a2d4-a7d35161e8f8").getDynMemberships();
assertFalse(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
memberships = anyObjectService.read(newAny.getKey()).getDynMemberships();
assertTrue(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
}
use of org.apache.syncope.common.lib.patch.GroupPatch 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.patch.GroupPatch 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));
}
Aggregations