use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class PolicyITCase method issueSYNCOPE682.
@Test
public void issueSYNCOPE682() {
AccountPolicyTO policy = new AccountPolicyTO();
policy.setDescription("SYNCOPE682");
policy.getPassthroughResources().add(RESOURCE_NAME_LDAP);
DefaultAccountRuleConf ruleConf = new DefaultAccountRuleConf();
ruleConf.setMinLength(3);
ruleConf.setMaxLength(8);
ImplementationTO rule = new ImplementationTO();
rule.setKey("DefaultAccountRuleConf" + getUUIDString());
rule.setEngine(ImplementationEngine.JAVA);
rule.setType(ImplementationType.ACCOUNT_RULE);
rule.setBody(POJOHelper.serialize(ruleConf));
Response response = implementationService.create(rule);
rule.setKey(response.getHeaderString(RESTHeaders.RESOURCE_KEY));
policy.getRules().add(rule.getKey());
policy = createPolicy(PolicyType.ACCOUNT, policy);
assertNotNull(policy);
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class PolicyITCase method issueSYNCOPE553.
@Test
public void issueSYNCOPE553() {
AccountPolicyTO policy = new AccountPolicyTO();
policy.setDescription("SYNCOPE553");
DefaultAccountRuleConf ruleConf = new DefaultAccountRuleConf();
ruleConf.setMinLength(3);
ruleConf.setMaxLength(8);
ImplementationTO rule = new ImplementationTO();
rule.setKey("DefaultAccountRuleConf" + getUUIDString());
rule.setEngine(ImplementationEngine.JAVA);
rule.setType(ImplementationType.ACCOUNT_RULE);
rule.setBody(POJOHelper.serialize(ruleConf));
Response response = implementationService.create(rule);
rule.setKey(response.getHeaderString(RESTHeaders.RESOURCE_KEY));
policy.getRules().add(rule.getKey());
policy = createPolicy(PolicyType.ACCOUNT, policy);
assertNotNull(policy);
}
use of org.apache.syncope.common.lib.to.ImplementationTO 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.ImplementationTO in project syncope by apache.
the class PullTaskITCase method filteredReconciliation.
@Test
public void filteredReconciliation() throws IOException {
String user1OnTestPull = UUID.randomUUID().toString();
String user2OnTestPull = UUID.randomUUID().toString();
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
PullTaskTO task = null;
UserTO userTO = null;
try {
// 1. create 2 users on testpull
jdbcTemplate.execute("INSERT INTO testpull VALUES (" + "'" + user1OnTestPull + "', 'user1', 'Doe', false, 'mail1@apache.org', NULL)");
jdbcTemplate.execute("INSERT INTO testpull VALUES (" + "'" + user2OnTestPull + "', 'user2', 'Rossi', false, 'mail2@apache.org', NULL)");
// 2. create new pull task for test-db, with reconciliation filter (surname 'Rossi')
ImplementationTO reconFilterBuilder = new ImplementationTO();
reconFilterBuilder.setKey("TestReconFilterBuilder");
reconFilterBuilder.setEngine(ImplementationEngine.GROOVY);
reconFilterBuilder.setType(ImplementationType.RECON_FILTER_BUILDER);
reconFilterBuilder.setBody(IOUtils.toString(getClass().getResourceAsStream("/TestReconFilterBuilder.groovy"), StandardCharsets.UTF_8));
Response response = implementationService.create(reconFilterBuilder);
reconFilterBuilder = implementationService.read(reconFilterBuilder.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(reconFilterBuilder);
task = taskService.read(TaskType.PULL, "7c2242f4-14af-4ab5-af31-cdae23783655", true);
task.setPullMode(PullMode.FILTERED_RECONCILIATION);
task.setReconFilterBuilder(reconFilterBuilder.getKey());
response = taskService.create(TaskType.PULL, task);
task = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
assertNotNull(task);
assertEquals(reconFilterBuilder.getKey(), task.getReconFilterBuilder());
// 3. exec task
ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, task.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
// 4. verify that only enabled user was pulled
userTO = userService.read("user2");
assertNotNull(userTO);
try {
userService.read("user1");
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
} finally {
jdbcTemplate.execute("DELETE FROM testpull WHERE id = '" + user1OnTestPull + "'");
jdbcTemplate.execute("DELETE FROM testpull WHERE id = '" + user2OnTestPull + "'");
if (task != null && !"7c2242f4-14af-4ab5-af31-cdae23783655".equals(task.getKey())) {
taskService.delete(TaskType.PULL, task.getKey());
}
if (userTO != null) {
userService.delete(userTO.getKey());
}
}
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class PullTaskITCase method issueSYNCOPE313DB.
@Test
public void issueSYNCOPE313DB() throws Exception {
// 1. create user in DB
UserTO user = UserITCase.getUniqueSampleTO("syncope313-db@syncope.apache.org");
user.setPassword("security123");
user.getResources().add(RESOURCE_NAME_TESTDB);
user = createUser(user).getEntity();
assertNotNull(user);
assertFalse(user.getResources().isEmpty());
// 2. Check that the DB resource has the correct password
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
String value = queryForObject(jdbcTemplate, 50, "SELECT PASSWORD FROM test WHERE ID=?", String.class, user.getUsername());
assertEquals(Encryptor.getInstance().encode("security123", CipherAlgorithm.SHA1), value.toUpperCase());
// 3. Update the password in the DB
String newCleanPassword = "new-security";
String newPassword = Encryptor.getInstance().encode(newCleanPassword, CipherAlgorithm.SHA1);
jdbcTemplate.execute("UPDATE test set PASSWORD='" + newPassword + "' where ID='" + user.getUsername() + "'");
// 4. Pull the user from the resource
ImplementationTO pullActions = new ImplementationTO();
pullActions.setKey(DBPasswordPullActions.class.getSimpleName());
pullActions.setEngine(ImplementationEngine.JAVA);
pullActions.setType(ImplementationType.PULL_ACTIONS);
pullActions.setBody(DBPasswordPullActions.class.getName());
Response response = implementationService.create(pullActions);
pullActions = implementationService.read(pullActions.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(pullActions);
PullTaskTO pullTask = new PullTaskTO();
pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
pullTask.setName("DB Pull Task");
pullTask.setActive(true);
pullTask.setPerformCreate(true);
pullTask.setPerformUpdate(true);
pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
pullTask.setResource(RESOURCE_NAME_TESTDB);
pullTask.getActions().add(pullActions.getKey());
Response taskResponse = taskService.create(TaskType.PULL, pullTask);
PullTaskTO actual = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
assertNotNull(actual);
pullTask = taskService.read(TaskType.PULL, actual.getKey(), true);
assertNotNull(pullTask);
assertEquals(actual.getKey(), pullTask.getKey());
assertEquals(actual.getJobDelegate(), pullTask.getJobDelegate());
ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
// 5. Test the pulled user
Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(user.getUsername(), newCleanPassword).self();
assertNotNull(self);
// 6. Delete PullTask + user
taskService.delete(TaskType.PULL, pullTask.getKey());
deleteUser(user.getKey());
}
Aggregations