Search in sources :

Example 11 with ConnConfProperty

use of org.apache.syncope.common.lib.types.ConnConfProperty in project syncope by apache.

the class ConnectorITCase method validate.

@Test
public void validate() {
    ConnInstanceTO connectorTO = new ConnInstanceTO();
    connectorTO.setAdminRealm(SyncopeConstants.ROOT_REALM);
    connectorTO.setLocation(connectorServerLocation);
    connectorTO.setVersion(connIdDbVersion);
    connectorTO.setConnectorName("net.tirasa.connid.bundles.db.table.DatabaseTableConnector");
    connectorTO.setBundleName("net.tirasa.connid.bundles.db.table");
    connectorTO.setDisplayName("H2Test");
    // set the connector configuration using PropertyTO
    Set<ConnConfProperty> conf = new HashSet<>();
    ConnConfPropSchema jdbcDriverSchema = new ConnConfPropSchema();
    jdbcDriverSchema.setName("jdbcDriver");
    jdbcDriverSchema.setType(String.class.getName());
    jdbcDriverSchema.setRequired(true);
    ConnConfProperty jdbcDriver = new ConnConfProperty();
    jdbcDriver.setSchema(jdbcDriverSchema);
    jdbcDriver.getValues().add("org.h2.Driver");
    conf.add(jdbcDriver);
    ConnConfPropSchema jdbcUrlTemplateSchema = new ConnConfPropSchema();
    jdbcUrlTemplateSchema.setName("jdbcUrlTemplate");
    jdbcUrlTemplateSchema.setType(String.class.getName());
    jdbcUrlTemplateSchema.setRequired(true);
    ConnConfProperty jdbcUrlTemplate = new ConnConfProperty();
    jdbcUrlTemplate.setSchema(jdbcUrlTemplateSchema);
    jdbcUrlTemplate.getValues().add(testJDBCURL);
    conf.add(jdbcUrlTemplate);
    ConnConfPropSchema userSchema = new ConnConfPropSchema();
    userSchema.setName("user");
    userSchema.setType(String.class.getName());
    userSchema.setRequired(false);
    ConnConfProperty user = new ConnConfProperty();
    user.setSchema(userSchema);
    user.getValues().add("sa");
    conf.add(user);
    ConnConfPropSchema passwordSchema = new ConnConfPropSchema();
    passwordSchema.setName("password");
    passwordSchema.setType(GuardedString.class.getName());
    passwordSchema.setRequired(true);
    ConnConfProperty password = new ConnConfProperty();
    password.setSchema(passwordSchema);
    password.getValues().add("sa");
    conf.add(password);
    ConnConfPropSchema tableSchema = new ConnConfPropSchema();
    tableSchema.setName("table");
    tableSchema.setType(String.class.getName());
    tableSchema.setRequired(true);
    ConnConfProperty table = new ConnConfProperty();
    table.setSchema(tableSchema);
    table.getValues().add("test");
    conf.add(table);
    ConnConfPropSchema keyColumnSchema = new ConnConfPropSchema();
    keyColumnSchema.setName("keyColumn");
    keyColumnSchema.setType(String.class.getName());
    keyColumnSchema.setRequired(true);
    ConnConfProperty keyColumn = new ConnConfProperty();
    keyColumn.setSchema(keyColumnSchema);
    keyColumn.getValues().add("id");
    conf.add(keyColumn);
    ConnConfPropSchema passwordColumnSchema = new ConnConfPropSchema();
    passwordColumnSchema.setName("passwordColumn");
    passwordColumnSchema.setType(String.class.getName());
    passwordColumnSchema.setRequired(true);
    ConnConfProperty passwordColumn = new ConnConfProperty();
    passwordColumn.setSchema(passwordColumnSchema);
    passwordColumn.getValues().add("password");
    conf.add(passwordColumn);
    // set connector configuration
    connectorTO.getConf().addAll(conf);
    try {
        connectorService.check(connectorTO);
    } catch (Exception e) {
        fail(ExceptionUtils.getStackTrace(e));
    }
    conf.remove(password);
    password.getValues().clear();
    password.getValues().add("password");
    conf.add(password);
    try {
        connectorService.check(connectorTO);
        fail("This should not happen");
    } catch (Exception e) {
        assertNotNull(e);
    }
}
Also used : ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) GuardedString(org.identityconnectors.common.security.GuardedString) GuardedString(org.identityconnectors.common.security.GuardedString) ConnConfPropSchema(org.apache.syncope.common.lib.types.ConnConfPropSchema) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) IOException(java.io.IOException) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 12 with ConnConfProperty

use of org.apache.syncope.common.lib.types.ConnConfProperty in project syncope by apache.

the class ConnectorITCase method checkHiddenProperty.

@Test
public void checkHiddenProperty() {
    ConnInstanceTO connInstanceTO = connectorService.read("88a7a819-dab5-46b4-9b90-0b9769eabdb8", Locale.ENGLISH.getLanguage());
    boolean check = false;
    for (ConnConfProperty prop : connInstanceTO.getConf()) {
        if ("receiveTimeout".equals(prop.getSchema().getName())) {
            check = true;
        }
    }
    assertTrue(check);
}
Also used : ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) Test(org.junit.jupiter.api.Test)

Example 13 with ConnConfProperty

use of org.apache.syncope.common.lib.types.ConnConfProperty in project syncope by apache.

the class ConnectorITCase method create.

@Test
public void create() {
    ConnInstanceTO connectorTO = new ConnInstanceTO();
    connectorTO.setAdminRealm(SyncopeConstants.ROOT_REALM);
    connectorTO.setLocation(connectorService.read("88a7a819-dab5-46b4-9b90-0b9769eabdb8", Locale.ENGLISH.getLanguage()).getLocation());
    connectorTO.setVersion(connIdSoapVersion);
    connectorTO.setConnectorName("net.tirasa.connid.bundles.soap.WebServiceConnector");
    connectorTO.setBundleName("net.tirasa.connid.bundles.soap");
    connectorTO.setDisplayName("Display name");
    connectorTO.setConnRequestTimeout(15);
    // set the connector configuration using PropertyTO
    Set<ConnConfProperty> conf = new HashSet<>();
    ConnConfPropSchema endpointSchema = new ConnConfPropSchema();
    endpointSchema.setName("endpoint");
    endpointSchema.setType(String.class.getName());
    endpointSchema.setRequired(true);
    ConnConfProperty endpoint = new ConnConfProperty();
    endpoint.setSchema(endpointSchema);
    endpoint.getValues().add("http://localhost:8888/syncope-fit-build-tools/cxf/soap");
    endpoint.getValues().add("Provisioning");
    conf.add(endpoint);
    ConnConfPropSchema servicenameSchema = new ConnConfPropSchema();
    servicenameSchema.setName("servicename");
    servicenameSchema.setType(String.class.getName());
    servicenameSchema.setRequired(true);
    ConnConfProperty servicename = new ConnConfProperty();
    servicename.setSchema(servicenameSchema);
    conf.add(servicename);
    // set connector configuration
    connectorTO.getConf().addAll(conf);
    // set connector capabilities
    connectorTO.getCapabilities().add(ConnectorCapability.CREATE);
    connectorTO.getCapabilities().add(ConnectorCapability.UPDATE);
    // set connector pool conf
    ConnPoolConfTO cpc = new ConnPoolConfTO();
    cpc.setMaxObjects(1534);
    connectorTO.setPoolConf(cpc);
    Response response = connectorService.create(connectorTO);
    if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
        throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
    }
    ConnInstanceTO actual = getObject(response.getLocation(), ConnectorService.class, ConnInstanceTO.class);
    assertNotNull(actual);
    assertEquals(actual.getBundleName(), connectorTO.getBundleName());
    assertEquals(actual.getConnectorName(), connectorTO.getConnectorName());
    assertEquals(actual.getVersion(), connectorTO.getVersion());
    assertEquals("Display name", actual.getDisplayName());
    assertEquals(Integer.valueOf(15), actual.getConnRequestTimeout());
    assertEquals(connectorTO.getCapabilities(), actual.getCapabilities());
    assertNotNull(actual.getPoolConf());
    assertEquals(1534, actual.getPoolConf().getMaxObjects().intValue());
    assertEquals(10, actual.getPoolConf().getMaxIdle().intValue());
    Throwable t = null;
    // check update
    actual.getCapabilities().remove(ConnectorCapability.UPDATE);
    actual.getPoolConf().setMaxObjects(null);
    try {
        connectorService.update(actual);
        actual = connectorService.read(actual.getKey(), Locale.ENGLISH.getLanguage());
    } catch (SyncopeClientException e) {
        LOG.error("update failed", e);
        t = e;
    }
    assertNull(t);
    assertNotNull(actual);
    assertEquals(EnumSet.of(ConnectorCapability.CREATE), actual.getCapabilities());
    assertEquals(10, actual.getPoolConf().getMaxObjects().intValue());
    // check also for the deletion of the created object
    try {
        connectorService.delete(actual.getKey());
    } catch (SyncopeClientException e) {
        LOG.error("delete failed", e);
        t = e;
    }
    assertNull(t);
    // check the non existence
    try {
        connectorService.read(actual.getKey(), Locale.ENGLISH.getLanguage());
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
    }
}
Also used : Response(javax.ws.rs.core.Response) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) GuardedString(org.identityconnectors.common.security.GuardedString) ConnPoolConfTO(org.apache.syncope.common.lib.to.ConnPoolConfTO) ConnConfPropSchema(org.apache.syncope.common.lib.types.ConnConfPropSchema) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 14 with ConnConfProperty

use of org.apache.syncope.common.lib.types.ConnConfProperty in project syncope by apache.

the class ConnectorManager method buildConnInstanceOverride.

@Override
public ConnInstance buildConnInstanceOverride(final ConnInstanceTO connInstance, final Collection<ConnConfProperty> confOverride, final Collection<ConnectorCapability> capabilitiesOverride) {
    synchronized (this) {
        if (entityFactory == null) {
            entityFactory = ApplicationContextProvider.getApplicationContext().getBean(EntityFactory.class);
        }
    }
    ConnInstance override = entityFactory.newEntity(ConnInstance.class);
    override.setAdminRealm(realmDAO.findByFullPath(connInstance.getAdminRealm()));
    override.setConnectorName(connInstance.getConnectorName());
    override.setDisplayName(connInstance.getDisplayName());
    override.setBundleName(connInstance.getBundleName());
    override.setVersion(connInstance.getVersion());
    override.setLocation(connInstance.getLocation());
    override.setConf(connInstance.getConf());
    override.getCapabilities().addAll(connInstance.getCapabilities());
    override.setConnRequestTimeout(connInstance.getConnRequestTimeout());
    Map<String, ConnConfProperty> overridable = new HashMap<>();
    Set<ConnConfProperty> conf = new HashSet<>();
    for (ConnConfProperty prop : override.getConf()) {
        if (prop.isOverridable()) {
            overridable.put(prop.getSchema().getName(), prop);
        } else {
            conf.add(prop);
        }
    }
    // add override properties
    for (ConnConfProperty prop : confOverride) {
        if (overridable.containsKey(prop.getSchema().getName()) && !prop.getValues().isEmpty()) {
            conf.add(prop);
            overridable.remove(prop.getSchema().getName());
        }
    }
    // add override properties not substituted
    conf.addAll(overridable.values());
    override.setConf(conf);
    // replace capabilities
    if (capabilitiesOverride != null) {
        override.getCapabilities().clear();
        override.getCapabilities().addAll(capabilitiesOverride);
    }
    return override;
}
Also used : HashMap(java.util.HashMap) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) HashSet(java.util.HashSet)

Example 15 with ConnConfProperty

use of org.apache.syncope.common.lib.types.ConnConfProperty in project syncope by apache.

the class ConnectorRestClient method filterProperties.

private List<ConnConfProperty> filterProperties(final Collection<ConnConfProperty> properties) {
    List<ConnConfProperty> newProperties = new ArrayList<>();
    properties.stream().map(property -> {
        ConnConfProperty prop = new ConnConfProperty();
        prop.setSchema(property.getSchema());
        prop.setOverridable(property.isOverridable());
        final List<Object> parsed = new ArrayList<>();
        if (property.getValues() != null) {
            property.getValues().stream().filter(obj -> (obj != null && !obj.toString().isEmpty())).forEachOrdered((obj) -> {
                parsed.add(obj);
            });
        }
        prop.getValues().addAll(parsed);
        return prop;
    }).forEachOrdered(prop -> {
        newProperties.add(prop);
    });
    return newProperties;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Collection(java.util.Collection) SyncopeConsoleSession(org.apache.syncope.client.console.SyncopeConsoleSession) ConnIdObjectClassTO(org.apache.syncope.common.lib.to.ConnIdObjectClassTO) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) List(java.util.List) Response(javax.ws.rs.core.Response) Pair(org.apache.commons.lang3.tuple.Pair) Optional(java.util.Optional) ConnectorService(org.apache.syncope.common.rest.api.service.ConnectorService) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) Collections(java.util.Collections) ConnBundleTO(org.apache.syncope.common.lib.to.ConnBundleTO) BeanUtils(org.springframework.beans.BeanUtils) ArrayList(java.util.ArrayList) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ConnConfProperty (org.apache.syncope.common.lib.types.ConnConfProperty)18 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)13 Test (org.junit.jupiter.api.Test)12 HashSet (java.util.HashSet)9 Response (javax.ws.rs.core.Response)9 ConnConfPropSchema (org.apache.syncope.common.lib.types.ConnConfPropSchema)8 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)7 ConnectorService (org.apache.syncope.common.rest.api.service.ConnectorService)6 GuardedString (org.identityconnectors.common.security.GuardedString)6 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)5 IOException (java.io.IOException)4 Collection (java.util.Collection)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ConnBundleTO (org.apache.syncope.common.lib.to.ConnBundleTO)3 ConnIdObjectClassTO (org.apache.syncope.common.lib.to.ConnIdObjectClassTO)3 ConnPoolConfTO (org.apache.syncope.common.lib.to.ConnPoolConfTO)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Optional (java.util.Optional)2