Search in sources :

Example 11 with MappingTO

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

the class ResourceITCase method createWithSingleMappingItem.

@Test
public void createWithSingleMappingItem() {
    String resourceKey = RESOURCE_NAME_CREATE_SINGLE;
    ResourceTO resourceTO = new ResourceTO();
    resourceTO.setKey(resourceKey);
    resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
    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 item = new ItemTO();
    item.setIntAttrName("key");
    item.setExtAttrName("userId");
    item.setConnObjectKey(true);
    item.setPurpose(MappingPurpose.PROPAGATION);
    mapping.setConnObjectKeyItem(item);
    provisionTO = new ProvisionTO();
    provisionTO.setAnyType(AnyTypeKind.GROUP.name());
    provisionTO.setObjectClass(ObjectClass.GROUP_NAME);
    resourceTO.getProvisions().add(provisionTO);
    mapping = new MappingTO();
    provisionTO.setMapping(mapping);
    item = new ItemTO();
    item.setIntAttrName("key");
    item.setExtAttrName("groupId");
    item.setConnObjectKey(true);
    item.setPurpose(MappingPurpose.PULL);
    mapping.setConnObjectKeyItem(item);
    Response response = resourceService.create(resourceTO);
    ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
    assertNotNull(actual);
    assertNotNull(actual.getProvision(AnyTypeKind.USER.name()).get().getMapping());
    assertNotNull(actual.getProvision(AnyTypeKind.USER.name()).get().getMapping().getItems());
    assertNotNull(actual.getProvision(AnyTypeKind.GROUP.name()).get().getMapping());
    assertNotNull(actual.getProvision(AnyTypeKind.GROUP.name()).get().getMapping().getItems());
    assertEquals(MappingPurpose.PULL, actual.getProvision(AnyTypeKind.GROUP.name()).get().getMapping().getConnObjectKeyItem().getPurpose());
    assertEquals(MappingPurpose.PROPAGATION, actual.getProvision(AnyTypeKind.USER.name()).get().getMapping().getConnObjectKeyItem().getPurpose());
}
Also used : Response(javax.ws.rs.core.Response) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Test(org.junit.jupiter.api.Test)

Example 12 with MappingTO

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

the class ResourceDataBinderTest method issue42.

@Test
public void issue42() {
    PlainSchema userId = plainSchemaDAO.find("userId");
    Set<MappingItem> beforeUserIdMappings = new HashSet<>();
    for (ExternalResource res : resourceDAO.findAll()) {
        if (res.getProvision(anyTypeDAO.findUser()).isPresent() && res.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
            for (MappingItem mapItem : res.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
                if (userId.getKey().equals(mapItem.getIntAttrName())) {
                    beforeUserIdMappings.add(mapItem);
                }
            }
        }
    }
    ResourceTO resourceTO = new ResourceTO();
    resourceTO.setKey("resource-issue42");
    resourceTO.setConnector("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
    resourceTO.setEnforceMandatoryCondition(true);
    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 item = new ItemTO();
    item.setIntAttrName("userId");
    item.setExtAttrName("campo1");
    item.setConnObjectKey(true);
    item.setMandatoryCondition("false");
    item.setPurpose(MappingPurpose.BOTH);
    mapping.setConnObjectKeyItem(item);
    ExternalResource resource = resourceDataBinder.create(resourceTO);
    resource = resourceDAO.save(resource);
    assertNotNull(resource);
    assertNotNull(resource.getProvision(anyTypeDAO.findUser()).get().getMapping());
    assertEquals(1, resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().size());
    resourceDAO.flush();
    ExternalResource actual = resourceDAO.find("resource-issue42");
    assertNotNull(actual);
    assertEquals(resource, actual);
    userId = plainSchemaDAO.find("userId");
    Set<MappingItem> afterUserIdMappings = new HashSet<>();
    for (ExternalResource res : resourceDAO.findAll()) {
        if (res.getProvision(anyTypeDAO.findUser()).isPresent() && res.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
            for (MappingItem mapItem : res.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
                if (userId.getKey().equals(mapItem.getIntAttrName())) {
                    afterUserIdMappings.add(mapItem);
                }
            }
        }
    }
    assertEquals(beforeUserIdMappings.size(), afterUserIdMappings.size() - 1);
}
Also used : MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ItemTO(org.apache.syncope.common.lib.to.ItemTO) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 13 with MappingTO

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

the class ResourceDataBinderImpl method getResourceTO.

@Override
public ResourceTO getResourceTO(final ExternalResource resource) {
    ResourceTO resourceTO = new ResourceTO();
    // set the resource name
    resourceTO.setKey(resource.getKey());
    // set the connector instance
    ConnInstance connector = resource.getConnector();
    resourceTO.setConnector(connector == null ? null : connector.getKey());
    resourceTO.setConnectorDisplayName(connector == null ? null : connector.getDisplayName());
    // set the provision information
    resource.getProvisions().stream().map(provision -> {
        ProvisionTO provisionTO = new ProvisionTO();
        provisionTO.setKey(provision.getKey());
        provisionTO.setAnyType(provision.getAnyType().getKey());
        provisionTO.setObjectClass(provision.getObjectClass().getObjectClassValue());
        provisionTO.getAuxClasses().addAll(provision.getAuxClasses().stream().map(cls -> cls.getKey()).collect(Collectors.toList()));
        provisionTO.setSyncToken(provision.getSerializedSyncToken());
        if (provision.getMapping() != null) {
            MappingTO mappingTO = new MappingTO();
            provisionTO.setMapping(mappingTO);
            mappingTO.setConnObjectLink(provision.getMapping().getConnObjectLink());
            populateItems(provision.getMapping().getItems(), mappingTO);
        }
        virSchemaDAO.findByProvision(provision).forEach(virSchema -> {
            provisionTO.getVirSchemas().add(virSchema.getKey());
            MappingItem linkingMappingItem = virSchema.asLinkingMappingItem();
            ItemTO itemTO = new ItemTO();
            itemTO.setKey(linkingMappingItem.getKey());
            BeanUtils.copyProperties(linkingMappingItem, itemTO, ITEM_IGNORE_PROPERTIES);
            provisionTO.getMapping().getLinkingItems().add(itemTO);
        });
        return provisionTO;
    }).forEachOrdered(provisionTO -> {
        resourceTO.getProvisions().add(provisionTO);
    });
    if (resource.getOrgUnit() != null) {
        OrgUnit orgUnit = resource.getOrgUnit();
        OrgUnitTO orgUnitTO = new OrgUnitTO();
        orgUnitTO.setKey(orgUnit.getKey());
        orgUnitTO.setObjectClass(orgUnit.getObjectClass().getObjectClassValue());
        orgUnitTO.setSyncToken(orgUnit.getSerializedSyncToken());
        orgUnitTO.setConnObjectLink(orgUnit.getConnObjectLink());
        populateItems(orgUnit.getItems(), orgUnitTO);
        resourceTO.setOrgUnit(orgUnitTO);
    }
    resourceTO.setEnforceMandatoryCondition(resource.isEnforceMandatoryCondition());
    resourceTO.setPropagationPriority(resource.getPropagationPriority());
    resourceTO.setRandomPwdIfNotProvided(resource.isRandomPwdIfNotProvided());
    resourceTO.setCreateTraceLevel(resource.getCreateTraceLevel());
    resourceTO.setUpdateTraceLevel(resource.getUpdateTraceLevel());
    resourceTO.setDeleteTraceLevel(resource.getDeleteTraceLevel());
    resourceTO.setProvisioningTraceLevel(resource.getProvisioningTraceLevel());
    resourceTO.setPasswordPolicy(resource.getPasswordPolicy() == null ? null : resource.getPasswordPolicy().getKey());
    resourceTO.setAccountPolicy(resource.getAccountPolicy() == null ? null : resource.getAccountPolicy().getKey());
    resourceTO.setPullPolicy(resource.getPullPolicy() == null ? null : resource.getPullPolicy().getKey());
    resourceTO.getConfOverride().addAll(resource.getConfOverride());
    Collections.sort(resourceTO.getConfOverride());
    resourceTO.setOverrideCapabilities(resource.isOverrideCapabilities());
    resourceTO.getCapabilitiesOverride().addAll(resource.getCapabilitiesOverride());
    resourceTO.getPropagationActions().addAll(resource.getPropagationActions().stream().map(Entity::getKey).collect(Collectors.toList()));
    return resourceTO;
}
Also used : ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PullPolicy(org.apache.syncope.core.persistence.api.entity.policy.PullPolicy) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) JexlUtils(org.apache.syncope.core.provisioning.java.jexl.JexlUtils) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) ParseException(java.text.ParseException) ImplementationDAO(org.apache.syncope.core.persistence.api.dao.ImplementationDAO) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) MappingTO(org.apache.syncope.common.lib.to.MappingTO) OrgUnitItem(org.apache.syncope.core.persistence.api.entity.resource.OrgUnitItem) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) SchemaType(org.apache.syncope.common.lib.types.SchemaType) ConnInstanceDAO(org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO) ResourceDataBinder(org.apache.syncope.core.provisioning.api.data.ResourceDataBinder) Collectors(java.util.stream.Collectors) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) List(java.util.List) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) PolicyDAO(org.apache.syncope.core.persistence.api.dao.PolicyDAO) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) ExternalResourceHistoryConfDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceHistoryConfDAO) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) ResourceHistoryConfTO(org.apache.syncope.common.lib.to.ResourceHistoryConfTO) BeanUtils(org.apache.syncope.core.spring.BeanUtils) HashSet(java.util.HashSet) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ItemTO(org.apache.syncope.common.lib.to.ItemTO) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) Item(org.apache.syncope.core.persistence.api.entity.resource.Item) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ItemContainerTO(org.apache.syncope.common.lib.to.ItemContainerTO) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) ExternalResourceHistoryConf(org.apache.syncope.core.persistence.api.entity.resource.ExternalResourceHistoryConf) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Component(org.springframework.stereotype.Component) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) OrgUnitTO(org.apache.syncope.common.lib.to.OrgUnitTO) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) IntAttrNameParser(org.apache.syncope.core.provisioning.java.IntAttrNameParser) Collections(java.util.Collections) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) Entity(org.apache.syncope.core.persistence.api.entity.Entity) MappingTO(org.apache.syncope.common.lib.to.MappingTO) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) OrgUnitTO(org.apache.syncope.common.lib.to.OrgUnitTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance)

Example 14 with MappingTO

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

the class ResourceDataBinderImpl method populateMapping.

private void populateMapping(final MappingTO mappingTO, final Mapping mapping, final AnyTypeClassTO allowedSchemas) {
    mapping.setConnObjectLink(mappingTO.getConnObjectLink());
    SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
    SyncopeClientException invalidMapping = SyncopeClientException.build(ClientExceptionType.InvalidMapping);
    SyncopeClientException requiredValuesMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
    for (ItemTO itemTO : mappingTO.getItems()) {
        if (itemTO == null) {
            LOG.error("Null {}", ItemTO.class.getSimpleName());
            invalidMapping.getElements().add("Null " + ItemTO.class.getSimpleName());
        } else if (itemTO.getIntAttrName() == null) {
            requiredValuesMissing.getElements().add("intAttrName");
            scce.addException(requiredValuesMissing);
        } else {
            IntAttrName intAttrName = null;
            try {
                intAttrName = intAttrNameParser.parse(itemTO.getIntAttrName(), mapping.getProvision().getAnyType().getKind());
            } catch (ParseException e) {
                LOG.error("Invalid intAttrName '{}'", itemTO.getIntAttrName(), e);
            }
            if (intAttrName == null || intAttrName.getSchemaType() == null && intAttrName.getField() == null && intAttrName.getPrivilegesOfApplication() == null) {
                LOG.error("'{}' not existing", itemTO.getIntAttrName());
                invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not existing");
            } else {
                boolean allowed = true;
                if (intAttrName.getSchemaType() != null && intAttrName.getEnclosingGroup() == null && intAttrName.getRelatedAnyObject() == null && intAttrName.getPrivilegesOfApplication() == null) {
                    switch(intAttrName.getSchemaType()) {
                        case PLAIN:
                            allowed = allowedSchemas.getPlainSchemas().contains(intAttrName.getSchemaName());
                            break;
                        case DERIVED:
                            allowed = allowedSchemas.getDerSchemas().contains(intAttrName.getSchemaName());
                            break;
                        case VIRTUAL:
                            allowed = allowedSchemas.getVirSchemas().contains(intAttrName.getSchemaName());
                            break;
                        default:
                    }
                }
                if (allowed) {
                    // no mandatory condition implies mandatory condition false
                    if (!JexlUtils.isExpressionValid(itemTO.getMandatoryCondition() == null ? "false" : itemTO.getMandatoryCondition())) {
                        SyncopeClientException invalidMandatoryCondition = SyncopeClientException.build(ClientExceptionType.InvalidValues);
                        invalidMandatoryCondition.getElements().add(itemTO.getMandatoryCondition());
                        scce.addException(invalidMandatoryCondition);
                    }
                    MappingItem item = entityFactory.newEntity(MappingItem.class);
                    BeanUtils.copyProperties(itemTO, item, ITEM_IGNORE_PROPERTIES);
                    item.setMapping(mapping);
                    if (item.isConnObjectKey()) {
                        if (intAttrName.getSchemaType() == SchemaType.VIRTUAL) {
                            invalidMapping.getElements().add("Virtual attributes cannot be set as ConnObjectKey");
                        }
                        if ("password".equals(intAttrName.getField())) {
                            invalidMapping.getElements().add("Password attributes cannot be set as ConnObjectKey");
                        }
                        mapping.setConnObjectKeyItem(item);
                    } else {
                        mapping.add(item);
                    }
                    itemTO.getTransformers().forEach(transformerKey -> {
                        Implementation transformer = implementationDAO.find(transformerKey);
                        if (transformer == null) {
                            LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", transformerKey);
                        } else {
                            item.add(transformer);
                        }
                    });
                    // remove all implementations not contained in the TO
                    item.getTransformers().removeIf(implementation -> !itemTO.getTransformers().contains(implementation.getKey()));
                    if (intAttrName.getEnclosingGroup() != null && item.getPurpose() != MappingPurpose.PROPAGATION) {
                        invalidMapping.getElements().add("Only " + MappingPurpose.PROPAGATION.name() + " allowed when referring to groups");
                    }
                    if (intAttrName.getRelatedAnyObject() != null && item.getPurpose() != MappingPurpose.PROPAGATION) {
                        invalidMapping.getElements().add("Only " + MappingPurpose.PROPAGATION.name() + " allowed when referring to any objects");
                    }
                    if (intAttrName.getPrivilegesOfApplication() != null && item.getPurpose() != MappingPurpose.PROPAGATION) {
                        invalidMapping.getElements().add("Only " + MappingPurpose.PROPAGATION.name() + " allowed when referring to privileges");
                    }
                    if (intAttrName.getSchemaType() == SchemaType.DERIVED && item.getPurpose() != MappingPurpose.PROPAGATION) {
                        invalidMapping.getElements().add("Only " + MappingPurpose.PROPAGATION.name() + " allowed for derived");
                    }
                    if (intAttrName.getSchemaType() == SchemaType.VIRTUAL) {
                        if (item.getPurpose() != MappingPurpose.PROPAGATION) {
                            invalidMapping.getElements().add("Only " + MappingPurpose.PROPAGATION.name() + " allowed for virtual");
                        }
                        VirSchema schema = virSchemaDAO.find(item.getIntAttrName());
                        if (schema != null && schema.getProvision().equals(item.getMapping().getProvision())) {
                            invalidMapping.getElements().add("No need to map virtual schema on linking resource");
                        }
                    }
                } else {
                    LOG.error("'{}' not allowed", itemTO.getIntAttrName());
                    invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not allowed");
                }
            }
        }
    }
    if (!invalidMapping.getElements().isEmpty()) {
        scce.addException(invalidMapping);
    }
    if (scce.hasExceptions()) {
        throw scce;
    }
}
Also used : ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PullPolicy(org.apache.syncope.core.persistence.api.entity.policy.PullPolicy) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) JexlUtils(org.apache.syncope.core.provisioning.java.jexl.JexlUtils) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) ParseException(java.text.ParseException) ImplementationDAO(org.apache.syncope.core.persistence.api.dao.ImplementationDAO) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) MappingTO(org.apache.syncope.common.lib.to.MappingTO) OrgUnitItem(org.apache.syncope.core.persistence.api.entity.resource.OrgUnitItem) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) SchemaType(org.apache.syncope.common.lib.types.SchemaType) ConnInstanceDAO(org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO) ResourceDataBinder(org.apache.syncope.core.provisioning.api.data.ResourceDataBinder) Collectors(java.util.stream.Collectors) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) List(java.util.List) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) PolicyDAO(org.apache.syncope.core.persistence.api.dao.PolicyDAO) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) ExternalResourceHistoryConfDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceHistoryConfDAO) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) ResourceHistoryConfTO(org.apache.syncope.common.lib.to.ResourceHistoryConfTO) BeanUtils(org.apache.syncope.core.spring.BeanUtils) HashSet(java.util.HashSet) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ItemTO(org.apache.syncope.common.lib.to.ItemTO) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) Item(org.apache.syncope.core.persistence.api.entity.resource.Item) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ItemContainerTO(org.apache.syncope.common.lib.to.ItemContainerTO) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) ExternalResourceHistoryConf(org.apache.syncope.core.persistence.api.entity.resource.ExternalResourceHistoryConf) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Component(org.springframework.stereotype.Component) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) OrgUnitTO(org.apache.syncope.common.lib.to.OrgUnitTO) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) IntAttrNameParser(org.apache.syncope.core.provisioning.java.IntAttrNameParser) Collections(java.util.Collections) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ParseException(java.text.ParseException) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName)

Example 15 with MappingTO

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

the class MultitenancyITCase method createResourceAndPull.

@Test
public void createResourceAndPull() {
    // read connector
    ConnInstanceTO conn = adminClient.getService(ConnectorService.class).read("b7ea96c3-c633-488b-98a0-b52ac35850f7", Locale.ENGLISH.getLanguage());
    assertNotNull(conn);
    assertEquals("LDAP", conn.getDisplayName());
    // prepare resource
    ResourceTO resource = new ResourceTO();
    resource.setKey("new-ldap-resource");
    resource.setConnector(conn.getKey());
    try {
        ProvisionTO provisionTO = new ProvisionTO();
        provisionTO.setAnyType(AnyTypeKind.USER.name());
        provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
        resource.getProvisions().add(provisionTO);
        MappingTO mapping = new MappingTO();
        mapping.setConnObjectLink("'uid=' + username + ',ou=people,o=isp'");
        provisionTO.setMapping(mapping);
        ItemTO item = new ItemTO();
        item.setIntAttrName("username");
        item.setExtAttrName("cn");
        item.setPurpose(MappingPurpose.BOTH);
        mapping.setConnObjectKeyItem(item);
        item = new ItemTO();
        item.setPassword(true);
        item.setIntAttrName("password");
        item.setExtAttrName("userPassword");
        item.setPurpose(MappingPurpose.BOTH);
        item.setMandatoryCondition("true");
        mapping.add(item);
        item = new ItemTO();
        item.setIntAttrName("key");
        item.setPurpose(MappingPurpose.BOTH);
        item.setExtAttrName("sn");
        item.setMandatoryCondition("true");
        mapping.add(item);
        item = new ItemTO();
        item.setIntAttrName("email");
        item.setPurpose(MappingPurpose.BOTH);
        item.setExtAttrName("mail");
        mapping.add(item);
        // create resource
        Response response = adminClient.getService(ResourceService.class).create(resource);
        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
        resource = adminClient.getService(ResourceService.class).read(resource.getKey());
        assertNotNull(resource);
        // create pull task
        PullTaskTO task = new PullTaskTO();
        task.setName("LDAP Pull Task");
        task.setActive(true);
        task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
        task.setResource(resource.getKey());
        task.setPullMode(PullMode.FULL_RECONCILIATION);
        task.setPerformCreate(true);
        response = adminClient.getService(TaskService.class).create(TaskType.PULL, task);
        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
        task = adminClient.getService(TaskService.class).read(TaskType.PULL, StringUtils.substringAfterLast(response.getLocation().toASCIIString(), "/"), true);
        assertNotNull(resource);
        // pull
        ExecTO execution = AbstractTaskITCase.execProvisioningTask(adminClient.getService(TaskService.class), TaskType.PULL, task.getKey(), 50, false);
        // verify execution status
        String status = execution.getStatus();
        assertNotNull(status);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(status));
        // verify that pulled user is found
        PagedResult<UserTO> matchingUsers = adminClient.getService(UserService.class).search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").query()).build());
        assertNotNull(matchingUsers);
        assertEquals(1, matchingUsers.getResult().size());
    } finally {
        adminClient.getService(ResourceService.class).delete(resource.getKey());
    }
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) UserService(org.apache.syncope.common.rest.api.service.UserService) TaskService(org.apache.syncope.common.rest.api.service.TaskService) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) ItemTO(org.apache.syncope.common.lib.to.ItemTO) 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) UserTO(org.apache.syncope.common.lib.to.UserTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) Test(org.junit.jupiter.api.Test)

Aggregations

MappingTO (org.apache.syncope.common.lib.to.MappingTO)23 ItemTO (org.apache.syncope.common.lib.to.ItemTO)21 ProvisionTO (org.apache.syncope.common.lib.to.ProvisionTO)21 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)21 Test (org.junit.jupiter.api.Test)17 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)10 Response (javax.ws.rs.core.Response)8 HashSet (java.util.HashSet)6 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)5 GroupTO (org.apache.syncope.common.lib.to.GroupTO)5 ResourceService (org.apache.syncope.common.rest.api.service.ResourceService)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 OrgUnitTO (org.apache.syncope.common.lib.to.OrgUnitTO)4 UserTO (org.apache.syncope.common.lib.to.UserTO)4 ConnConfProperty (org.apache.syncope.common.lib.types.ConnConfProperty)4 MappingPurpose (org.apache.syncope.common.lib.types.MappingPurpose)3 ObjectClass (org.identityconnectors.framework.common.objects.ObjectClass)3 ParseException (java.text.ParseException)2 Collections (java.util.Collections)2