Search in sources :

Example 6 with ResourceTO

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

the class VirAttrITCase method issueSYNCOPE397.

@Test
public void issueSYNCOPE397() {
    ResourceTO csv = resourceService.read(RESOURCE_NAME_CSV);
    // change mapping of resource-csv
    MappingTO origMapping = SerializationUtils.clone(csv.getProvisions().get(0).getMapping());
    try {
        // remove this mapping
        Optional<ItemTO> email = csv.getProvisions().get(0).getMapping().getItems().stream().filter(item -> "email".equals(item.getIntAttrName())).findFirst();
        if (email.isPresent()) {
            csv.getProvisions().get(0).getMapping().getItems().remove(email.get());
        }
        resourceService.update(csv);
        csv = resourceService.read(RESOURCE_NAME_CSV);
        assertNotNull(csv.getProvisions().get(0).getMapping());
        // create new virtual schema for the resource below
        ProvisionTO provision = csv.getProvision(AnyTypeKind.USER.name()).get();
        assertNotNull(provision);
        VirSchemaTO virSchema = new VirSchemaTO();
        virSchema.setKey("syncope397" + getUUIDString());
        virSchema.setExtAttrName("email");
        virSchema.setResource(RESOURCE_NAME_CSV);
        virSchema.setAnyType(provision.getAnyType());
        virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
        assertNotNull(virSchema);
        AnyTypeClassTO newClass = new AnyTypeClassTO();
        newClass.setKey("syncope397" + getUUIDString());
        newClass.getVirSchemas().add(virSchema.getKey());
        Response response = anyTypeClassService.create(newClass);
        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
        newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
        // create a new user
        UserTO userTO = UserITCase.getUniqueSampleTO("397@syncope.apache.org");
        userTO.getAuxClasses().add("csv");
        userTO.getAuxClasses().add(newClass.getKey());
        userTO.getResources().clear();
        userTO.getMemberships().clear();
        userTO.getVirAttrs().clear();
        userTO.getVirAttrs().add(attrTO(virSchema.getKey(), "test@testone.org"));
        // assign resource-csv to user
        userTO.getResources().add(RESOURCE_NAME_CSV);
        // save user
        userTO = createUser(userTO).getEntity();
        // make std controls about user
        assertNotNull(userTO);
        assertTrue(RESOURCE_NAME_CSV.equals(userTO.getResources().iterator().next()));
        assertEquals("test@testone.org", userTO.getVirAttrs().iterator().next().getValues().get(0));
        // update user
        UserTO toBeUpdated = userService.read(userTO.getKey());
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(toBeUpdated.getKey());
        userPatch.setPassword(new PasswordPatch.Builder().value("password234").build());
        // assign new resource to user
        userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_WS2).build());
        // modify virtual attribute
        userPatch.getVirAttrs().add(attrTO(virSchema.getKey(), "test@testoneone.com"));
        // check Syncope change password
        userPatch.setPassword(new PasswordPatch.Builder().value("password234").onSyncope(true).resource(RESOURCE_NAME_WS2).build());
        ProvisioningResult<UserTO> result = updateUser(userPatch);
        assertNotNull(result);
        toBeUpdated = result.getEntity();
        assertTrue(toBeUpdated.getVirAttrs().iterator().next().getValues().contains("test@testoneone.com"));
        // check if propagates correctly with assertEquals on size of tasks list
        assertEquals(2, result.getPropagationStatuses().size());
    } finally {
        // restore mapping of resource-csv
        csv.getProvisions().get(0).setMapping(origMapping);
        resourceService.update(csv);
    }
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Autowired(org.springframework.beans.factory.annotation.Autowired) SerializationUtils(org.apache.commons.lang3.SerializationUtils) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Locale(java.util.Locale) Map(java.util.Map) DataSource(javax.sql.DataSource) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) StatusPatchType(org.apache.syncope.common.lib.types.StatusPatchType) MappingTO(org.apache.syncope.common.lib.to.MappingTO) SchemaType(org.apache.syncope.common.lib.types.SchemaType) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) List(java.util.List) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) Response(javax.ws.rs.core.Response) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Response(javax.ws.rs.core.Response) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Example 7 with ResourceTO

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

the class PropagationTaskITCase method privileges.

@Test
public void privileges() {
    ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
    ldap.setKey("ldapWithPrivileges");
    ItemTO item = new ItemTO();
    item.setIntAttrName("privileges[mightyApp]");
    item.setExtAttrName("businessCategory");
    item.setPurpose(MappingPurpose.PROPAGATION);
    ProvisionTO provision = ldap.getProvision(AnyTypeKind.USER.name()).get();
    provision.getVirSchemas().clear();
    provision.getMapping().add(item);
    ldap = createResource(ldap);
    try {
        UserTO user = UserITCase.getUniqueSampleTO("privilege@syncope.apache.org");
        user.getResources().add(ldap.getKey());
        user.getRoles().add("Other");
        ProvisioningResult<UserTO> result = createUser(user);
        assertEquals(1, result.getPropagationStatuses().size());
        assertNotNull(result.getPropagationStatuses().get(0).getAfterObj());
        AttrTO businessCategory = result.getPropagationStatuses().get(0).getAfterObj().getAttr("businessCategory").orElse(null);
        assertNotNull(businessCategory);
        assertEquals(1, businessCategory.getValues().size());
        assertEquals("postMighty", businessCategory.getValues().get(0));
    } finally {
        resourceService.delete(ldap.getKey());
    }
}
Also used : ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Test(org.junit.jupiter.api.Test)

Example 8 with ResourceTO

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

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

Example 10 with ResourceTO

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

the class ExceptionMapperITCase method invalidRequests.

@Test
public void invalidRequests() {
    try {
        taskService.search(new TaskQuery.Builder(TaskType.NOTIFICATION).resource(RESOURCE_NAME_LDAP).build());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidRequest, e.getType());
    }
    try {
        taskService.search(new TaskQuery.Builder(TaskType.PULL).anyTypeKind(AnyTypeKind.ANY_OBJECT).build());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidRequest, e.getType());
    }
    try {
        taskService.search(new TaskQuery.Builder(TaskType.PULL).notification("e00945b5-1184-4d43-8e45-4318a8dcdfd4").build());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidRequest, e.getType());
    }
    try {
        anyTypeService.delete(AnyTypeKind.USER.name());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidRequest, e.getType());
    }
    try {
        clientFactory.create(ANONYMOUS_UNAME, ANONYMOUS_KEY).getService(AccessTokenService.class).login();
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidRequest, e.getType());
    }
    try {
        ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
        ItemTO mapping = ldap.getProvisions().get(0).getMapping().getItems().get(0);
        mapping.setIntAttrName("memberships.cn");
        resourceService.update(ldap);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidMapping, e.getType());
    }
}
Also used : AccessTokenService(org.apache.syncope.common.rest.api.service.AccessTokenService) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ItemTO(org.apache.syncope.common.lib.to.ItemTO) 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