Search in sources :

Example 26 with ExecTO

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());
        }
    }
}
Also used : TaskTO(org.apache.syncope.common.lib.to.TaskTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) IOException(java.io.IOException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Response(javax.ws.rs.core.Response) UserTO(org.apache.syncope.common.lib.to.UserTO) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Example 27 with ExecTO

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());
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) ExecTO(org.apache.syncope.common.lib.to.ExecTO) DBPasswordPullActions(org.apache.syncope.core.provisioning.java.pushpull.DBPasswordPullActions) UserTO(org.apache.syncope.common.lib.to.UserTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 28 with ExecTO

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));
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) ExecQuery(org.apache.syncope.common.rest.api.beans.ExecQuery) TestSampleJobDelegate(org.apache.syncope.fit.core.reference.TestSampleJobDelegate) Date(java.util.Date) ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) Test(org.junit.jupiter.api.Test)

Example 29 with ExecTO

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());
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) UserTO(org.apache.syncope.common.lib.to.UserTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 30 with ExecTO

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());
        }
    }
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) UserTO(org.apache.syncope.common.lib.to.UserTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

ExecTO (org.apache.syncope.common.lib.to.ExecTO)37 Test (org.junit.jupiter.api.Test)22 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)13 UserTO (org.apache.syncope.common.lib.to.UserTO)13 Response (javax.ws.rs.core.Response)11 PullTaskTO (org.apache.syncope.common.lib.to.PullTaskTO)10 Date (java.util.Date)9 TaskService (org.apache.syncope.common.rest.api.service.TaskService)8 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Map (java.util.Map)6 GroupTO (org.apache.syncope.common.lib.to.GroupTO)6 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)6 IOException (java.io.IOException)5 TaskTO (org.apache.syncope.common.lib.to.TaskTO)5 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)5 AttrTO (org.apache.syncope.common.lib.to.AttrTO)4 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)4 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)4 ItemTO (org.apache.syncope.common.lib.to.ItemTO)4