Search in sources :

Example 1 with PullTaskTO

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

the class PullTaskITCase method syncTokenWithErrors.

@Test
public void syncTokenWithErrors() {
    ResourceTO origResource = resourceService.read(RESOURCE_NAME_DBPULL);
    ConnInstanceTO origConnector = connectorService.read(origResource.getConnector(), null);
    ResourceTO resForTest = SerializationUtils.clone(origResource);
    resForTest.setKey("syncTokenWithErrors");
    resForTest.setConnector(null);
    ConnInstanceTO connForTest = SerializationUtils.clone(origConnector);
    connForTest.setKey(null);
    connForTest.setDisplayName("For syncTokenWithErrors");
    JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
    try {
        connForTest.getCapabilities().add(ConnectorCapability.SYNC);
        ConnConfProperty changeLogColumn = connForTest.getConf("changeLogColumn").get();
        assertNotNull(changeLogColumn);
        assertTrue(changeLogColumn.getValues().isEmpty());
        changeLogColumn.getValues().add("lastModification");
        Response response = connectorService.create(connForTest);
        if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
            throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
        }
        connForTest = getObject(response.getLocation(), ConnectorService.class, ConnInstanceTO.class);
        assertNotNull(connForTest);
        resForTest.setConnector(connForTest.getKey());
        resForTest = createResource(resForTest);
        assertNotNull(resForTest);
        PullTaskTO pullTask = new PullTaskTO();
        pullTask.setActive(true);
        pullTask.setName("For syncTokenWithErrors");
        pullTask.setResource(resForTest.getKey());
        pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
        pullTask.setPullMode(PullMode.INCREMENTAL);
        pullTask.setPerformCreate(true);
        pullTask.setPerformUpdate(true);
        pullTask.setPerformDelete(true);
        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);
        jdbcTemplate.execute("DELETE FROM testpull");
        jdbcTemplate.execute("INSERT INTO testpull VALUES " + "(1040, 'syncTokenWithErrors1', 'Surname1', " + "false, 'syncTokenWithErrors1@syncope.apache.org', '2014-05-23 13:53:24.293')");
        jdbcTemplate.execute("INSERT INTO testpull VALUES " + "(1041, 'syncTokenWithErrors2', 'Surname2', " + "false, 'syncTokenWithErrors1@syncope.apache.org', '2015-05-23 13:53:24.293')");
        ExecTO exec = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
        resForTest = resourceService.read(resForTest.getKey());
        assertTrue(resForTest.getProvision(AnyTypeKind.USER.name()).get().getSyncToken().contains("2014-05-23"));
        jdbcTemplate.execute("UPDATE testpull " + "SET email='syncTokenWithErrors2@syncope.apache.org', lastModification='2016-05-23 13:53:24.293' " + "WHERE ID=1041");
        exec = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
        resForTest = resourceService.read(resForTest.getKey());
        assertTrue(resForTest.getProvision(AnyTypeKind.USER.name()).get().getSyncToken().contains("2016-05-23"));
    } finally {
        if (resForTest.getConnector() != null) {
            resourceService.delete(resForTest.getKey());
            connectorService.delete(connForTest.getKey());
        }
        jdbcTemplate.execute("DELETE FROM testpull WHERE ID=1040");
        jdbcTemplate.execute("DELETE FROM testpull WHERE ID=1041");
    }
}
Also used : Response(javax.ws.rs.core.Response) ExecTO(org.apache.syncope.common.lib.to.ExecTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) ConnectorService(org.apache.syncope.common.rest.api.service.ConnectorService) Test(org.junit.jupiter.api.Test)

Example 2 with PullTaskTO

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

the class PullTaskITCase method issueSYNCOPE68.

@Test
public void issueSYNCOPE68() {
    // -----------------------------
    // Create a new user ... it should be updated applying pull policy
    // -----------------------------
    UserTO userTO = new UserTO();
    userTO.setRealm(SyncopeConstants.ROOT_REALM);
    userTO.setPassword("password123");
    userTO.setUsername("testuser2");
    userTO.getPlainAttrs().add(attrTO("firstname", "testuser2"));
    userTO.getPlainAttrs().add(attrTO("surname", "testuser2"));
    userTO.getPlainAttrs().add(attrTO("ctype", "a type"));
    userTO.getPlainAttrs().add(attrTO("fullname", "a type"));
    userTO.getPlainAttrs().add(attrTO("userId", "testuser2@syncope.apache.org"));
    userTO.getPlainAttrs().add(attrTO("email", "testuser2@syncope.apache.org"));
    userTO.getResources().add(RESOURCE_NAME_NOPROPAGATION2);
    userTO.getResources().add(RESOURCE_NAME_NOPROPAGATION4);
    userTO.getMemberships().add(new MembershipTO.Builder().group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    assertEquals("testuser2", userTO.getUsername());
    assertEquals(1, userTO.getMemberships().size());
    assertEquals(3, userTO.getResources().size());
    try {
        // -----------------------------
        // add user template
        // -----------------------------
        UserTO template = new UserTO();
        template.getMemberships().add(new MembershipTO.Builder().group("b8d38784-57e7-4595-859a-076222644b55").build());
        template.getResources().add(RESOURCE_NAME_NOPROPAGATION4);
        // -----------------------------
        // Update pull task
        PullTaskTO task = taskService.read(TaskType.PULL, "81d88f73-d474-4450-9031-605daa4e313f", true);
        assertNotNull(task);
        task.getTemplates().put(AnyTypeKind.USER.name(), template);
        taskService.update(TaskType.PULL, task);
        PullTaskTO actual = taskService.read(TaskType.PULL, task.getKey(), true);
        assertNotNull(actual);
        assertEquals(task.getKey(), actual.getKey());
        assertFalse(actual.getTemplates().get(AnyTypeKind.USER.name()).getResources().isEmpty());
        assertFalse(((UserTO) actual.getTemplates().get(AnyTypeKind.USER.name())).getMemberships().isEmpty());
        ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, actual.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
        userTO = userService.read("testuser2");
        assertNotNull(userTO);
        assertEquals("testuser2@syncope.apache.org", userTO.getPlainAttr("userId").get().getValues().get(0));
        assertEquals(2, userTO.getMemberships().size());
        assertEquals(4, userTO.getResources().size());
    } finally {
        UserTO dUserTO = deleteUser(userTO.getKey()).getEntity();
        assertNotNull(dUserTO);
    }
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) Test(org.junit.jupiter.api.Test)

Example 3 with PullTaskTO

use of org.apache.syncope.common.lib.to.PullTaskTO 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 4 with PullTaskTO

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

the class PullTaskITCase method testPullActionsSetup.

@BeforeAll
public static void testPullActionsSetup() {
    ImplementationTO pullActions = null;
    try {
        pullActions = implementationService.read(ImplementationType.PULL_ACTIONS, TestPullActions.class.getSimpleName());
    } catch (SyncopeClientException e) {
        if (e.getType().getResponseStatus() == Response.Status.NOT_FOUND) {
            pullActions = new ImplementationTO();
            pullActions.setKey(TestPullActions.class.getSimpleName());
            pullActions.setEngine(ImplementationEngine.JAVA);
            pullActions.setType(ImplementationType.PULL_ACTIONS);
            pullActions.setBody(TestPullActions.class.getName());
            Response response = implementationService.create(pullActions);
            pullActions = implementationService.read(pullActions.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
            assertNotNull(pullActions);
        }
    }
    assertNotNull(pullActions);
    PullTaskTO pullTask = taskService.read(TaskType.PULL, PULL_TASK_KEY, true);
    pullTask.getActions().add(pullActions.getKey());
    taskService.update(TaskType.PULL, pullTask);
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with PullTaskTO

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

the class PullTaskITCase method issueSYNCOPE258.

@Test
public void issueSYNCOPE258() throws IOException {
    // -----------------------------
    // Add a custom correlation rule
    // -----------------------------
    ImplementationTO corrRule = null;
    try {
        corrRule = implementationService.read(ImplementationType.PULL_CORRELATION_RULE, "TestPullRule");
    } catch (SyncopeClientException e) {
        if (e.getType().getResponseStatus() == Response.Status.NOT_FOUND) {
            corrRule = new ImplementationTO();
            corrRule.setKey("TestPullRule");
            corrRule.setEngine(ImplementationEngine.GROOVY);
            corrRule.setType(ImplementationType.PULL_CORRELATION_RULE);
            corrRule.setBody(IOUtils.toString(getClass().getResourceAsStream("/TestPullRule.groovy"), StandardCharsets.UTF_8));
            Response response = implementationService.create(corrRule);
            corrRule = implementationService.read(corrRule.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
            assertNotNull(corrRule);
        }
    }
    assertNotNull(corrRule);
    PullPolicyTO policyTO = policyService.read(PolicyType.PULL, "9454b0d7-2610-400a-be82-fc23cf553dd6");
    policyTO.getCorrelationRules().put(AnyTypeKind.USER.name(), corrRule.getKey());
    policyService.update(PolicyType.PULL, policyTO);
    // -----------------------------
    PullTaskTO task = new PullTaskTO();
    task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
    task.setName("Test Pull Rule");
    task.setActive(true);
    task.setResource(RESOURCE_NAME_WS2);
    task.setPullMode(PullMode.FULL_RECONCILIATION);
    task.setPerformCreate(true);
    task.setPerformDelete(true);
    task.setPerformUpdate(true);
    Response response = taskService.create(TaskType.PULL, task);
    task = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
    UserTO userTO = UserITCase.getUniqueSampleTO("s258_1@apache.org");
    userTO.getResources().clear();
    userTO.getResources().add(RESOURCE_NAME_WS2);
    createUser(userTO);
    userTO = UserITCase.getUniqueSampleTO("s258_2@apache.org");
    userTO.getResources().clear();
    userTO.getResources().add(RESOURCE_NAME_WS2);
    userTO = createUser(userTO).getEntity();
    // change email in order to unmatch the second user
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getPlainAttrs().add(attrAddReplacePatch("email", "s258@apache.org"));
    userService.update(userPatch);
    execProvisioningTask(taskService, TaskType.PULL, task.getKey(), 50, false);
    PullTaskTO executed = taskService.read(TaskType.PULL, task.getKey(), true);
    assertEquals(1, executed.getExecutions().size());
    // asser for just one match
    assertTrue(executed.getExecutions().get(0).getMessage().contains("[updated/failures]: 1/0"), executed.getExecutions().get(0).getMessage().substring(0, 55) + "...");
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) PullPolicyTO(org.apache.syncope.common.lib.policy.PullPolicyTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Aggregations

PullTaskTO (org.apache.syncope.common.lib.to.PullTaskTO)19 Test (org.junit.jupiter.api.Test)15 Response (javax.ws.rs.core.Response)12 ExecTO (org.apache.syncope.common.lib.to.ExecTO)12 UserTO (org.apache.syncope.common.lib.to.UserTO)12 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)11 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)8 TaskService (org.apache.syncope.common.rest.api.service.TaskService)8 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)6 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)6 GroupTO (org.apache.syncope.common.lib.to.GroupTO)5 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)5 TaskTO (org.apache.syncope.common.lib.to.TaskTO)5 TaskType (org.apache.syncope.common.lib.types.TaskType)5 Map (java.util.Map)4 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)4 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)4 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)4 ItemTO (org.apache.syncope.common.lib.to.ItemTO)4 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)4