Search in sources :

Example 26 with Attribute

use of org.identityconnectors.framework.common.objects.Attribute in project syncope by apache.

the class AbstractPullResultHandler method doHandle.

/**
 * Look into SyncDelta and take necessary profile.getActions() (create / update / delete) on any object(s).
 *
 * @param delta returned by the underlying profile.getConnector()
 * @param provision provisioning info
 * @throws JobExecutionException in case of pull failure.
 */
protected void doHandle(final SyncDelta delta, final Provision provision) throws JobExecutionException {
    AnyUtils anyUtils = getAnyUtils();
    LOG.debug("Process {} for {} as {}", delta.getDeltaType(), delta.getUid().getUidValue(), delta.getObject().getObjectClass());
    SyncDelta processed = delta;
    for (PullActions action : profile.getActions()) {
        processed = action.preprocess(profile, processed);
    }
    LOG.debug("Transformed {} for {} as {}", processed.getDeltaType(), processed.getUid().getUidValue(), processed.getObject().getObjectClass());
    try {
        List<String> anyKeys = pullUtils.match(processed.getObject(), provision, anyUtils);
        LOG.debug("Match(es) found for {} as {}: {}", processed.getUid().getUidValue(), processed.getObject().getObjectClass(), anyKeys);
        if (anyKeys.size() > 1) {
            switch(profile.getResAct()) {
                case IGNORE:
                    throw new IllegalStateException("More than one match " + anyKeys);
                case FIRSTMATCH:
                    anyKeys = anyKeys.subList(0, 1);
                    break;
                case LASTMATCH:
                    anyKeys = anyKeys.subList(anyKeys.size() - 1, anyKeys.size());
                    break;
                default:
            }
        }
        if (SyncDeltaType.CREATE_OR_UPDATE == processed.getDeltaType()) {
            if (anyKeys.isEmpty()) {
                switch(profile.getTask().getUnmatchingRule()) {
                    case ASSIGN:
                        profile.getResults().addAll(assign(processed, provision, anyUtils));
                        break;
                    case PROVISION:
                        profile.getResults().addAll(provision(processed, provision, anyUtils));
                        break;
                    case IGNORE:
                        profile.getResults().addAll(ignore(processed, null, provision, false));
                        break;
                    default:
                }
            } else {
                // update VirAttrCache
                for (VirSchema virSchema : virSchemaDAO.findByProvision(provision)) {
                    Attribute attr = processed.getObject().getAttributeByName(virSchema.getExtAttrName());
                    for (String anyKey : anyKeys) {
                        if (attr == null) {
                            virAttrCache.expire(provision.getAnyType().getKey(), anyKey, virSchema.getKey());
                        } else {
                            VirAttrCacheValue cacheValue = new VirAttrCacheValue();
                            cacheValue.setValues(attr.getValue());
                            virAttrCache.put(provision.getAnyType().getKey(), anyKey, virSchema.getKey(), cacheValue);
                        }
                    }
                }
                switch(profile.getTask().getMatchingRule()) {
                    case UPDATE:
                        profile.getResults().addAll(update(processed, anyKeys, provision));
                        break;
                    case DEPROVISION:
                        profile.getResults().addAll(deprovision(processed, anyKeys, provision, false));
                        break;
                    case UNASSIGN:
                        profile.getResults().addAll(deprovision(processed, anyKeys, provision, true));
                        break;
                    case LINK:
                        profile.getResults().addAll(link(processed, anyKeys, provision, false));
                        break;
                    case UNLINK:
                        profile.getResults().addAll(link(processed, anyKeys, provision, true));
                        break;
                    case IGNORE:
                        profile.getResults().addAll(ignore(processed, anyKeys, provision, true));
                        break;
                    default:
                }
            }
        } else if (SyncDeltaType.DELETE == processed.getDeltaType()) {
            if (anyKeys.isEmpty()) {
                finalize(ResourceOperation.DELETE.name().toLowerCase(), Result.SUCCESS, null, null, processed);
                LOG.debug("No match found for deletion");
            } else {
                profile.getResults().addAll(delete(processed, anyKeys, provision));
            }
        }
    } catch (IllegalStateException | IllegalArgumentException e) {
        LOG.warn(e.getMessage());
    }
}
Also used : SyncDelta(org.identityconnectors.framework.common.objects.SyncDelta) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) Attribute(org.identityconnectors.framework.common.objects.Attribute) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) VirAttrCacheValue(org.apache.syncope.core.provisioning.api.cache.VirAttrCacheValue) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils)

Example 27 with Attribute

use of org.identityconnectors.framework.common.objects.Attribute in project syncope by apache.

the class LDAPMembershipPullActions method getMembAttrValues.

/**
 * Read values of attribute returned by getGroupMembershipAttrName(); if not present in the given delta, perform an
 * additional read on the underlying connector.
 *
 * @param delta representing the pulling group
 * @param connector associated to the current resource
 * @return value of attribute returned by
 * {@link #getGroupMembershipAttrName}
 */
protected List<Object> getMembAttrValues(final SyncDelta delta, final Connector connector) {
    List<Object> result = Collections.<Object>emptyList();
    String groupMemberName = getGroupMembershipAttrName(connector);
    // first, try to read the configured attribute from delta, returned by the ongoing pull
    Attribute membAttr = delta.getObject().getAttributeByName(groupMemberName);
    // if not found, perform an additional read on the underlying connector for the same connector object
    if (membAttr == null) {
        OperationOptionsBuilder oob = new OperationOptionsBuilder();
        oob.setAttributesToGet(groupMemberName);
        ConnectorObject remoteObj = connector.getObject(ObjectClass.GROUP, delta.getUid(), oob.build());
        if (remoteObj == null) {
            LOG.debug("Object for '{}' not found", delta.getUid().getUidValue());
        } else {
            membAttr = remoteObj.getAttributeByName(groupMemberName);
        }
    }
    if (membAttr != null && membAttr.getValue() != null) {
        result = membAttr.getValue();
    }
    return result;
}
Also used : Attribute(org.identityconnectors.framework.common.objects.Attribute) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) OperationOptionsBuilder(org.identityconnectors.framework.common.objects.OperationOptionsBuilder)

Example 28 with Attribute

use of org.identityconnectors.framework.common.objects.Attribute in project syncope by apache.

the class MappingManagerImpl method prepareAttrs.

@Transactional(readOnly = true)
@Override
public Pair<String, Set<Attribute>> prepareAttrs(final Any<?> any, final String password, final boolean changePwd, final Boolean enable, final Provision provision) {
    LOG.debug("Preparing resource attributes for {} with provision {} for attributes {}", any, provision, any.getPlainAttrs());
    Set<Attribute> attributes = new HashSet<>();
    String connObjectKey = null;
    for (Item mapItem : MappingUtils.getPropagationItems(provision.getMapping().getItems())) {
        LOG.debug("Processing expression '{}'", mapItem.getIntAttrName());
        try {
            Pair<String, Attribute> preparedAttr = prepareAttr(provision, mapItem, any, password);
            if (preparedAttr != null) {
                if (preparedAttr.getLeft() != null) {
                    connObjectKey = preparedAttr.getLeft();
                }
                if (preparedAttr.getRight() != null) {
                    Attribute alreadyAdded = AttributeUtil.find(preparedAttr.getRight().getName(), attributes);
                    if (alreadyAdded == null) {
                        attributes.add(preparedAttr.getRight());
                    } else {
                        attributes.remove(alreadyAdded);
                        Set<Object> values = new HashSet<>();
                        if (alreadyAdded.getValue() != null && !alreadyAdded.getValue().isEmpty()) {
                            values.addAll(alreadyAdded.getValue());
                        }
                        if (preparedAttr.getRight().getValue() != null) {
                            values.addAll(preparedAttr.getRight().getValue());
                        }
                        attributes.add(AttributeBuilder.build(preparedAttr.getRight().getName(), values));
                    }
                }
            }
        } catch (Exception e) {
            LOG.error("Expression '{}' processing failed", mapItem.getIntAttrName(), e);
        }
    }
    Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
    if (connObjectKeyItem.isPresent()) {
        Attribute connObjectKeyExtAttr = AttributeUtil.find(connObjectKeyItem.get().getExtAttrName(), attributes);
        if (connObjectKeyExtAttr != null) {
            attributes.remove(connObjectKeyExtAttr);
            attributes.add(AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKey));
        }
        Name name = MappingUtils.evaluateNAME(any, provision, connObjectKey);
        attributes.add(name);
        if (connObjectKey != null && !connObjectKey.equals(name.getNameValue()) && connObjectKeyExtAttr == null) {
            attributes.add(AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKey));
        }
    }
    if (enable != null) {
        attributes.add(AttributeBuilder.buildEnabled(enable));
    }
    if (!changePwd) {
        Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes);
        if (pwdAttr != null) {
            attributes.remove(pwdAttr);
        }
    }
    return Pair.of(connObjectKey, attributes);
}
Also used : OrgUnitItem(org.apache.syncope.core.persistence.api.entity.resource.OrgUnitItem) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Item(org.apache.syncope.core.persistence.api.entity.resource.Item) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Attribute(org.identityconnectors.framework.common.objects.Attribute) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) ParseException(java.text.ParseException) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) HashSet(java.util.HashSet) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) Name(org.identityconnectors.framework.common.objects.Name) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with Attribute

use of org.identityconnectors.framework.common.objects.Attribute in project syncope by apache.

the class VirAttrHandlerImpl method getValues.

private Map<VirSchema, List<String>> getValues(final Any<?> any, final Set<VirSchema> schemas) {
    Set<ExternalResource> ownedResources = anyUtilsFactory.getInstance(any).getAllResources(any);
    Map<VirSchema, List<String>> result = new HashMap<>();
    Map<Provision, Set<VirSchema>> toRead = new HashMap<>();
    for (VirSchema schema : schemas) {
        if (ownedResources.contains(schema.getProvision().getResource())) {
            VirAttrCacheValue virAttrCacheValue = virAttrCache.get(any.getType().getKey(), any.getKey(), schema.getKey());
            if (virAttrCache.isValidEntry(virAttrCacheValue)) {
                LOG.debug("Values for {} found in cache: {}", schema, virAttrCacheValue);
                result.put(schema, virAttrCacheValue.getValues());
            } else {
                Set<VirSchema> schemasToRead = toRead.get(schema.getProvision());
                if (schemasToRead == null) {
                    schemasToRead = new HashSet<>();
                    toRead.put(schema.getProvision(), schemasToRead);
                }
                schemasToRead.add(schema);
            }
        } else {
            LOG.debug("Not considering {} since {} is not assigned to {}", schema, any, schema.getProvision().getResource());
        }
    }
    for (Map.Entry<Provision, Set<VirSchema>> entry : toRead.entrySet()) {
        LOG.debug("About to read from {}: {}", entry.getKey(), entry.getValue());
        Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(entry.getKey());
        String connObjectKeyValue = connObjectKeyItem.isPresent() ? mappingManager.getConnObjectKeyValue(any, entry.getKey()).orElse(null) : null;
        if (!connObjectKeyItem.isPresent() || connObjectKeyValue == null) {
            LOG.error("No ConnObjectKey or value found for {}, ignoring...", entry.getKey());
        } else {
            Set<MappingItem> linkingMappingItems = new HashSet<>();
            linkingMappingItems.add(connObjectKeyItem.get());
            linkingMappingItems.addAll(entry.getValue().stream().map(schema -> schema.asLinkingMappingItem()).collect(Collectors.toSet()));
            Connector connector = connFactory.getConnector(entry.getKey().getResource());
            try {
                ConnectorObject connectorObject = connector.getObject(entry.getKey().getObjectClass(), AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKeyValue), MappingUtils.buildOperationOptions(linkingMappingItems.iterator()));
                if (connectorObject == null) {
                    LOG.debug("No read from {} with filter '{} == {}'", entry.getKey(), connObjectKeyItem.get().getExtAttrName(), connObjectKeyValue);
                } else {
                    entry.getValue().forEach(schema -> {
                        Attribute attr = connectorObject.getAttributeByName(schema.getExtAttrName());
                        if (attr != null) {
                            VirAttrCacheValue virAttrCacheValue = new VirAttrCacheValue();
                            virAttrCacheValue.setValues(attr.getValue());
                            virAttrCache.put(any.getType().getKey(), any.getKey(), schema.getKey(), virAttrCacheValue);
                            LOG.debug("Values for {} set in cache: {}", schema, virAttrCacheValue);
                            result.put(schema, virAttrCacheValue.getValues());
                        }
                    });
                }
            } catch (Exception e) {
                LOG.error("Error reading from {}", entry.getKey(), e);
            }
        }
    }
    return result;
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) Connector(org.apache.syncope.core.provisioning.api.Connector) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) HashSet(java.util.HashSet) Set(java.util.Set) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) HashMap(java.util.HashMap) Attribute(org.identityconnectors.framework.common.objects.Attribute) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) VirAttrCacheValue(org.apache.syncope.core.provisioning.api.cache.VirAttrCacheValue) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 30 with Attribute

use of org.identityconnectors.framework.common.objects.Attribute in project syncope by apache.

the class TaskTest method save.

@Test
public void save() {
    ExternalResource resource = resourceDAO.find("ws-target-resource-1");
    assertNotNull(resource);
    User user = userDAO.findByUsername("verdi");
    assertNotNull(user);
    PropagationTask task = entityFactory.newEntity(PropagationTask.class);
    task.setResource(resource);
    task.setAnyTypeKind(AnyTypeKind.USER);
    task.setAnyType(AnyTypeKind.USER.name());
    task.setOperation(ResourceOperation.CREATE);
    task.setConnObjectKey("one@two.com");
    Set<Attribute> attributes = new HashSet<>();
    attributes.add(AttributeBuilder.build("testAttribute", "testValue1", "testValue2"));
    attributes.add(AttributeBuilder.buildPassword("password".toCharArray()));
    task.setAttributes(attributes);
    task = taskDAO.save(task);
    assertNotNull(task);
    PropagationTask actual = taskDAO.find(task.getKey());
    assertEquals(task, actual);
    taskDAO.flush();
    resource = resourceDAO.find("ws-target-resource-1");
    assertTrue(taskDAO.findAll(TaskType.PROPAGATION, resource, null, null, null, -1, -1, Collections.<OrderByClause>emptyList()).contains(task));
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) Attribute(org.identityconnectors.framework.common.objects.Attribute) 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)

Aggregations

Attribute (org.identityconnectors.framework.common.objects.Attribute)35 HashSet (java.util.HashSet)19 ArrayList (java.util.ArrayList)14 ConnectorObject (org.identityconnectors.framework.common.objects.ConnectorObject)12 Transactional (org.springframework.transaction.annotation.Transactional)12 User (org.apache.syncope.core.persistence.api.entity.user.User)11 List (java.util.List)10 Set (java.util.Set)10 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)10 Uid (org.identityconnectors.framework.common.objects.Uid)10 ObjectClass (org.identityconnectors.framework.common.objects.ObjectClass)9 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)8 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)8 Name (org.identityconnectors.framework.common.objects.Name)8 AttributeBuilder (org.identityconnectors.framework.common.objects.AttributeBuilder)7 Map (java.util.Map)6 StringUtils (org.apache.commons.lang3.StringUtils)6 GroupDAO (org.apache.syncope.core.persistence.api.dao.GroupDAO)6 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)6 OrgUnitItem (org.apache.syncope.core.persistence.api.entity.resource.OrgUnitItem)6