use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.
the class NotificationTaskITCase method notifyByMailWithRetry.
@Test
public void notifyByMailWithRetry() throws Exception {
// 1. Set higher number of retries
AttrTO origMaxRetries = configurationService.get("notification.maxRetries");
configurationService.set(attrTO(origMaxRetries.getSchema(), "10"));
// 2. Stop mail server to force errors while sending out e-mails
stopGreenMail();
try {
// 3. create notification and user
String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
String subject = "Test notification " + getUUIDString();
Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, subject);
NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
assertNotNull(taskTO);
assertNotNull(taskTO.getNotification());
int preExecs = taskTO.getExecutions().size();
// 4. verify notification could not be delivered
execTask(taskService, TaskType.NOTIFICATION, taskTO.getKey(), NotificationJob.Status.NOT_SENT.name(), 5, false);
taskTO = taskService.read(TaskType.NOTIFICATION, taskTO.getKey(), true);
assertNotNull(taskTO);
assertFalse(taskTO.isExecuted());
assertTrue(preExecs <= taskTO.getExecutions().size());
for (ExecTO exec : taskTO.getExecutions()) {
assertEquals(NotificationJob.Status.NOT_SENT.name(), exec.getStatus());
}
} finally {
// start mail server again
startGreenMail();
// reset number of retries
configurationService.set(origMaxRetries);
}
}
use of org.apache.syncope.common.lib.to.ExecTO 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.ExecTO in project syncope by apache.
the class PullTaskITCase method remediation.
@Test
public void remediation() {
// First of all, clear any potential conflict with existing user / group
ldapCleanup();
// 1. create ldap cloned resource, where 'userId' (mandatory on Syncope) is removed from mapping
ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
ldap.setKey("ldapForRemediation");
ProvisionTO provision = ldap.getProvision(AnyTypeKind.USER.name()).get();
provision.getVirSchemas().clear();
provision.getMapping().getItems().removeIf(item -> "userId".equals(item.getIntAttrName()));
ldap = createResource(ldap);
// 2. create PullTask with remediation enabled, for the new resource
PullTaskTO pullTask = (PullTaskTO) taskService.search(new TaskQuery.Builder(TaskType.PULL).resource(RESOURCE_NAME_LDAP).build()).getResult().get(0);
assertNotNull(pullTask);
pullTask.setResource(ldap.getKey());
pullTask.setRemediation(true);
pullTask.getActions().clear();
Response response = taskService.create(TaskType.PULL, pullTask);
if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
}
pullTask = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
assertNotNull(pullTask);
try {
// 3. execute the pull task and verify that:
ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
// 3a. user was not pulled
try {
userService.read("pullFromLDAP");
fail("This should never happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
// 3b. remediation was created
Optional<RemediationTO> remediation = remediationService.list().stream().filter(r -> "uid=pullFromLDAP,ou=People,o=isp".equalsIgnoreCase(r.getRemoteName())).findFirst();
assertTrue(remediation.isPresent());
assertEquals(AnyTypeKind.USER.name(), remediation.get().getAnyType());
assertEquals(ResourceOperation.CREATE, remediation.get().getOperation());
assertNotNull(remediation.get().getAnyTOPayload());
assertNull(remediation.get().getAnyPatchPayload());
assertNull(remediation.get().getKeyPayload());
assertTrue(remediation.get().getError().contains("RequiredValuesMissing [userId]"));
// 4. remedy by copying the email value to userId
UserTO user = (UserTO) remediation.get().getAnyTOPayload();
user.getResources().clear();
String email = user.getPlainAttr("email").get().getValues().get(0);
user.getPlainAttrs().add(new AttrTO.Builder().schema("userId").value(email).build());
remediationService.remedy(remediation.get().getKey(), user);
// 5. user is now found
user = userService.read("pullFromLDAP");
assertNotNull(user);
assertEquals(email, user.getPlainAttr("userId").get().getValues().get(0));
// 6. remediation was removed
try {
remediationService.read(remediation.get().getKey());
fail("This should never happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
} finally {
resourceService.delete(ldap.getKey());
}
}
use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.
the class PullTaskITCase method issueSYNCOPE272.
@Test
public void issueSYNCOPE272() {
removeTestUsers();
// create user with testdb resource
UserTO userTO = UserITCase.getUniqueSampleTO("syncope272@syncope.apache.org");
userTO.getResources().add(RESOURCE_NAME_TESTDB);
ProvisioningResult<UserTO> result = createUser(userTO);
userTO = result.getEntity();
try {
assertNotNull(userTO);
assertEquals(1, result.getPropagationStatuses().size());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
ExecTO taskExecTO = execProvisioningTask(taskService, TaskType.PULL, "986867e2-993b-430e-8feb-aa9abb4c1dcd", 50, false);
assertNotNull(taskExecTO.getStatus());
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(taskExecTO.getStatus()));
userTO = userService.read(userTO.getKey());
assertNotNull(userTO);
assertNotNull(userTO.getPlainAttr("firstname").get().getValues().get(0));
} finally {
removeTestUsers();
}
}
use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.
the class PullTaskITCase method fromCSV.
@Test
public void fromCSV() throws Exception {
removeTestUsers();
// Attemp to reset CSV content
Properties props = new Properties();
InputStream propStream = null;
InputStream srcStream = null;
OutputStream dstStream = null;
try {
propStream = getClass().getResourceAsStream("/core-test.properties");
props.load(propStream);
srcStream = new FileInputStream(props.getProperty("test.csv.src"));
dstStream = new FileOutputStream(props.getProperty("test.csv.dst"));
IOUtils.copy(srcStream, dstStream);
} catch (IOException e) {
fail(e.getMessage());
} finally {
if (propStream != null) {
propStream.close();
}
if (srcStream != null) {
srcStream.close();
}
if (dstStream != null) {
dstStream.close();
}
}
// -----------------------------
// Create a new user ... it should be updated applying pull policy
// -----------------------------
UserTO inUserTO = new UserTO();
inUserTO.setRealm(SyncopeConstants.ROOT_REALM);
inUserTO.setPassword("password123");
String userName = "test9";
inUserTO.setUsername(userName);
inUserTO.getPlainAttrs().add(attrTO("firstname", "nome9"));
inUserTO.getPlainAttrs().add(attrTO("surname", "cognome"));
inUserTO.getPlainAttrs().add(attrTO("ctype", "a type"));
inUserTO.getPlainAttrs().add(attrTO("fullname", "nome cognome"));
inUserTO.getPlainAttrs().add(attrTO("userId", "puccini@syncope.apache.org"));
inUserTO.getPlainAttrs().add(attrTO("email", "puccini@syncope.apache.org"));
inUserTO.getAuxClasses().add("csv");
inUserTO = createUser(inUserTO).getEntity();
assertNotNull(inUserTO);
assertFalse(inUserTO.getResources().contains(RESOURCE_NAME_CSV));
// -----------------------------
try {
int usersPre = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).page(1).size(1).build()).getTotalCount();
assertNotNull(usersPre);
ExecTO exec = execProvisioningTask(taskService, TaskType.PULL, PULL_TASK_KEY, 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
LOG.debug("Execution of task {}:\n{}", PULL_TASK_KEY, exec);
// check for pull results
int usersPost = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).page(1).size(1).build()).getTotalCount();
assertNotNull(usersPost);
assertEquals(usersPre + 8, usersPost);
// after execution of the pull task the user data should have been pulled from CSV
// and processed by user template
UserTO userTO = userService.read(inUserTO.getKey());
assertNotNull(userTO);
assertEquals(userName, userTO.getUsername());
assertEquals(FlowableDetector.isFlowableEnabledForUsers(syncopeService) ? "active" : "created", userTO.getStatus());
assertEquals("test9@syncope.apache.org", userTO.getPlainAttr("email").get().getValues().get(0));
assertEquals("test9@syncope.apache.org", userTO.getPlainAttr("userId").get().getValues().get(0));
assertTrue(Integer.valueOf(userTO.getPlainAttr("fullname").get().getValues().get(0)) <= 10);
assertTrue(userTO.getResources().contains(RESOURCE_NAME_TESTDB));
assertTrue(userTO.getResources().contains(RESOURCE_NAME_WS2));
// Matching --> Update (no link)
assertFalse(userTO.getResources().contains(RESOURCE_NAME_CSV));
// check for user template
userTO = userService.read("test7");
assertNotNull(userTO);
assertEquals("TYPE_OTHER", userTO.getPlainAttr("ctype").get().getValues().get(0));
assertEquals(3, userTO.getResources().size());
assertTrue(userTO.getResources().contains(RESOURCE_NAME_TESTDB));
assertTrue(userTO.getResources().contains(RESOURCE_NAME_WS2));
assertEquals(1, userTO.getMemberships().size());
assertEquals("f779c0d4-633b-4be5-8f57-32eb478a3ca5", userTO.getMemberships().get(0).getGroupKey());
// Unmatching --> Assign (link) - SYNCOPE-658
assertTrue(userTO.getResources().contains(RESOURCE_NAME_CSV));
assertEquals(1, userTO.getDerAttrs().stream().filter(attrTO -> "csvuserid".equals(attrTO.getSchema())).count());
userTO = userService.read("test8");
assertNotNull(userTO);
assertEquals("TYPE_8", userTO.getPlainAttr("ctype").get().getValues().get(0));
// Check for ignored user - SYNCOPE-663
try {
userService.read("test2");
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
}
// Check for issue 215:
// * expected disabled user test1
// * expected enabled user test3
userTO = userService.read("test1");
assertNotNull(userTO);
assertEquals("suspended", userTO.getStatus());
userTO = userService.read("test3");
assertNotNull(userTO);
assertEquals("active", userTO.getStatus());
Set<String> otherPullTaskKeys = new HashSet<>();
otherPullTaskKeys.add("feae4e57-15ca-40d9-b973-8b9015efca49");
otherPullTaskKeys.add("55d5e74b-497e-4bc0-9156-73abef4b9adc");
execProvisioningTasks(taskService, TaskType.PULL, otherPullTaskKeys, 50, false);
// Matching --> UNLINK
assertFalse(userService.read("test9").getResources().contains(RESOURCE_NAME_CSV));
assertFalse(userService.read("test7").getResources().contains(RESOURCE_NAME_CSV));
} finally {
removeTestUsers();
}
}
Aggregations