Search in sources :

Example 31 with ConnInstanceTO

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

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

the class AbstractITCase method getLdapResourceDirContext.

@SuppressWarnings({ "unchecked", "rawtypes", "UseOfObsoleteCollectionType" })
protected InitialDirContext getLdapResourceDirContext(final String bindDn, final String bindPwd) throws NamingException {
    ResourceTO ldapRes = resourceService.read(RESOURCE_NAME_LDAP);
    ConnInstanceTO ldapConn = connectorService.read(ldapRes.getConnector(), Locale.ENGLISH.getLanguage());
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://" + ldapConn.getConf("host").get().getValues().get(0) + ":" + ldapConn.getConf("port").get().getValues().get(0) + "/");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, bindDn == null ? ldapConn.getConf("principal").get().getValues().get(0) : bindDn);
    env.put(Context.SECURITY_CREDENTIALS, bindPwd == null ? ldapConn.getConf("credentials").get().getValues().get(0) : bindPwd);
    return new InitialDirContext(env);
}
Also used : ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) InitialDirContext(javax.naming.directory.InitialDirContext) Properties(java.util.Properties)

Example 33 with ConnInstanceTO

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

the class ConnectorServiceImpl method create.

@Override
public Response create(final ConnInstanceTO connInstanceTO) {
    ConnInstanceTO connInstance = logic.create(connInstanceTO);
    URI location = uriInfo.getAbsolutePathBuilder().path(connInstance.getKey()).build();
    return Response.created(location).header(RESTHeaders.RESOURCE_KEY, connInstance.getKey()).build();
}
Also used : ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) URI(java.net.URI)

Example 34 with ConnInstanceTO

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

the class ConnectorDetails method details.

public void details() {
    if (input.parameterNumber() == 0) {
        try {
            final Map<String, String> details = new LinkedHashMap<>();
            final List<ConnInstanceTO> connInstanceTOs = connectorSyncopeOperations.list();
            int withCreateCapability = 0;
            int withDeleteCapability = 0;
            int withSearchCapability = 0;
            int withSyncCapability = 0;
            int withUpdateCapability = 0;
            for (final ConnInstanceTO connInstanceTO : connInstanceTOs) {
                if (connInstanceTO.getCapabilities().contains(ConnectorCapability.CREATE)) {
                    withCreateCapability++;
                }
                if (connInstanceTO.getCapabilities().contains(ConnectorCapability.DELETE)) {
                    withDeleteCapability++;
                }
                if (connInstanceTO.getCapabilities().contains(ConnectorCapability.SEARCH)) {
                    withSearchCapability++;
                }
                if (connInstanceTO.getCapabilities().contains(ConnectorCapability.SYNC)) {
                    withSyncCapability++;
                }
                if (connInstanceTO.getCapabilities().contains(ConnectorCapability.UPDATE)) {
                    withUpdateCapability++;
                }
            }
            details.put("Total number", String.valueOf(connInstanceTOs.size()));
            details.put("With create capability", String.valueOf(withCreateCapability));
            details.put("With delete capability", String.valueOf(withDeleteCapability));
            details.put("With search capability", String.valueOf(withSearchCapability));
            details.put("With sync capability", String.valueOf(withSyncCapability));
            details.put("With update capability", String.valueOf(withUpdateCapability));
            details.put("Bundles number", String.valueOf(connectorSyncopeOperations.getBundles().size()));
            connectorResultManager.printDetails(details);
        } catch (final SyncopeClientException ex) {
            LOG.error("Error reading details about connector", ex);
            connectorResultManager.genericError(ex.getMessage());
        }
    } else {
        connectorResultManager.unnecessaryParameters(input.listParameters(), DETAILS_HELP_MESSAGE);
    }
}
Also used : ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) LinkedHashMap(java.util.LinkedHashMap)

Example 35 with ConnInstanceTO

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

the class HistoryConfDetails method addCurrentInstanceConf.

@SuppressWarnings("unchecked")
private void addCurrentInstanceConf() {
    T conf = null;
    if (selectedHistoryConfTO instanceof ConnInstanceHistoryConfTO) {
        ConnInstanceTO current = new ConnectorRestClient().read(ConnInstanceHistoryConfTO.class.cast(selectedHistoryConfTO).getConnInstanceTO().getKey());
        conf = (T) new ConnInstanceHistoryConfTO();
        ((ConnInstanceHistoryConfTO) conf).setConnInstanceTO(current);
    } else if (selectedHistoryConfTO instanceof ResourceHistoryConfTO) {
        ResourceTO current = new ResourceRestClient().read(ResourceHistoryConfTO.class.cast(selectedHistoryConfTO).getResourceTO().getKey());
        conf = (T) new ResourceHistoryConfTO();
        ((ResourceHistoryConfTO) conf).setResourceTO(current);
    }
    if (conf != null) {
        conf.setCreator(selectedHistoryConfTO.getCreator());
        conf.setKey("current");
        availableHistoryConfTOs.add(conf);
    }
}
Also used : ConnectorRestClient(org.apache.syncope.client.console.rest.ConnectorRestClient) ResourceHistoryConfTO(org.apache.syncope.common.lib.to.ResourceHistoryConfTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ConnInstanceHistoryConfTO(org.apache.syncope.common.lib.to.ConnInstanceHistoryConfTO) ResourceRestClient(org.apache.syncope.client.console.rest.ResourceRestClient)

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