Package org.apache.syncope.common.to

Examples of org.apache.syncope.common.to.MappingTO


    }

    @Test
    public void issueSYNCOPE397() {
        ResourceTO csv = resourceService.read(RESOURCE_NAME_CSV);
        final MappingTO origMapping = SerializationUtils.clone(csv.getUmapping());
        try {
            // change mapping of resource-csv
            assertNotNull(origMapping);
            for (MappingItemTO item : csv.getUmapping().getItems()) {
                if ("email".equals(item.getIntAttrName())) {
View Full Code Here


        final ResourceTO resourceTO = new ResourceTO();

        resourceTO.setName(resourceName);
        resourceTO.setConnectorId(107L);

        MappingTO mapping = new MappingTO();

        MappingItemTO item = new MappingItemTO();
        item.setIntAttrName("aLong");
        item.setIntMappingType(IntMappingType.UserSchema);
        item.setExtAttrName(roleName);
        item.setPurpose(MappingPurpose.PROPAGATION);
        item.setAccountid(true);
        mapping.setAccountIdItem(item);

        item = new MappingItemTO();
        item.setExtAttrName("USERNAME");
        item.setIntAttrName("username");
        item.setIntMappingType(IntMappingType.Username);
        item.setPurpose(MappingPurpose.PROPAGATION);
        mapping.getItems().add(item);

        item = new MappingItemTO();
        item.setExtAttrName("EMAIL");
        item.setIntAttrName("rvirtualdata");
        item.setIntMappingType(IntMappingType.RoleVirtualSchema);
        item.setPurpose(MappingPurpose.PROPAGATION);
        mapping.getItems().add(item);

        resourceTO.setUmapping(mapping);
        assertNotNull(getObject(
                resourceService.create(resourceTO).getLocation(), ResourceService.class, ResourceTO.class));
        // -------------------------------------------
View Full Code Here

        // Update resource-db-virattr mapping adding new membership virtual schema mapping
        // -------------------------------------------
        ResourceTO resourceDBVirAttr = resourceService.read(RESOURCE_NAME_DBVIRATTR);
        assertNotNull(resourceDBVirAttr);

        final MappingTO resourceUMapping = resourceDBVirAttr.getUmapping();

        MappingItemTO item = new MappingItemTO();
        item.setIntAttrName("mvirtualdata");
        item.setIntMappingType(IntMappingType.MembershipVirtualSchema);
        item.setExtAttrName("EMAIL");
        item.setPurpose(MappingPurpose.BOTH);

        resourceUMapping.addItem(item);

        resourceDBVirAttr.setUmapping(resourceUMapping);

        resourceService.update(RESOURCE_NAME_DBVIRATTR, resourceDBVirAttr);
        // -------------------------------------------

        // -------------------------------------------
        // Create new user
        // -------------------------------------------
        UserTO userTO = UserTestITCase.getUniqueSampleTO("syncope458@syncope.apache.org");
        userTO.getResources().clear();
        userTO.getResources().add(RESOURCE_NAME_DBVIRATTR);
        userTO.getVirAttrs().clear();
        userTO.getDerAttrs().clear();
        userTO.getMemberships().clear();

        // add membership, with virtual attribute populated, to user
        MembershipTO membership = new MembershipTO();
        membership.setRoleId(roleTO.getId());
        membership.getVirAttrs().add(attributeTO("mvirtualdata", "syncope458@syncope.apache.org"));
        userTO.getMemberships().add(membership);

        //propagate user
        userTO = createUser(userTO);
        assertEquals(1, userTO.getPropagationStatusTOs().size());
        assertTrue(userTO.getPropagationStatusTOs().get(0).getStatus().isSuccessful());
       // -------------------------------------------

        // 1. check if membership has virtual attribute populated
        assertNotNull(userTO.getMemberships().get(0).getVirAttrMap().get("mvirtualdata"));
        assertEquals("syncope458@syncope.apache.org",
                userTO.getMemberships().get(0).getVirAttrMap().get("mvirtualdata").getValues().get(0));
        // -------------------------------------------

        // 2. update membership virtual attribute
        MembershipMod membershipMod = new MembershipMod();
        membershipMod.setRole(roleTO.getId());
        membershipMod.getVirAttrsToUpdate().add(attributeMod("mvirtualdata", "syncope458_NEW@syncope.apache.org"));

        UserMod userMod = new UserMod();
        userMod.setId(userTO.getId());
        userMod.getMembershipsToAdd().add(membershipMod);
        userMod.getMembershipsToRemove().add(userTO.getMemberships().iterator().next().getId());

        userTO = updateUser(userMod);
        assertNotNull(userTO);
        // 3. check again after update if membership has virtual attribute populated with new value
        assertNotNull(userTO.getMemberships().get(0).getVirAttrMap().get("mvirtualdata"));
        assertEquals("syncope458_NEW@syncope.apache.org", userTO.getMemberships().get(0).getVirAttrMap().get(
                "mvirtualdata").getValues().get(0));

        // ----------------------------------------
        // force cache expiring without any modification
        // ----------------------------------------
        String jdbcURL = null;
        ConnInstanceTO connInstanceBean = connectorService.readByResource(RESOURCE_NAME_DBVIRATTR);
        for (ConnConfProperty prop : connInstanceBean.getConfiguration()) {
            if ("jdbcUrlTemplate".equals(prop.getSchema().getName())) {
                jdbcURL = prop.getValues().iterator().next().toString();
                prop.getValues().clear();
                prop.getValues().add("jdbc:h2:tcp://localhost:9092/xxx");
            }
        }

        connectorService.update(connInstanceBean.getId(), connInstanceBean);

        membershipMod = new MembershipMod();
        membershipMod.setRole(roleTO.getId());
        membershipMod.getVirAttrsToUpdate().add(attributeMod("mvirtualdata", "syncope458_updated@syncope.apache.org"));

        userMod = new UserMod();
        userMod.setId(userTO.getId());
        userMod.getMembershipsToAdd().add(membershipMod);
        userMod.getMembershipsToRemove().add(userTO.getMemberships().iterator().next().getId());

        userTO = updateUser(userMod);
        assertNotNull(userTO);
        // ----------------------------------

        // change attribute value directly on resource
        final JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);

        String value = jdbcTemplate.queryForObject(
                "SELECT EMAIL FROM testsync WHERE ID=?", String.class, userTO.getId());
        assertEquals("syncope458_NEW@syncope.apache.org", value);

        jdbcTemplate.update("UPDATE testsync set EMAIL='syncope458_NEW_TWO@syncope.apache.org' WHERE ID=?", userTO.
                getId());

        value = jdbcTemplate.queryForObject("SELECT EMAIL FROM testsync WHERE ID=?", String.class, userTO.getId());
        assertEquals("syncope458_NEW_TWO@syncope.apache.org", value);
        // ----------------------------------------

        // ----------------------------------------
        // restore connector
        // ----------------------------------------
        for (ConnConfProperty prop : connInstanceBean.getConfiguration()) {
            if ("jdbcUrlTemplate".equals(prop.getSchema().getName())) {
                prop.getValues().clear();
                prop.getValues().add(jdbcURL);
            }
        }
        connectorService.update(connInstanceBean.getId(), connInstanceBean);
        // ----------------------------------------

        userTO = userService.read(userTO.getId());
        assertNotNull(userTO);
        // 4. check virtual attribute synchronization after direct update on resource
        assertEquals("syncope458_NEW_TWO@syncope.apache.org", userTO.getMemberships().get(0).getVirAttrMap().get(
                "mvirtualdata").getValues().get(0));

        // 5. remove membership virtual attribute
        membershipMod = new MembershipMod();
        membershipMod.setRole(roleTO.getId());
        membershipMod.getVirAttrsToRemove().add("mvirtualdata");

        userMod = new UserMod();
        userMod.setId(userTO.getId());
        userMod.getMembershipsToAdd().add(membershipMod);
        userMod.getMembershipsToRemove().add(userTO.getMemberships().iterator().next().getId());

        userTO = updateUser(userMod);
        assertNotNull(userTO);
        // check again after update if membership hasn't any virtual attribute
        assertTrue(userTO.getMemberships().get(0).getVirAttrMap().isEmpty());

        // -------------------------------------------
        // Delete role ad-hoc and restore resource mapping
        // -------------------------------------------
        roleService.delete(roleTO.getId());

        resourceUMapping.removeItem(item);
        resourceDBVirAttr.setUmapping(resourceUMapping);
        resourceService.update(RESOURCE_NAME_DBVIRATTR, resourceDBVirAttr);
        // -------------------------------------------
    }
View Full Code Here

        // Update resource-db-virattr mapping adding new membership virtual schema mapping
        // -------------------------------------------
        ResourceTO resourceDBVirAttr = resourceService.read(RESOURCE_NAME_DBVIRATTR);
        assertNotNull(resourceDBVirAttr);

        final MappingTO resourceUMapping = resourceDBVirAttr.getUmapping();

        MappingItemTO item = new MappingItemTO();
        item.setIntAttrName("mvirtualdata");
        item.setIntMappingType(IntMappingType.MembershipVirtualSchema);
        item.setExtAttrName("EMAIL");
        item.setPurpose(MappingPurpose.BOTH);

        resourceUMapping.addItem(item);

        resourceDBVirAttr.setUmapping(resourceUMapping);

        resourceService.update(RESOURCE_NAME_DBVIRATTR, resourceDBVirAttr);
        // -------------------------------------------

        // -------------------------------------------
        // Create a role ad-hoc
        // -------------------------------------------
        final String roleName = "issueSYNCOPE501-Role-" + getUUIDString();
        RoleTO roleTO = new RoleTO();
        roleTO.setName(roleName);
        roleTO.setParent(2L);
        roleTO.setInheritTemplates(true);
        roleTO = createRole(roleTO);
        // -------------------------------------------

        // 1. add membership, with virtual attribute populated, to user
        MembershipMod membershipMod = new MembershipMod();
        membershipMod.setRole(roleTO.getId());
        membershipMod.getVirAttrsToUpdate().add(attributeMod("mvirtualdata", "syncope501membership@test.org"));

        userMod = new UserMod();
        userMod.setId(userTO.getId());
        userMod.getMembershipsToAdd().add(membershipMod);
        userMod.setPwdPropRequest(statusMod);

        userTO = updateUser(userMod);
        assertNotNull(userTO);
        assertEquals("syncope501membership@test.org",
                userTO.getMemberships().get(0).getVirAttrMap().get("mvirtualdata").getValues().get(0));

        // 2. update only membership virtual attribute and propagate user
        membershipMod = new MembershipMod();
        membershipMod.setRole(roleTO.getId());
        membershipMod.getVirAttrsToUpdate().add(attributeMod("mvirtualdata",
                "syncope501membership_updated@test.org"));
        membershipMod.getVirAttrsToRemove().add("syncope501membership@test.org");

        userMod = new UserMod();
        userMod.setId(userTO.getId());
        userMod.getMembershipsToAdd().add(membershipMod);
        userMod.getMembershipsToRemove().add(userTO.getMemberships().iterator().next().getId());
        userMod.setPwdPropRequest(statusMod);

        userTO = updateUser(userMod);
        assertNotNull(userTO);

        // 3. check if change has been propagated
        assertEquals("syncope501membership_updated@test.org", userTO.getMemberships().get(0).getVirAttrMap().
                get("mvirtualdata").getValues().get(0));

        // 4. delete membership and check on resource attribute deletion
        userMod = new UserMod();
        userMod.setId(userTO.getId());
        userMod.getMembershipsToRemove().add(userTO.getMemberships().get(0).getId());
        userMod.setPwdPropRequest(statusMod);

        userTO = updateUser(userMod);
        assertNotNull(userTO);
        assertTrue(userTO.getMemberships().isEmpty());

        // read attribute value directly on resource
        final JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);

        final String emailValue = jdbcTemplate.queryForObject(
                "SELECT EMAIL FROM testsync WHERE ID=?", String.class, userTO.getId());
        assertTrue(StringUtils.isBlank(emailValue));
        // ----------------------------------------

        // -------------------------------------------
        // Delete role ad-hoc and restore resource mapping
        // -------------------------------------------
        roleService.delete(roleTO.getId());

        resourceUMapping.removeItem(item);
        resourceDBVirAttr.setUmapping(resourceUMapping);
        resourceService.update(RESOURCE_NAME_DBVIRATTR, resourceDBVirAttr);
        // -------------------------------------------
    }
View Full Code Here

        // 2.  update resource ws-target-resource-1
        ResourceTO ws1 = resourceService.read(RESOURCE_NAME_WS1);
        assertNotNull(ws1);

        MappingTO ws1NewUMapping = ws1.getUmapping();
        // change purpose from NONE to BOTH
        for (MappingItemTO itemTO : ws1NewUMapping.getItems()) {
            if ("firstname".equals(itemTO.getIntAttrName())) {
                itemTO.setPurpose(MappingPurpose.BOTH);
            }
        }

        ws1.setUmapping(ws1NewUMapping);
        ws1.setRmapping(ws1.getRmapping());

        resourceService.update(RESOURCE_NAME_WS1, ws1);
        ResourceTO newWs1 = resourceService.read(ws1.getName());
        assertNotNull(newWs1);

        // check for existence
        Collection<MappingItemTO> mapItems = newWs1.getUmapping().getItems();
        assertNotNull(mapItems);
        assertEquals(7, mapItems.size());

        // 3.  update user and check firstname propagation       
        UserMod userMod = new UserMod();
        userMod.setId(userTO.getId());
        userMod.setPwdPropRequest(new StatusMod());
        userMod.getAttrsToUpdate().add(attributeMod("firstname", "firstnameNew"));

        userTO = updateUser(userMod);
        assertNotNull(userTO);
        assertEquals(1, userTO.getPropagationStatusTOs().size());
        assertTrue(userTO.getPropagationStatusTOs().get(0).getStatus().isSuccessful());

        final ConnObjectTO newUser = resourceService.getConnectorObject(RESOURCE_NAME_WS1, SubjectType.USER,
                userTO.getId());

        assertNotNull(newUser.getAttrMap().get("NAME"));
        assertEquals("firstnameNew", newUser.getAttrMap().get("NAME").getValues().get(0));

        // 4.  restore resource ws-target-resource-1 mapping
        ws1NewUMapping = newWs1.getUmapping();
        // restore purpose from BOTH to NONE
        for (MappingItemTO itemTO : ws1NewUMapping.getItems()) {
            if ("firstname".equals(itemTO.getIntAttrName())) {
                itemTO.setPurpose(MappingPurpose.NONE);
            }
        }
View Full Code Here

            endpoint.getValues().add("http://localhost:9080/wssample/services/provisioning");
            conf.add(endpoint);

            resourceTO.getConnConfProperties().addAll(conf);

            MappingTO mapping = new MappingTO();
            resourceTO.setUmapping(mapping);

            MappingItemTO mapItem = new MappingItemTO();
            mapItem.setExtAttrName("uid");
            mapItem.setIntAttrName("userId");
            mapItem.setIntMappingType(IntMappingType.UserSchema);
            mapItem.setAccountid(true);
            mapping.setAccountIdItem(mapItem);
            // ----------------------------------------

            // ----------------------------------------
            // Check connection without saving the resource ....
            // ----------------------------------------
View Full Code Here

        resourceTO.setConnectorId(connector == null ? null : connector.getId());
        resourceTO.setConnectorDisplayName(connector == null ? null : connector.getDisplayName());

        // set the mappings
        if (resource.getUmapping() != null) {
            MappingTO mappingTO = new MappingTO();
            resourceTO.setUmapping(mappingTO);
            populateMappingTO(resource.getUmapping(), mappingTO);
        }
        if (resource.getRmapping() != null) {
            MappingTO mappingTO = new MappingTO();
            resourceTO.setRmapping(mappingTO);
            populateMappingTO(resource.getRmapping(), mappingTO);
        }

        resourceTO.setEnforceMandatoryCondition(resource.isEnforceMandatoryCondition());
View Full Code Here

TOP

Related Classes of org.apache.syncope.common.to.MappingTO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.