use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.
the class AnyDirectoryPanel method customResultBody.
@Override
@SuppressWarnings("unchecked")
protected Panel customResultBody(final String panelId, final AnyWrapper<A> item, final Serializable result) {
if (!(result instanceof ProvisioningResult)) {
throw new IllegalStateException("Unsupported result type");
}
return new StatusPanel(panelId, ((ProvisioningResult<A>) result).getEntity(), new ListModel<>(new ArrayList<>()), ((ProvisioningResult<A>) result).getPropagationStatuses().stream().map(input -> {
ConnObjectTO before = input.getBeforeObj();
ConnObjectWrapper afterObjWrapper = new ConnObjectWrapper(((ProvisioningResult<A>) result).getEntity(), input.getResource(), input.getAfterObj());
return Pair.of(before, afterObjWrapper);
}).collect(Collectors.toList()), pageRef);
}
use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.
the class AnyObjectITCase method create.
@Test
public void create() {
AnyObjectTO anyObjectTO = getSampleTO("create");
anyObjectTO = createAnyObject(anyObjectTO).getEntity();
assertNotNull(anyObjectTO);
ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
assertNotNull(connObjectTO);
assertNotNull(connObjectTO.getAttr("LOCATION"));
assertEquals(anyObjectTO.getPlainAttr("location").get().getValues(), connObjectTO.getAttr("LOCATION").get().getValues());
}
use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.
the class PropagationTaskITCase method propagationJEXLTransformer.
@Test
public void propagationJEXLTransformer() {
// 0. Set propagation JEXL MappingItemTransformer
ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED);
ResourceTO originalResource = SerializationUtils.clone(resource);
ProvisionTO provision = resource.getProvision("PRINTER").get();
assertNotNull(provision);
Optional<ItemTO> mappingItem = provision.getMapping().getItems().stream().filter(item -> "location".equals(item.getIntAttrName())).findFirst();
assertTrue(mappingItem.isPresent());
assertTrue(mappingItem.get().getTransformers().isEmpty());
String suffix = getUUIDString();
mappingItem.get().setPropagationJEXLTransformer("value + '" + suffix + "'");
try {
resourceService.update(resource);
// 1. create printer on external resource
AnyObjectTO anyObjectTO = AnyObjectITCase.getSampleTO("propagationJEXLTransformer");
String originalLocation = anyObjectTO.getPlainAttr("location").get().getValues().get(0);
assertFalse(originalLocation.endsWith(suffix));
anyObjectTO = createAnyObject(anyObjectTO).getEntity();
assertNotNull(anyObjectTO);
// 2. verify that JEXL MappingItemTransformer was applied during propagation
// (location ends with given suffix on external resource)
ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
assertFalse(anyObjectTO.getPlainAttr("location").get().getValues().get(0).endsWith(suffix));
assertTrue(connObjectTO.getAttr("LOCATION").get().getValues().get(0).endsWith(suffix));
} finally {
resourceService.update(originalResource);
}
}
use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.
the class PullTaskITCase method reconcileFromScriptedSQL.
@Test
public void reconcileFromScriptedSQL() throws IOException {
// 0. reset sync token and set MappingItemTransformer
ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED);
ResourceTO originalResource = SerializationUtils.clone(resource);
ProvisionTO provision = resource.getProvision("PRINTER").get();
assertNotNull(provision);
ItemTO mappingItem = provision.getMapping().getItems().stream().filter(object -> "location".equals(object.getIntAttrName())).findFirst().get();
assertNotNull(mappingItem);
final String prefix = "PREFIX_";
ImplementationTO transformer = new ImplementationTO();
transformer.setKey("PrefixItemTransformer");
transformer.setEngine(ImplementationEngine.GROOVY);
transformer.setType(ImplementationType.ITEM_TRANSFORMER);
transformer.setBody(IOUtils.toString(getClass().getResourceAsStream("/PrefixItemTransformer.groovy"), StandardCharsets.UTF_8));
Response response = implementationService.create(transformer);
transformer = implementationService.read(transformer.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(transformer);
mappingItem.getTransformers().clear();
mappingItem.getTransformers().add(transformer.getKey());
try {
resourceService.update(resource);
resourceService.removeSyncToken(resource.getKey(), provision.getAnyType());
// insert a deleted record in the external resource (SYNCOPE-923), which will be returned
// as sync event prior to the CREATE_OR_UPDATE events generated by the actions below (before pull)
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
jdbcTemplate.update("INSERT INTO TESTPRINTER (id, printername, location, deleted, lastmodification) VALUES (?,?,?,?,?)", UUID.randomUUID().toString(), "Mysterious Printer", "Nowhere", true, new Date());
// 1. create printer on external resource
AnyObjectTO anyObjectTO = AnyObjectITCase.getSampleTO("pull");
String originalLocation = anyObjectTO.getPlainAttr("location").get().getValues().get(0);
assertFalse(originalLocation.startsWith(prefix));
anyObjectTO = createAnyObject(anyObjectTO).getEntity();
assertNotNull(anyObjectTO);
// 2. verify that PrefixMappingItemTransformer was applied during propagation
// (location starts with given prefix on external resource)
ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
assertFalse(anyObjectTO.getPlainAttr("location").get().getValues().get(0).startsWith(prefix));
assertTrue(connObjectTO.getAttr("LOCATION").get().getValues().get(0).startsWith(prefix));
// 3. unlink any existing printer and delete from Syncope (printer is now only on external resource)
PagedResult<AnyObjectTO> matchingPrinters = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("pull*").query()).build());
assertTrue(matchingPrinters.getSize() > 0);
for (AnyObjectTO printer : matchingPrinters.getResult()) {
anyObjectService.deassociate(new DeassociationPatch.Builder().key(printer.getKey()).action(ResourceDeassociationAction.UNLINK).resource(RESOURCE_NAME_DBSCRIPTED).build());
anyObjectService.delete(printer.getKey());
}
// ensure that the pull task does not have the DELETE capability (SYNCOPE-923)
PullTaskTO pullTask = taskService.read(TaskType.PULL, "30cfd653-257b-495f-8665-281281dbcb3d", false);
assertNotNull(pullTask);
assertFalse(pullTask.isPerformDelete());
// 4. pull
execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
// 5. verify that printer was re-created in Syncope (implies that location does not start with given prefix,
// hence PrefixItemTransformer was applied during pull)
matchingPrinters = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("pull*").query()).build());
assertTrue(matchingPrinters.getSize() > 0);
// 6. verify that synctoken was updated
assertNotNull(resourceService.read(RESOURCE_NAME_DBSCRIPTED).getProvision(anyObjectTO.getType()).get().getSyncToken());
} finally {
resourceService.update(originalResource);
}
}
use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.
the class PullTaskITCase method issueSYNCOPE1062.
@Test
public void issueSYNCOPE1062() {
GroupTO propagationGroup = null;
PullTaskTO pullTask = null;
UserTO user = null;
GroupTO group = null;
try {
// 1. create group with resource for propagation
propagationGroup = GroupITCase.getBasicSampleTO("SYNCOPE1062");
propagationGroup.getResources().add(RESOURCE_NAME_DBPULL);
propagationGroup = createGroup(propagationGroup).getEntity();
// 2. create pull task for another resource, with user template assigning the group above
pullTask = new PullTaskTO();
pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
pullTask.setName("SYNCOPE1062");
pullTask.setActive(true);
pullTask.setPerformCreate(true);
pullTask.setPerformUpdate(true);
pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
pullTask.setResource(RESOURCE_NAME_LDAP);
UserTO template = new UserTO();
template.getAuxClasses().add("minimal group");
template.getMemberships().add(new MembershipTO.Builder().group(propagationGroup.getKey()).build());
template.getPlainAttrs().add(attrTO("firstname", "'fixed'"));
pullTask.getTemplates().put(AnyTypeKind.USER.name(), template);
Response taskResponse = taskService.create(TaskType.PULL, pullTask);
pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
assertNotNull(pullTask);
assertFalse(pullTask.getTemplates().isEmpty());
// 3. exec the pull task
ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
// the user is successfully pulled...
user = userService.read("pullFromLDAP");
assertNotNull(user);
assertEquals("pullFromLDAP@syncope.apache.org", user.getPlainAttr("email").get().getValues().get(0));
group = groupService.read("testLDAPGroup");
assertNotNull(group);
ConnObjectTO connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
assertNotNull(connObject);
assertEquals("pullFromLDAP@syncope.apache.org", connObject.getAttr("mail").get().getValues().get(0));
AttrTO userDn = connObject.getAttr(Name.NAME).get();
assertNotNull(userDn);
assertEquals(1, userDn.getValues().size());
assertNotNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, userDn.getValues().get(0)));
// ...and propagated
PagedResult<TaskTO> propagationTasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).resource(RESOURCE_NAME_DBPULL).anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
assertEquals(1, propagationTasks.getSize());
// 4. update the user on the external resource
updateLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, userDn.getValues().get(0), Pair.of("mail", "pullFromLDAP2@syncope.apache.org"));
connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
assertNotNull(connObject);
assertEquals("pullFromLDAP2@syncope.apache.org", connObject.getAttr("mail").get().getValues().get(0));
// 5. exec the pull task again
execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
// the internal is updated...
user = userService.read("pullFromLDAP");
assertNotNull(user);
assertEquals("pullFromLDAP2@syncope.apache.org", user.getPlainAttr("email").get().getValues().get(0));
// ...and propagated
propagationTasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).resource(RESOURCE_NAME_DBPULL).anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
assertEquals(2, propagationTasks.getSize());
} catch (Exception e) {
LOG.error("Unexpected during issueSYNCOPE1062()", e);
fail(e.getMessage());
} finally {
if (pullTask != null) {
taskService.delete(TaskType.PULL, pullTask.getKey());
}
if (propagationGroup != null) {
groupService.delete(propagationGroup.getKey());
}
if (group != null) {
groupService.delete(group.getKey());
}
if (user != null) {
userService.delete(user.getKey());
}
}
}
Aggregations