use of org.apache.syncope.common.lib.to.ExecTO 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());
}
}
}
use of org.apache.syncope.common.lib.to.ExecTO 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());
}
use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.
the class SchedTaskITCase method deferred.
@Test
public void deferred() {
ImplementationTO taskJobDelegate = implementationService.read(ImplementationType.TASKJOB_DELEGATE, TestSampleJobDelegate.class.getSimpleName());
assertNotNull(taskJobDelegate);
SchedTaskTO task = new SchedTaskTO();
task.setActive(true);
task.setName("deferred");
task.setJobDelegate(taskJobDelegate.getKey());
Response response = taskService.create(TaskType.SCHEDULED, task);
task = getObject(response.getLocation(), TaskService.class, SchedTaskTO.class);
assertNotNull(task);
Date initial = new Date();
Date later = DateUtils.addSeconds(initial, 2);
taskService.execute(new ExecuteQuery.Builder().key(task.getKey()).startAt(later).build());
int i = 0;
int maxit = 50;
// wait for completion (executions incremented)
do {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
task = taskService.read(TaskType.SCHEDULED, task.getKey(), true);
assertNotNull(task);
assertNotNull(task.getExecutions());
i++;
} while (task.getExecutions().isEmpty() && i < maxit);
PagedResult<ExecTO> execs = taskService.listExecutions(new ExecQuery.Builder().key(task.getKey()).build());
assertEquals(1, execs.getTotalCount());
assertTrue(execs.getResult().get(0).getStart().after(initial));
// round 1 sec for safety
assertTrue(DateUtils.addSeconds(execs.getResult().get(0).getStart(), 1).after(later));
}
use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.
the class PullTaskITCase method reconcileFromLDAP.
@Test
public void reconcileFromLDAP() {
// First of all, clear any potential conflict with existing user / group
ldapCleanup();
// 0. pull
ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, "1e419ca4-ea81-4493-a14f-28b90113686d", 50, false);
// 1. verify execution status
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
// 2. verify that pulled group is found
PagedResult<GroupTO> matchingGroups = groupService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo("testLDAPGroup").query()).build());
assertNotNull(matchingGroups);
assertEquals(1, matchingGroups.getResult().size());
// SYNCOPE-898
PullTaskTO task = taskService.read(TaskType.PULL, "1e419ca4-ea81-4493-a14f-28b90113686d", false);
assertEquals("/", task.getDestinationRealm());
assertEquals("/", matchingGroups.getResult().get(0).getRealm());
// 3. verify that pulled user is found
PagedResult<UserTO> matchingUsers = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").query()).build());
assertNotNull(matchingUsers);
assertEquals(1, matchingUsers.getResult().size());
// SYNCOPE-898
assertEquals("/odd", matchingUsers.getResult().get(0).getRealm());
// Check for SYNCOPE-436
assertEquals("pullFromLDAP", matchingUsers.getResult().get(0).getVirAttr("virtualReadOnly").get().getValues().get(0));
// Check for SYNCOPE-270
assertNotNull(matchingUsers.getResult().get(0).getPlainAttr("obscure"));
// Check for SYNCOPE-123
assertNotNull(matchingUsers.getResult().get(0).getPlainAttr("photo"));
GroupTO groupTO = matchingGroups.getResult().iterator().next();
assertNotNull(groupTO);
assertEquals("testLDAPGroup", groupTO.getName());
assertEquals("true", groupTO.getPlainAttr("show").get().getValues().get(0));
assertEquals(matchingUsers.getResult().iterator().next().getKey(), groupTO.getUserOwner());
assertNull(groupTO.getGroupOwner());
// SYNCOPE-317
execProvisioningTask(taskService, TaskType.PULL, "1e419ca4-ea81-4493-a14f-28b90113686d", 50, false);
// 4. verify that LDAP group membership is propagated as Syncope membership
int i = 0;
int maxit = 50;
PagedResult<UserTO> members;
do {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
members = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().inGroups(groupTO.getKey()).query()).build());
assertNotNull(members);
i++;
} while (members.getResult().isEmpty() && i < maxit);
if (i == maxit) {
fail("Timeout while checking for memberships of " + groupTO.getName());
}
assertEquals(1, members.getResult().size());
}
use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.
the class PullTaskITCase method reconcileFromDB.
@Test
public void reconcileFromDB() {
UserTO userTO = null;
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
try {
ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, "83f7e85d-9774-43fe-adba-ccd856312994", 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
userTO = userService.read("testuser1");
assertNotNull(userTO);
assertEquals("reconciled@syncope.apache.org", userTO.getPlainAttr("userId").get().getValues().get(0));
assertEquals("suspended", userTO.getStatus());
// enable user on external resource
jdbcTemplate.execute("UPDATE TEST SET status=TRUE WHERE id='testuser1'");
// re-execute the same PullTask: now user must be active
execution = execProvisioningTask(taskService, TaskType.PULL, "83f7e85d-9774-43fe-adba-ccd856312994", 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
userTO = userService.read("testuser1");
assertNotNull(userTO);
assertEquals("active", userTO.getStatus());
} finally {
jdbcTemplate.execute("UPDATE TEST SET status=FALSE WHERE id='testUser1'");
if (userTO != null) {
userService.delete(userTO.getKey());
}
}
}
Aggregations