Search in sources :

Example 6 with ExecTO

use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.

the class PullTaskITCase method issueSYNCOPE313LDAP.

@Test
public void issueSYNCOPE313LDAP() throws Exception {
    // First of all, clear any potential conflict with existing user / group
    ldapCleanup();
    UserTO user = null;
    PullTaskTO pullTask = null;
    ConnInstanceTO resourceConnector = null;
    ConnConfProperty property = null;
    try {
        // 1. create user in LDAP
        String oldCleanPassword = "security123";
        user = UserITCase.getUniqueSampleTO("syncope313-ldap@syncope.apache.org");
        user.setPassword(oldCleanPassword);
        user.getResources().add(RESOURCE_NAME_LDAP);
        user = createUser(user).getEntity();
        assertNotNull(user);
        assertFalse(user.getResources().isEmpty());
        // 2. request to change password only on Syncope and not on LDAP
        String newCleanPassword = "new-security123";
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(user.getKey());
        userPatch.setPassword(new PasswordPatch.Builder().value(newCleanPassword).build());
        user = updateUser(userPatch).getEntity();
        // 3. Check that the Syncope user now has the changed password
        Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(user.getUsername(), newCleanPassword).self();
        assertNotNull(self);
        // 4. Check that the LDAP resource has the old password
        ConnObjectTO connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
        assertNotNull(getLdapRemoteObject(connObject.getAttr(Name.NAME).get().getValues().get(0), oldCleanPassword, connObject.getAttr(Name.NAME).get().getValues().get(0)));
        // 5. Update the LDAP Connector to retrieve passwords
        ResourceTO ldapResource = resourceService.read(RESOURCE_NAME_LDAP);
        resourceConnector = connectorService.read(ldapResource.getConnector(), Locale.ENGLISH.getLanguage());
        property = resourceConnector.getConf("retrievePasswordsWithSearch").get();
        property.getValues().clear();
        property.getValues().add(Boolean.TRUE);
        connectorService.update(resourceConnector);
        // 6. Pull the user from the resource
        ImplementationTO pullActions = new ImplementationTO();
        pullActions.setKey(LDAPPasswordPullActions.class.getSimpleName());
        pullActions.setEngine(ImplementationEngine.JAVA);
        pullActions.setType(ImplementationType.PULL_ACTIONS);
        pullActions.setBody(LDAPPasswordPullActions.class.getName());
        Response response = implementationService.create(pullActions);
        pullActions = implementationService.read(pullActions.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
        assertNotNull(pullActions);
        pullTask = new PullTaskTO();
        pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
        pullTask.setName("LDAP Pull Task");
        pullTask.setActive(true);
        pullTask.setPerformCreate(true);
        pullTask.setPerformUpdate(true);
        pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
        pullTask.setResource(RESOURCE_NAME_LDAP);
        pullTask.getActions().add(pullActions.getKey());
        Response taskResponse = taskService.create(TaskType.PULL, pullTask);
        pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
        assertNotNull(pullTask);
        ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
        // 7. Test the pulled user
        self = clientFactory.create(user.getUsername(), oldCleanPassword).self();
        assertNotNull(self);
    } catch (Exception e) {
        fail(e.getMessage());
    } finally {
        // Delete PullTask + user + reset the connector
        if (pullTask != null) {
            taskService.delete(TaskType.PULL, pullTask.getKey());
        }
        if (resourceConnector != null && property != null) {
            property.getValues().clear();
            property.getValues().add(Boolean.FALSE);
            connectorService.update(resourceConnector);
        }
        if (user != null) {
            deleteUser(user.getKey());
        }
    }
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) IOException(java.io.IOException) ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Map(java.util.Map) LDAPPasswordPullActions(org.apache.syncope.core.provisioning.java.pushpull.LDAPPasswordPullActions) Test(org.junit.jupiter.api.Test)

Example 7 with ExecTO

use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.

the class PushTaskITCase method orgUnit.

@Test
public void orgUnit() {
    assertNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=odd,o=isp"));
    assertNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=even,o=isp"));
    assertNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=two,ou=even,o=isp"));
    // 1. create task for pulling org units
    PushTaskTO task = new PushTaskTO();
    task.setName("For orgUnit");
    task.setActive(true);
    task.setResource(RESOURCE_NAME_LDAP_ORGUNIT);
    task.setSourceRealm(SyncopeConstants.ROOT_REALM);
    task.setPerformCreate(true);
    task.setPerformDelete(true);
    task.setPerformUpdate(true);
    Response response = taskService.create(TaskType.PUSH, task);
    PushTaskTO pushTask = getObject(response.getLocation(), TaskService.class, PushTaskTO.class);
    assertNotNull(pushTask);
    ExecTO exec = execProvisioningTask(taskService, TaskType.PUSH, pushTask.getKey(), 50, false);
    assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
    // 2. check
    assertNotNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=odd,o=isp"));
    assertNotNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=even,o=isp"));
    assertNotNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=two,ou=even,o=isp"));
}
Also used : Response(javax.ws.rs.core.Response) ExecTO(org.apache.syncope.common.lib.to.ExecTO) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) Test(org.junit.jupiter.api.Test)

Example 8 with ExecTO

use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.

the class ReportITCase method issueSYNCOPE43.

@Test
public void issueSYNCOPE43() {
    ReportTO reportTO = new ReportTO();
    reportTO.setName("issueSYNCOPE43" + getUUIDString());
    reportTO.setActive(true);
    reportTO.setTemplate("sample");
    reportTO = createReport(reportTO);
    assertNotNull(reportTO);
    ExecTO execution = reportService.execute(new ExecuteQuery.Builder().key(reportTO.getKey()).build());
    assertNotNull(execution);
    int maxit = 50;
    do {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        reportTO = reportService.read(reportTO.getKey());
        maxit--;
    } while (reportTO.getExecutions().isEmpty() && maxit > 0);
    assertEquals(1, reportTO.getExecutions().size());
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) ExecuteQuery(org.apache.syncope.common.rest.api.beans.ExecuteQuery) ReportTO(org.apache.syncope.common.lib.to.ReportTO) Test(org.junit.jupiter.api.Test)

Example 9 with ExecTO

use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.

the class ReportITCase method issueSYNCOPE102.

@Test
public void issueSYNCOPE102() throws IOException {
    // Create
    ReportTO reportTO = reportService.read("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
    reportTO.setKey(null);
    reportTO.setName("issueSYNCOPE102" + getUUIDString());
    reportTO = createReport(reportTO);
    assertNotNull(reportTO);
    // Execute (multiple requests)
    for (int i = 0; i < 10; i++) {
        ExecTO execution = reportService.execute(new ExecuteQuery.Builder().key(reportTO.getKey()).build());
        assertNotNull(execution);
    }
    // Wait for one execution
    int maxit = 50;
    do {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        reportTO = reportService.read(reportTO.getKey());
        maxit--;
    } while (reportTO.getExecutions().isEmpty() && maxit > 0);
    assertFalse(reportTO.getExecutions().isEmpty());
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) ExecuteQuery(org.apache.syncope.common.rest.api.beans.ExecuteQuery) ReportTO(org.apache.syncope.common.lib.to.ReportTO) Test(org.junit.jupiter.api.Test)

Example 10 with ExecTO

use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.

the class TaskDataBinderImpl method getExecTO.

@Override
public ExecTO getExecTO(final TaskExec execution) {
    ExecTO execTO = new ExecTO();
    BeanUtils.copyProperties(execution, execTO, IGNORE_TASK_EXECUTION_PROPERTIES);
    if (execution.getKey() != null) {
        execTO.setKey(execution.getKey());
    }
    if (execution.getTask() != null && execution.getTask().getKey() != null) {
        execTO.setJobType(JobType.TASK);
        execTO.setRefKey(execution.getTask().getKey());
        execTO.setRefDesc(buildRefDesc(execution.getTask()));
    }
    return execTO;
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO)

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