Search in sources :

Example 1 with ConnPoolConfTO

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

the class ConnInstanceDataBinderImpl method getConnInstanceTO.

@Override
public ConnInstanceTO getConnInstanceTO(final ConnInstance connInstance) {
    ConnInstanceTO connInstanceTO = new ConnInstanceTO();
    Pair<URI, ConnectorInfo> info = connIdBundleManager.getConnectorInfo(connInstance);
    BeanUtils.copyProperties(connInstance, connInstanceTO, IGNORE_PROPERTIES);
    connInstanceTO.setAdminRealm(connInstance.getAdminRealm().getFullPath());
    connInstanceTO.setLocation(info.getLeft().toASCIIString());
    connInstanceTO.getConf().addAll(connInstance.getConf());
    // refresh stored properties in the given connInstance with direct information from underlying connector
    ConfigurationProperties properties = connIdBundleManager.getConfigurationProperties(info.getRight());
    properties.getPropertyNames().forEach(propName -> {
        ConnConfPropSchema schema = build(properties.getProperty(propName));
        Optional<ConnConfProperty> property = connInstanceTO.getConf(propName);
        if (!property.isPresent()) {
            property = Optional.of(new ConnConfProperty());
            connInstanceTO.getConf().add(property.get());
        }
        property.get().setSchema(schema);
    });
    Collections.sort(connInstanceTO.getConf());
    // pool configuration
    if (connInstance.getPoolConf() != null && (connInstance.getPoolConf().getMaxIdle() != null || connInstance.getPoolConf().getMaxObjects() != null || connInstance.getPoolConf().getMaxWait() != null || connInstance.getPoolConf().getMinEvictableIdleTimeMillis() != null || connInstance.getPoolConf().getMinIdle() != null)) {
        ConnPoolConfTO poolConf = new ConnPoolConfTO();
        BeanUtils.copyProperties(connInstance.getPoolConf(), poolConf);
        connInstanceTO.setPoolConf(poolConf);
    }
    return connInstanceTO;
}
Also used : ConnectorInfo(org.identityconnectors.framework.api.ConnectorInfo) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) ConfigurationProperties(org.identityconnectors.framework.api.ConfigurationProperties) ConnPoolConfTO(org.apache.syncope.common.lib.to.ConnPoolConfTO) URI(java.net.URI) ConnConfPropSchema(org.apache.syncope.common.lib.types.ConnConfPropSchema)

Example 2 with ConnPoolConfTO

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

the class LoggerITCase method customAuditAppender.

@Test
public void customAuditAppender() throws IOException, InterruptedException {
    try (InputStream propStream = getClass().getResourceAsStream("/core-test.properties")) {
        Properties props = new Properties();
        props.load(propStream);
        String auditFilePath = props.getProperty("test.log.dir") + File.separator + "audit_for_Master_file.log";
        String auditNoRewriteFilePath = props.getProperty("test.log.dir") + File.separator + "audit_for_Master_norewrite_file.log";
        // 1. Enable audit for resource update -> catched by FileRewriteAuditAppender
        AuditLoggerName auditLoggerResUpd = new AuditLoggerName(EventCategoryType.LOGIC, ResourceLogic.class.getSimpleName(), null, "update", AuditElements.Result.SUCCESS);
        LoggerTO loggerTOUpd = new LoggerTO();
        loggerTOUpd.setKey(auditLoggerResUpd.toLoggerName());
        loggerTOUpd.setLevel(LoggerLevel.DEBUG);
        loggerService.update(LoggerType.AUDIT, loggerTOUpd);
        // 2. Enable audit for connector update -> NOT catched by FileRewriteAuditAppender
        AuditLoggerName auditLoggerConnUpd = new AuditLoggerName(EventCategoryType.LOGIC, ConnectorLogic.class.getSimpleName(), null, "update", AuditElements.Result.SUCCESS);
        LoggerTO loggerTOConnUpd = new LoggerTO();
        loggerTOConnUpd.setKey(auditLoggerConnUpd.toLoggerName());
        loggerTOConnUpd.setLevel(LoggerLevel.DEBUG);
        loggerService.update(LoggerType.AUDIT, loggerTOConnUpd);
        // 3. check that resource update is transformed and logged onto an audit file.
        ResourceTO resource = resourceService.read(RESOURCE_NAME_CSV);
        assertNotNull(resource);
        resource.setPropagationPriority(100);
        resourceService.update(resource);
        ConnInstanceTO connector = connectorService.readByResource(RESOURCE_NAME_CSV, null);
        assertNotNull(connector);
        connector.setPoolConf(new ConnPoolConfTO());
        connectorService.update(connector);
        File auditTempFile = new File(auditFilePath);
        // check audit_for_Master_file.log, it should contain only a static message
        String auditLog = FileUtils.readFileToString(auditTempFile, Charset.defaultCharset());
        assertTrue(StringUtils.contains(auditLog, "DEBUG Master.syncope.audit.[LOGIC]:[ResourceLogic]:[]:[update]:[SUCCESS]" + " - This is a static test message"));
        File auditNoRewriteTempFile = new File(auditNoRewriteFilePath);
        // check audit_for_Master_file.log, it should contain only a static message
        String auditLogNoRewrite = FileUtils.readFileToString(auditNoRewriteTempFile, Charset.defaultCharset());
        assertFalse(StringUtils.contains(auditLogNoRewrite, "DEBUG Master.syncope.audit.[LOGIC]:[ResourceLogic]:[]:[update]:[SUCCESS]" + " - This is a static test message"));
        // clean audit_for_Master_file.log
        FileUtils.writeStringToFile(auditTempFile, StringUtils.EMPTY, Charset.defaultCharset());
        loggerService.delete(LoggerType.AUDIT, "syncope.audit.[LOGIC]:[ResourceLogic]:[]:[update]:[SUCCESS]");
        resource = resourceService.read(RESOURCE_NAME_CSV);
        assertNotNull(resource);
        resource.setPropagationPriority(200);
        resourceService.update(resource);
        // check that nothing has been written to audit_for_Master_file.log
        assertTrue(StringUtils.isEmpty(FileUtils.readFileToString(auditTempFile, Charset.defaultCharset())));
    } catch (IOException e) {
        fail("Unable to read/write log files" + e.getMessage());
    }
}
Also used : LoggerTO(org.apache.syncope.common.lib.log.LoggerTO) ResourceLogic(org.apache.syncope.core.logic.ResourceLogic) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) InputStream(java.io.InputStream) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ConnPoolConfTO(org.apache.syncope.common.lib.to.ConnPoolConfTO) IOException(java.io.IOException) Properties(java.util.Properties) ConnectorLogic(org.apache.syncope.core.logic.ConnectorLogic) File(java.io.File) AuditLoggerName(org.apache.syncope.common.lib.types.AuditLoggerName) Test(org.junit.jupiter.api.Test)

Example 3 with ConnPoolConfTO

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

Aggregations

ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)3 ConnPoolConfTO (org.apache.syncope.common.lib.to.ConnPoolConfTO)3 ConnConfPropSchema (org.apache.syncope.common.lib.types.ConnConfPropSchema)2 ConnConfProperty (org.apache.syncope.common.lib.types.ConnConfProperty)2 Test (org.junit.jupiter.api.Test)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Response (javax.ws.rs.core.Response)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 LoggerTO (org.apache.syncope.common.lib.log.LoggerTO)1 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)1 AuditLoggerName (org.apache.syncope.common.lib.types.AuditLoggerName)1 ConnectorLogic (org.apache.syncope.core.logic.ConnectorLogic)1 ResourceLogic (org.apache.syncope.core.logic.ResourceLogic)1 GuardedString (org.identityconnectors.common.security.GuardedString)1 ConfigurationProperties (org.identityconnectors.framework.api.ConfigurationProperties)1