Search in sources :

Example 11 with MappingItem

use of org.apache.syncope.core.persistence.api.entity.resource.MappingItem in project syncope by apache.

the class AbstractPropagationTaskExecutor method getRemoteObject.

/**
 * Get remote object for given task.
 *
 * @param connector connector facade proxy.
 * @param task current propagation task.
 * @param provision provision
 * @param latest 'FALSE' to retrieve object using old connObjectKey if not null.
 * @return remote connector object.
 */
protected ConnectorObject getRemoteObject(final PropagationTask task, final Connector connector, final Provision provision, final boolean latest) {
    String connObjectKey = latest || task.getOldConnObjectKey() == null ? task.getConnObjectKey() : task.getOldConnObjectKey();
    Set<MappingItem> linkingMappingItems = virSchemaDAO.findByProvision(provision).stream().map(schema -> schema.asLinkingMappingItem()).collect(Collectors.toSet());
    ConnectorObject obj = null;
    Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
    if (connObjectKeyItem.isPresent()) {
        try {
            obj = connector.getObject(new ObjectClass(task.getObjectClassName()), AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKey), MappingUtils.buildOperationOptions(new IteratorChain<>(MappingUtils.getPropagationItems(provision.getMapping().getItems()).iterator(), linkingMappingItems.iterator())));
            for (MappingItem item : linkingMappingItems) {
                Attribute attr = obj.getAttributeByName(item.getExtAttrName());
                if (attr == null) {
                    virAttrCache.expire(task.getAnyType(), task.getEntityKey(), item.getIntAttrName());
                } else {
                    VirAttrCacheValue cacheValue = new VirAttrCacheValue();
                    cacheValue.setValues(attr.getValue());
                    virAttrCache.put(task.getAnyType(), task.getEntityKey(), item.getIntAttrName(), cacheValue);
                }
            }
        } catch (TimeoutException toe) {
            LOG.debug("Request timeout", toe);
            throw toe;
        } catch (RuntimeException ignore) {
            LOG.debug("While resolving {}", connObjectKey, ignore);
        }
    }
    return obj;
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AuditElements(org.apache.syncope.common.lib.types.AuditElements) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) NotificationManager(org.apache.syncope.core.provisioning.api.notification.NotificationManager) StringUtils(org.apache.commons.lang3.StringUtils) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) VirAttrCacheValue(org.apache.syncope.core.provisioning.api.cache.VirAttrCacheValue) Attribute(org.identityconnectors.framework.common.objects.Attribute) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) ConnObjectUtils(org.apache.syncope.core.provisioning.java.utils.ConnObjectUtils) Map(java.util.Map) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) ExceptionUtils2(org.apache.syncope.core.provisioning.api.utils.ExceptionUtils2) ExecTO(org.apache.syncope.common.lib.to.ExecTO) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) OrgUnitItem(org.apache.syncope.core.persistence.api.entity.resource.OrgUnitItem) Collection(java.util.Collection) Set(java.util.Set) PropagationActions(org.apache.syncope.core.provisioning.api.propagation.PropagationActions) Collectors(java.util.stream.Collectors) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) ImplementationManager(org.apache.syncope.core.spring.ImplementationManager) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) Connector(org.apache.syncope.core.provisioning.api.Connector) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttributeUtil(org.identityconnectors.framework.common.objects.AttributeUtil) TaskUtilsFactory(org.apache.syncope.core.persistence.api.entity.task.TaskUtilsFactory) AuditManager(org.apache.syncope.core.provisioning.api.AuditManager) AttributeBuilder(org.identityconnectors.framework.common.objects.AttributeBuilder) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) ConnectorFactory(org.apache.syncope.core.provisioning.api.ConnectorFactory) PropagationTaskExecutor(org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor) Optional(java.util.Optional) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) VirAttrCache(org.apache.syncope.core.provisioning.api.cache.VirAttrCache) POJOHelper(org.apache.syncope.core.provisioning.api.serialization.POJOHelper) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) TaskDataBinder(org.apache.syncope.core.provisioning.api.data.TaskDataBinder) ConnectorObjectBuilder(org.identityconnectors.framework.common.objects.ConnectorObjectBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) ArrayList(java.util.ArrayList) TaskDAO(org.apache.syncope.core.persistence.api.dao.TaskDAO) HashSet(java.util.HashSet) Result(org.apache.syncope.common.lib.types.AuditElements.Result) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) TimeoutException(org.apache.syncope.core.provisioning.api.TimeoutException) Logger(org.slf4j.Logger) Uid(org.identityconnectors.framework.common.objects.Uid) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) Name(org.identityconnectors.framework.common.objects.Name) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) Collections(java.util.Collections) TraceLevel(org.apache.syncope.common.lib.types.TraceLevel) Transactional(org.springframework.transaction.annotation.Transactional) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) Attribute(org.identityconnectors.framework.common.objects.Attribute) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) VirAttrCacheValue(org.apache.syncope.core.provisioning.api.cache.VirAttrCacheValue) TimeoutException(org.apache.syncope.core.provisioning.api.TimeoutException)

Example 12 with MappingItem

use of org.apache.syncope.core.persistence.api.entity.resource.MappingItem in project syncope by apache.

the class PlainSchemaTest method deleteSurname.

@Test
public void deleteSurname() {
    // search for user schema fullname
    PlainSchema schema = plainSchemaDAO.find("surname");
    assertNotNull(schema);
    // check for associated mappings
    Set<MappingItem> mappings = new HashSet<>();
    for (ExternalResource resource : resourceDAO.findAll()) {
        if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
            for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
                if (schema.getKey().equals(mapItem.getIntAttrName())) {
                    mappings.add(mapItem);
                }
            }
        }
    }
    assertFalse(mappings.isEmpty());
    // delete user schema fullname
    plainSchemaDAO.delete("surname");
    plainSchemaDAO.flush();
    // check for schema deletion
    schema = plainSchemaDAO.find("surname");
    assertNull(schema);
}
Also used : MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 13 with MappingItem

use of org.apache.syncope.core.persistence.api.entity.resource.MappingItem in project syncope by apache.

the class PlainSchemaTest method deleteFullname.

@Test
public void deleteFullname() {
    // fullname is mapped as ConnObjectKey for ws-target-resource-2, need to swap it otherwise validation errors
    // will be raised
    resourceDAO.find("ws-target-resource-2").getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().forEach(item -> {
        if ("fullname".equals(item.getIntAttrName())) {
            item.setConnObjectKey(false);
        } else if ("surname".equals(item.getIntAttrName())) {
            item.setConnObjectKey(true);
        }
    });
    // search for user schema fullname
    PlainSchema schema = plainSchemaDAO.find("fullname");
    assertNotNull(schema);
    // check for associated mappings
    Set<MappingItem> mapItems = new HashSet<>();
    for (ExternalResource resource : resourceDAO.findAll()) {
        if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
            for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
                if (schema.getKey().equals(mapItem.getIntAttrName())) {
                    mapItems.add(mapItem);
                }
            }
        }
    }
    assertFalse(mapItems.isEmpty());
    // delete user schema fullname
    plainSchemaDAO.delete("fullname");
    plainSchemaDAO.flush();
    // check for schema deletion
    schema = plainSchemaDAO.find("fullname");
    assertNull(schema);
    plainSchemaDAO.clear();
    // check for mappings deletion
    mapItems = new HashSet<>();
    for (ExternalResource resource : resourceDAO.findAll()) {
        if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
            for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
                if ("fullname".equals(mapItem.getIntAttrName())) {
                    mapItems.add(mapItem);
                }
            }
        }
    }
    assertTrue(mapItems.isEmpty());
    assertNull(plainAttrDAO.find("01f22fbd-b672-40af-b528-686d9b27ebc4", UPlainAttr.class));
    assertNull(plainAttrDAO.find(UUID.randomUUID().toString(), UPlainAttr.class));
    assertFalse(userDAO.findByUsername("rossini").getPlainAttr("fullname").isPresent());
    assertFalse(userDAO.findByUsername("vivaldi").getPlainAttr("fullname").isPresent());
}
Also used : MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 14 with MappingItem

use of org.apache.syncope.core.persistence.api.entity.resource.MappingItem in project syncope by apache.

the class ResourceTest method issue243.

@Test
public void issue243() {
    ExternalResource csv = resourceDAO.find("resource-csv");
    assertNotNull(csv);
    int origMapItems = csv.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().size();
    MappingItem newMapItem = entityFactory.newEntity(MappingItem.class);
    newMapItem.setIntAttrName("TEST");
    newMapItem.setExtAttrName("TEST");
    newMapItem.setPurpose(MappingPurpose.PROPAGATION);
    csv.getProvision(anyTypeDAO.findUser()).get().getMapping().add(newMapItem);
    resourceDAO.save(csv);
    resourceDAO.flush();
    csv = resourceDAO.find("resource-csv");
    assertNotNull(csv);
    assertEquals(origMapItems + 1, csv.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().size());
}
Also used : JPAMappingItem(org.apache.syncope.core.persistence.jpa.entity.resource.JPAMappingItem) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 15 with MappingItem

use of org.apache.syncope.core.persistence.api.entity.resource.MappingItem in project syncope by apache.

the class ResourceTest method save.

@Test
public void save() {
    ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
    resource.setKey("ws-target-resource-save");
    // specify the connector
    ConnInstance connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
    assertNotNull(connector);
    resource.setConnector(connector);
    Provision provision = entityFactory.newEntity(Provision.class);
    provision.setAnyType(anyTypeDAO.findUser());
    provision.setObjectClass(ObjectClass.ACCOUNT);
    provision.setResource(resource);
    resource.add(provision);
    Mapping mapping = entityFactory.newEntity(Mapping.class);
    mapping.setProvision(provision);
    provision.setMapping(mapping);
    // specify mappings
    for (int i = 0; i < 3; i++) {
        MappingItem item = entityFactory.newEntity(MappingItem.class);
        item.setExtAttrName("test" + i);
        item.setIntAttrName("nonexistent" + i);
        item.setMandatoryCondition("false");
        item.setPurpose(MappingPurpose.PULL);
        mapping.add(item);
        item.setMapping(mapping);
    }
    MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
    connObjectKey.setExtAttrName("username");
    connObjectKey.setIntAttrName("username");
    connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
    mapping.setConnObjectKeyItem(connObjectKey);
    connObjectKey.setMapping(mapping);
    // map a derived attribute
    MappingItem derived = entityFactory.newEntity(MappingItem.class);
    derived.setConnObjectKey(false);
    derived.setExtAttrName("fullname");
    derived.setIntAttrName("cn");
    derived.setPurpose(MappingPurpose.PROPAGATION);
    mapping.add(derived);
    derived.setMapping(mapping);
    // save the resource
    ExternalResource actual = resourceDAO.save(resource);
    assertNotNull(actual);
    assertNotNull(actual.getProvision(anyTypeDAO.findUser()).get().getMapping());
    resourceDAO.flush();
    resourceDAO.detach(actual);
    connInstanceDAO.detach(connector);
    // assign the new resource to an user
    User user = userDAO.findByUsername("rossini");
    assertNotNull(user);
    user.add(actual);
    resourceDAO.flush();
    // retrieve resource
    resource = resourceDAO.find(actual.getKey());
    assertNotNull(resource);
    resourceDAO.refresh(resource);
    // check connector
    connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
    assertNotNull(connector);
    assertNotNull(connector.getResources());
    assertNotNull(resource.getConnector());
    assertTrue(resource.getConnector().equals(connector));
    // check mappings
    List<? extends MappingItem> items = resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems();
    assertNotNull(items);
    assertEquals(5, items.size());
    // check user
    user = userDAO.findByUsername("rossini");
    assertNotNull(user);
    assertNotNull(user.getResources());
    assertTrue(user.getResources().contains(actual));
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) JPAMappingItem(org.apache.syncope.core.persistence.jpa.entity.resource.JPAMappingItem) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) User(org.apache.syncope.core.persistence.api.entity.user.User) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)24 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)17 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)16 ConnInstance (org.apache.syncope.core.persistence.api.entity.ConnInstance)11 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)10 Test (org.junit.jupiter.api.Test)10 HashSet (java.util.HashSet)9 List (java.util.List)8 Mapping (org.apache.syncope.core.persistence.api.entity.resource.Mapping)7 Attribute (org.identityconnectors.framework.common.objects.Attribute)7 ConnectorObject (org.identityconnectors.framework.common.objects.ConnectorObject)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 IteratorChain (org.apache.syncope.common.lib.collections.IteratorChain)6 VirSchemaDAO (org.apache.syncope.core.persistence.api.dao.VirSchemaDAO)6 Connector (org.apache.syncope.core.provisioning.api.Connector)6 ObjectClass (org.identityconnectors.framework.common.objects.ObjectClass)6 ArrayList (java.util.ArrayList)5 Iterator (java.util.Iterator)5