Search in sources :

Example 46 with ResourceTO

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

the class ResourceITCase method syncToken.

@Test
public void syncToken() {
    ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED);
    resource.setKey(resource.getKey() + getUUIDString());
    AnyObjectTO anyObject = AnyObjectITCase.getSampleTO("syncToken");
    anyObject.getResources().clear();
    anyObject.getResources().add(resource.getKey());
    try {
        // create a new resource
        resource = createResource(resource);
        assertNull(resource.getProvision("PRINTER").get().getSyncToken());
        // create some object on the new resource
        anyObject = createAnyObject(anyObject).getEntity();
        // update sync token
        resourceService.setLatestSyncToken(resource.getKey(), "PRINTER");
        resource = resourceService.read(resource.getKey());
        assertNotNull(resource.getProvision("PRINTER").get().getSyncToken());
        // remove sync token
        resourceService.removeSyncToken(resource.getKey(), "PRINTER");
        resource = resourceService.read(resource.getKey());
        assertNull(resource.getProvision("PRINTER").get().getSyncToken());
    } finally {
        if (anyObject.getKey() != null) {
            anyObjectService.delete(anyObject.getKey());
        }
        resourceService.delete(resource.getKey());
    }
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) Test(org.junit.jupiter.api.Test)

Example 47 with ResourceTO

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

the class ResourceITCase method issueSYNCOPE323.

@Test
public void issueSYNCOPE323() {
    ResourceTO actual = resourceService.read(RESOURCE_NAME_TESTDB);
    assertNotNull(actual);
    try {
        createResource(actual);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.CONFLICT, e.getType().getResponseStatus());
        assertEquals(ClientExceptionType.EntityExists, e.getType());
    }
    actual.setKey(null);
    try {
        createResource(actual);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.BAD_REQUEST, e.getType().getResponseStatus());
        assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
    }
}
Also used : ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 48 with ResourceTO

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

the class GroupITCase method issueSYNCOPE632.

@Test
public void issueSYNCOPE632() {
    DerSchemaTO orig = schemaService.read(SchemaType.DERIVED, "displayProperty");
    DerSchemaTO modified = SerializationUtils.clone(orig);
    modified.setExpression("icon + '_' + show");
    GroupTO groupTO = GroupITCase.getSampleTO("lastGroup");
    try {
        schemaService.update(SchemaType.DERIVED, modified);
        // 0. create group
        groupTO.getPlainAttrs().add(attrTO("icon", "anIcon"));
        groupTO.getPlainAttrs().add(attrTO("show", "true"));
        groupTO.getResources().clear();
        groupTO = createGroup(groupTO).getEntity();
        assertNotNull(groupTO);
        // 1. create new LDAP resource having ConnObjectKey mapped to a derived attribute
        ResourceTO newLDAP = resourceService.read(RESOURCE_NAME_LDAP);
        newLDAP.setKey("new-ldap");
        newLDAP.setPropagationPriority(0);
        for (ProvisionTO provision : newLDAP.getProvisions()) {
            provision.getVirSchemas().clear();
        }
        MappingTO mapping = newLDAP.getProvision(AnyTypeKind.GROUP.name()).get().getMapping();
        ItemTO connObjectKey = mapping.getConnObjectKeyItem();
        connObjectKey.setIntAttrName("displayProperty");
        connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
        mapping.setConnObjectKeyItem(connObjectKey);
        mapping.setConnObjectLink("'cn=' + displayProperty + ',ou=groups,o=isp'");
        ItemTO description = new ItemTO();
        description.setIntAttrName("key");
        description.setExtAttrName("description");
        description.setPurpose(MappingPurpose.PROPAGATION);
        mapping.add(description);
        newLDAP = createResource(newLDAP);
        assertNotNull(newLDAP);
        // 2. update group and give the resource created above
        GroupPatch patch = new GroupPatch();
        patch.setKey(groupTO.getKey());
        patch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value("new-ldap").build());
        groupTO = updateGroup(patch).getEntity();
        assertNotNull(groupTO);
        // 3. update the group
        GroupPatch groupPatch = new GroupPatch();
        groupPatch.setKey(groupTO.getKey());
        groupPatch.getPlainAttrs().add(attrAddReplacePatch("icon", "anotherIcon"));
        groupTO = updateGroup(groupPatch).getEntity();
        assertNotNull(groupTO);
        // 4. check that a single group exists in LDAP for the group created and updated above
        int entries = 0;
        DirContext ctx = null;
        try {
            ctx = getLdapResourceDirContext(null, null);
            SearchControls ctls = new SearchControls();
            ctls.setReturningAttributes(new String[] { "*", "+" });
            ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
            NamingEnumeration<SearchResult> result = ctx.search("ou=groups,o=isp", "(description=" + groupTO.getKey() + ")", ctls);
            while (result.hasMore()) {
                result.next();
                entries++;
            }
        } catch (Exception e) {
        // ignore
        } finally {
            if (ctx != null) {
                try {
                    ctx.close();
                } catch (NamingException e) {
                // ignore
                }
            }
        }
        assertEquals(1, entries);
    } finally {
        schemaService.update(SchemaType.DERIVED, orig);
        if (groupTO.getKey() != null) {
            groupService.delete(groupTO.getKey());
        }
        resourceService.delete("new-ldap");
    }
}
Also used : SearchResult(javax.naming.directory.SearchResult) DirContext(javax.naming.directory.DirContext) ItemTO(org.apache.syncope.common.lib.to.ItemTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NamingException(javax.naming.NamingException) AccessControlException(java.security.AccessControlException) ForbiddenException(javax.ws.rs.ForbiddenException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SearchControls(javax.naming.directory.SearchControls) NamingException(javax.naming.NamingException) Test(org.junit.jupiter.api.Test)

Example 49 with ResourceTO

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

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

the class ConnectorITCase method issueSYNCOPE112.

@Test
public void issueSYNCOPE112() {
    // ----------------------------------------
    // Create a new connector
    // ----------------------------------------
    ConnInstanceTO connectorTO = new ConnInstanceTO();
    connectorTO.setAdminRealm(SyncopeConstants.ROOT_REALM);
    connectorTO.setLocation(connectorService.read("88a7a819-dab5-46b4-9b90-0b9769eabdb8", Locale.ENGLISH.getLanguage()).getLocation());
    // set connector version
    connectorTO.setVersion(connIdSoapVersion);
    // set connector name
    connectorTO.setConnectorName("net.tirasa.connid.bundles.soap.WebServiceConnector");
    // set bundle name
    connectorTO.setBundleName("net.tirasa.connid.bundles.soap");
    // set display name
    connectorTO.setDisplayName("WSSoap");
    // set the connector configuration using PropertyTO
    Set<ConnConfProperty> conf = new HashSet<>();
    ConnConfPropSchema userSchema = new ConnConfPropSchema();
    userSchema.setName("endpoint");
    userSchema.setType(String.class.getName());
    userSchema.setRequired(true);
    ConnConfProperty endpoint = new ConnConfProperty();
    endpoint.setSchema(userSchema);
    endpoint.getValues().add("http://localhost:9080/does_not_work");
    endpoint.setOverridable(true);
    ConnConfPropSchema keyColumnSchema = new ConnConfPropSchema();
    keyColumnSchema.setName("servicename");
    keyColumnSchema.setType(String.class.getName());
    keyColumnSchema.setRequired(true);
    ConnConfProperty servicename = new ConnConfProperty();
    servicename.setSchema(keyColumnSchema);
    servicename.getValues().add("net.tirasa.connid.bundles.soap.provisioning.interfaces.Provisioning");
    servicename.setOverridable(false);
    conf.add(endpoint);
    conf.add(servicename);
    // set connector configuration
    connectorTO.getConf().addAll(conf);
    try {
        try {
            connectorService.check(connectorTO);
            fail("This should not happen");
        } catch (Exception e) {
            assertNotNull(e);
        }
        Response response = connectorService.create(connectorTO);
        if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
            throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
        }
        connectorTO = getObject(response.getLocation(), ConnectorService.class, ConnInstanceTO.class);
        assertNotNull(connectorTO);
        // ----------------------------------------
        // ----------------------------------------
        // create a resourceTO
        // ----------------------------------------
        String resourceName = "checkForPropOverriding";
        ResourceTO resourceTO = new ResourceTO();
        resourceTO.setKey(resourceName);
        resourceTO.setConnector(connectorTO.getKey());
        conf = new HashSet<>();
        endpoint.getValues().clear();
        endpoint.getValues().add("http://localhost:9080/syncope-fit-build-tools/cxf/soap/provisioning");
        conf.add(endpoint);
        resourceTO.getConfOverride().addAll(conf);
        ProvisionTO provisionTO = new ProvisionTO();
        provisionTO.setAnyType(AnyTypeKind.USER.name());
        provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
        resourceTO.getProvisions().add(provisionTO);
        MappingTO mapping = new MappingTO();
        provisionTO.setMapping(mapping);
        ItemTO mapItem = new ItemTO();
        mapItem.setExtAttrName("uid");
        mapItem.setIntAttrName("userId");
        mapItem.setConnObjectKey(true);
        mapping.setConnObjectKeyItem(mapItem);
        // ----------------------------------------
        try {
            resourceService.check(resourceTO);
        } catch (Exception e) {
            fail(ExceptionUtils.getStackTrace(e));
        }
    // ----------------------------------------
    } finally {
        // Remove connector from db to make test re-runnable
        connectorService.delete(connectorTO.getKey());
    }
}
Also used : ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) GuardedString(org.identityconnectors.common.security.GuardedString) ItemTO(org.apache.syncope.common.lib.to.ItemTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) IOException(java.io.IOException) ConnectorService(org.apache.syncope.common.rest.api.service.ConnectorService) Response(javax.ws.rs.core.Response) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ConnConfPropSchema(org.apache.syncope.common.lib.types.ConnConfPropSchema) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)61 Test (org.junit.jupiter.api.Test)49 ItemTO (org.apache.syncope.common.lib.to.ItemTO)32 ProvisionTO (org.apache.syncope.common.lib.to.ProvisionTO)29 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)27 Response (javax.ws.rs.core.Response)23 MappingTO (org.apache.syncope.common.lib.to.MappingTO)23 UserTO (org.apache.syncope.common.lib.to.UserTO)17 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)14 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)12 ResourceService (org.apache.syncope.common.rest.api.service.ResourceService)11 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)10 GroupTO (org.apache.syncope.common.lib.to.GroupTO)10 ConnConfProperty (org.apache.syncope.common.lib.types.ConnConfProperty)9 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)9 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)8 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)8 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)8 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)8 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)8