Search in sources :

Example 1 with ConnInstanceTO

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

the class ConnectorWizardBuilder method buildModelSteps.

@Override
protected WizardModel buildModelSteps(final Serializable modelObject, final WizardModel wizardModel) {
    ConnInstanceTO connInstanceTO = ConnInstanceTO.class.cast(modelObject);
    wizardModel.add(new ConnectorDetailsPanel(connInstanceTO, bundles));
    wizardModel.add(new ConnectorConfPanel(connInstanceTO, bundles) {

        private static final long serialVersionUID = -5886691077681158494L;

        @Override
        protected Pair<Boolean, String> check(final AjaxRequestTarget target) {
            ConnInstanceTO connInstanceTO = ConnInstanceTO.class.cast(modelObject);
            ConnBundleTO bundleTO = ConnectorWizardBuilder.getBundle(connInstanceTO, bundles);
            connInstanceTO.setConnectorName(bundleTO.getConnectorName());
            connInstanceTO.setBundleName(bundleTO.getBundleName());
            connInstanceTO.setVersion(bundleTO.getVersion());
            return connectorRestClient.check(connInstanceTO);
        }

        @Override
        protected void onComponentTag(final ComponentTag tag) {
            tag.append("class", "scrollable-tab-content", " ");
        }
    });
    wizardModel.add(new ConnCapabilitiesPanel(new PropertyModel<>(connInstanceTO, "capabilities")));
    return wizardModel;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ConnBundleTO(org.apache.syncope.common.lib.to.ConnBundleTO) ComponentTag(org.apache.wicket.markup.ComponentTag) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) PropertyModel(org.apache.wicket.model.PropertyModel) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with ConnInstanceTO

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

the class ConnectorWizardBuilder method onApplyInternal.

@Override
protected Serializable onApplyInternal(final Serializable modelObject) {
    ConnInstanceTO connInstanceTO = ConnInstanceTO.class.cast(modelObject);
    ConnBundleTO bundleTO = ConnectorWizardBuilder.getBundle(connInstanceTO, bundles);
    connInstanceTO.setConnectorName(bundleTO.getConnectorName());
    connInstanceTO.setBundleName(bundleTO.getBundleName());
    connInstanceTO.setVersion(bundleTO.getVersion());
    // Reset pool configuration if all fields are null
    if (connInstanceTO.getPoolConf() != null && connInstanceTO.getPoolConf().getMaxIdle() == null && connInstanceTO.getPoolConf().getMaxObjects() == null && connInstanceTO.getPoolConf().getMaxWait() == null && connInstanceTO.getPoolConf().getMinEvictableIdleTimeMillis() == null && connInstanceTO.getPoolConf().getMinIdle() == null) {
        connInstanceTO.setPoolConf(null);
    }
    ConnInstanceTO res;
    if (mode == AjaxWizard.Mode.CREATE) {
        res = connectorRestClient.create(connInstanceTO);
    } else {
        connectorRestClient.update(connInstanceTO);
        res = connInstanceTO;
    }
    return res;
}
Also used : ConnBundleTO(org.apache.syncope.common.lib.to.ConnBundleTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO)

Example 3 with ConnInstanceTO

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

the class VirAttrITCase method issueSYNCOPE442.

@Test
public void issueSYNCOPE442() {
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope442@apache.org");
    userTO.getVirAttrs().clear();
    AttrTO virAttrTO = new AttrTO();
    virAttrTO.setSchema("virtualdata");
    virAttrTO.getValues().add("virattrcache");
    userTO.getVirAttrs().add(virAttrTO);
    userTO.getMemberships().clear();
    userTO.getResources().clear();
    userTO.getResources().add(RESOURCE_NAME_DBVIRATTR);
    // 1. create user
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    // 2. check for virtual attribute value
    userTO = userService.read(userTO.getKey());
    assertEquals("virattrcache", userTO.getVirAttr("virtualdata").get().getValues().get(0));
    // ----------------------------------------
    // 3. change connector URL so that we are sure that any provided value will come from virtual cache
    // ----------------------------------------
    String jdbcURL = null;
    ConnInstanceTO connInstanceTO = connectorService.readByResource(RESOURCE_NAME_DBVIRATTR, Locale.ENGLISH.getLanguage());
    for (ConnConfProperty prop : connInstanceTO.getConf()) {
        if ("jdbcUrlTemplate".equals(prop.getSchema().getName())) {
            jdbcURL = prop.getValues().iterator().next().toString();
            prop.getValues().clear();
            prop.getValues().add("jdbc:h2:tcp://localhost:9092/xxx");
        }
    }
    connectorService.update(connInstanceTO);
    // ----------------------------------------
    // ----------------------------------------
    // 4. update value on external resource
    // ----------------------------------------
    JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
    String value = queryForObject(jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, userTO.getKey());
    assertEquals("virattrcache", value);
    jdbcTemplate.update("UPDATE testpull set USERNAME='virattrcache2' WHERE ID=?", userTO.getKey());
    value = queryForObject(jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, userTO.getKey());
    assertEquals("virattrcache2", value);
    // ----------------------------------------
    userTO = userService.read(userTO.getKey());
    assertEquals("virattrcache", userTO.getVirAttr("virtualdata").get().getValues().get(0));
    // ----------------------------------------
    for (ConnConfProperty prop : connInstanceTO.getConf()) {
        if ("jdbcUrlTemplate".equals(prop.getSchema().getName())) {
            prop.getValues().clear();
            prop.getValues().add(jdbcURL);
        }
    }
    connectorService.update(connInstanceTO);
    // ----------------------------------------
    // cached value still in place...
    userTO = userService.read(userTO.getKey());
    assertEquals("virattrcache", userTO.getVirAttr("virtualdata").get().getValues().get(0));
    // force cache update by adding a resource which has virtualdata mapped for propagation
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_WS2).build());
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
    userTO = userService.read(userTO.getKey());
    assertEquals("virattrcache2", userTO.getVirAttr("virtualdata").get().getValues().get(0));
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 4 with ConnInstanceTO

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

use of org.apache.syncope.common.lib.to.ConnInstanceTO 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)

Aggregations

ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)42 Test (org.junit.jupiter.api.Test)21 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)15 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)14 ConnConfProperty (org.apache.syncope.common.lib.types.ConnConfProperty)14 ConnectorService (org.apache.syncope.common.rest.api.service.ConnectorService)11 Response (javax.ws.rs.core.Response)10 HashSet (java.util.HashSet)8 ConnConfPropSchema (org.apache.syncope.common.lib.types.ConnConfPropSchema)8 GuardedString (org.identityconnectors.common.security.GuardedString)8 IOException (java.io.IOException)7 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 ConnBundleTO (org.apache.syncope.common.lib.to.ConnBundleTO)6 ConnPoolConfTO (org.apache.syncope.common.lib.to.ConnPoolConfTO)6 ItemTO (org.apache.syncope.common.lib.to.ItemTO)6 ProvisionTO (org.apache.syncope.common.lib.to.ProvisionTO)6 Locale (java.util.Locale)5 Properties (java.util.Properties)5