use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.
the class GroupITCase method issue178.
@Test
public void issue178() {
GroupTO groupTO = new GroupTO();
String groupName = "torename" + getUUIDString();
groupTO.setName(groupName);
groupTO.setRealm("/");
GroupTO actual = createGroup(groupTO).getEntity();
assertNotNull(actual);
assertEquals(groupName, actual.getName());
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(actual.getKey());
String renamedGroup = "renamed" + getUUIDString();
groupPatch.setName(new StringReplacePatchItem.Builder().value(renamedGroup).build());
actual = updateGroup(groupPatch).getEntity();
assertNotNull(actual);
assertEquals(renamedGroup, actual.getName());
}
use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.
the class GroupITCase method create.
@Test
public void create() {
GroupTO groupTO = getSampleTO("lastGroup");
groupTO.getVirAttrs().add(attrTO("rvirtualdata", "rvirtualvalue"));
groupTO.setGroupOwner("f779c0d4-633b-4be5-8f57-32eb478a3ca5");
groupTO = createGroup(groupTO).getEntity();
assertNotNull(groupTO);
assertNotNull(groupTO.getVirAttr("rvirtualdata").get().getValues());
assertFalse(groupTO.getVirAttr("rvirtualdata").get().getValues().isEmpty());
assertEquals("rvirtualvalue", groupTO.getVirAttr("rvirtualdata").get().getValues().get(0));
assertTrue(groupTO.getResources().contains(RESOURCE_NAME_LDAP));
ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey());
assertNotNull(connObjectTO);
assertNotNull(connObjectTO.getAttr("owner"));
// SYNCOPE-515: remove ownership
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(groupTO.getKey());
groupPatch.setGroupOwner(new StringReplacePatchItem());
assertNull(updateGroup(groupPatch).getEntity().getGroupOwner());
}
use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.
the class GroupITCase method createWithMandatorySchema.
@Test
public void createWithMandatorySchema() {
// 1. create a mandatory schema
PlainSchemaTO badge = new PlainSchemaTO();
badge.setKey("badge" + getUUIDString());
badge.setMandatoryCondition("true");
schemaService.create(SchemaType.PLAIN, badge);
// 2. create a group *without* an attribute for that schema: it works
GroupTO groupTO = getSampleTO("lastGroup");
assertFalse(groupTO.getPlainAttr(badge.getKey()).isPresent());
groupTO = createGroup(groupTO).getEntity();
assertNotNull(groupTO);
assertFalse(groupTO.getPlainAttr(badge.getKey()).isPresent());
// 3. add the new mandatory schema to the default group type
AnyTypeTO type = anyTypeService.read(AnyTypeKind.GROUP.name());
String typeClassName = type.getClasses().get(0);
AnyTypeClassTO typeClass = anyTypeClassService.read(typeClassName);
typeClass.getPlainSchemas().add(badge.getKey());
anyTypeClassService.update(typeClass);
typeClass = anyTypeClassService.read(typeClassName);
assertTrue(typeClass.getPlainSchemas().contains(badge.getKey()));
try {
// 4. update group: failure since no values are provided and it is mandatory
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(groupTO.getKey());
try {
updateGroup(groupPatch);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
}
// 5. also add an actual attribute for badge - it will work
groupPatch.getPlainAttrs().add(attrAddReplacePatch(badge.getKey(), "xxxxxxxxxx"));
groupTO = updateGroup(groupPatch).getEntity();
assertNotNull(groupTO);
assertNotNull(groupTO.getPlainAttr(badge.getKey()));
} finally {
// restore the original group class
typeClass.getPlainSchemas().remove(badge.getKey());
anyTypeClassService.update(typeClass);
typeClass = anyTypeClassService.read(typeClassName);
assertFalse(typeClass.getPlainSchemas().contains(badge.getKey()));
}
}
use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.
the class GroupITCase method issueSYNCOPE632.
@Test
public void issueSYNCOPE632() {
DerSchemaTO orig = schemaService.read(SchemaType.DERIVED, "displayProperty");
DerSchemaTO modified = SerializationUtils.clone(orig);
modified.setExpression("icon + '_' + show");
GroupTO groupTO = GroupITCase.getSampleTO("lastGroup");
try {
schemaService.update(SchemaType.DERIVED, modified);
// 0. create group
groupTO.getPlainAttrs().add(attrTO("icon", "anIcon"));
groupTO.getPlainAttrs().add(attrTO("show", "true"));
groupTO.getResources().clear();
groupTO = createGroup(groupTO).getEntity();
assertNotNull(groupTO);
// 1. create new LDAP resource having ConnObjectKey mapped to a derived attribute
ResourceTO newLDAP = resourceService.read(RESOURCE_NAME_LDAP);
newLDAP.setKey("new-ldap");
newLDAP.setPropagationPriority(0);
for (ProvisionTO provision : newLDAP.getProvisions()) {
provision.getVirSchemas().clear();
}
MappingTO mapping = newLDAP.getProvision(AnyTypeKind.GROUP.name()).get().getMapping();
ItemTO connObjectKey = mapping.getConnObjectKeyItem();
connObjectKey.setIntAttrName("displayProperty");
connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
mapping.setConnObjectKeyItem(connObjectKey);
mapping.setConnObjectLink("'cn=' + displayProperty + ',ou=groups,o=isp'");
ItemTO description = new ItemTO();
description.setIntAttrName("key");
description.setExtAttrName("description");
description.setPurpose(MappingPurpose.PROPAGATION);
mapping.add(description);
newLDAP = createResource(newLDAP);
assertNotNull(newLDAP);
// 2. update group and give the resource created above
GroupPatch patch = new GroupPatch();
patch.setKey(groupTO.getKey());
patch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value("new-ldap").build());
groupTO = updateGroup(patch).getEntity();
assertNotNull(groupTO);
// 3. update the group
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(groupTO.getKey());
groupPatch.getPlainAttrs().add(attrAddReplacePatch("icon", "anotherIcon"));
groupTO = updateGroup(groupPatch).getEntity();
assertNotNull(groupTO);
// 4. check that a single group exists in LDAP for the group created and updated above
int entries = 0;
DirContext ctx = null;
try {
ctx = getLdapResourceDirContext(null, null);
SearchControls ctls = new SearchControls();
ctls.setReturningAttributes(new String[] { "*", "+" });
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<SearchResult> result = ctx.search("ou=groups,o=isp", "(description=" + groupTO.getKey() + ")", ctls);
while (result.hasMore()) {
result.next();
entries++;
}
} catch (Exception e) {
// ignore
} finally {
if (ctx != null) {
try {
ctx.close();
} catch (NamingException e) {
// ignore
}
}
}
assertEquals(1, entries);
} finally {
schemaService.update(SchemaType.DERIVED, orig);
if (groupTO.getKey() != null) {
groupService.delete(groupTO.getKey());
}
resourceService.delete("new-ldap");
}
}
use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.
the class GroupITCase method bulkMembersAction.
@Test
public void bulkMembersAction() throws InterruptedException {
// 1. create group without resources
GroupTO groupTO = getBasicSampleTO("forProvision");
groupTO = createGroup(groupTO).getEntity();
// 2. create user with such group assigned
UserTO userTO = UserITCase.getUniqueSampleTO("forProvision@syncope.apache.org");
userTO.getMemberships().add(new MembershipTO.Builder().group(groupTO.getKey()).build());
userTO = createUser(userTO).getEntity();
// 3. modify the group by assiging the LDAP resource
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(groupTO.getKey());
groupPatch.getResources().add(new StringPatchItem.Builder().value(RESOURCE_NAME_LDAP).build());
ProvisioningResult<GroupTO> groupUpdateResult = updateGroup(groupPatch);
groupTO = groupUpdateResult.getEntity();
PropagationStatus propStatus = groupUpdateResult.getPropagationStatuses().get(0);
assertEquals(RESOURCE_NAME_LDAP, propStatus.getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, propStatus.getStatus());
// 4. verify that the user above is not found on LDAP
try {
resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
try {
// 5. bulk provision group members
ExecTO exec = groupService.bulkMembersAction(groupTO.getKey(), BulkMembersActionType.PROVISION);
assertNotNull(exec.getRefKey());
int i = 0;
int maxit = 50;
// wait for task exec completion (executions incremented)
SchedTaskTO taskTO;
do {
Thread.sleep(1000);
taskTO = taskService.read(TaskType.SCHEDULED, exec.getRefKey(), true);
assertNotNull(taskTO);
assertNotNull(taskTO.getExecutions());
i++;
} while (taskTO.getExecutions().isEmpty() && i < maxit);
assertFalse(taskTO.getExecutions().isEmpty());
assertEquals(TaskJob.Status.SUCCESS.name(), taskTO.getExecutions().get(0).getStatus());
// 6. verify that the user above is now fond on LDAP
ConnObjectTO userOnLdap = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
assertNotNull(userOnLdap);
} finally {
groupService.delete(groupTO.getKey());
userService.delete(userTO.getKey());
}
}
Aggregations