Search in sources :

Example 16 with VirSchema

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

the class NotificationManagerImpl method getRecipientEmail.

private String getRecipientEmail(final String recipientAttrName, final User user) {
    String email = null;
    IntAttrName intAttrName;
    try {
        intAttrName = intAttrNameParser.parse(recipientAttrName, AnyTypeKind.USER);
    } catch (ParseException e) {
        LOG.error("Invalid intAttrName '{}' specified as recipient, ignoring", recipientAttrName, e);
        return email;
    }
    if ("username".equals(intAttrName.getField())) {
        email = user.getUsername();
    } else if (intAttrName.getSchemaType() != null) {
        UMembership membership = null;
        if (intAttrName.getMembershipOfGroup() != null) {
            Group group = groupDAO.findByName(intAttrName.getMembershipOfGroup());
            if (group != null) {
                membership = user.getMembership(group.getKey()).orElse(null);
            }
        }
        switch(intAttrName.getSchemaType()) {
            case PLAIN:
                Optional<? extends UPlainAttr> attr = membership == null ? user.getPlainAttr(recipientAttrName) : user.getPlainAttr(recipientAttrName, membership);
                if (attr.isPresent()) {
                    email = attr.get().getValuesAsStrings().isEmpty() ? null : attr.get().getValuesAsStrings().get(0);
                }
                break;
            case DERIVED:
                DerSchema schema = derSchemaDAO.find(recipientAttrName);
                if (schema == null) {
                    LOG.warn("Ignoring non existing {} {}", DerSchema.class.getSimpleName(), recipientAttrName);
                } else {
                    email = membership == null ? derAttrHander.getValue(user, schema) : derAttrHander.getValue(user, membership, schema);
                }
                break;
            case VIRTUAL:
                VirSchema virSchema = virSchemaDAO.find(recipientAttrName);
                if (virSchema == null) {
                    LOG.warn("Ignoring non existing {} {}", VirSchema.class.getSimpleName(), recipientAttrName);
                } else {
                    List<String> virAttrValues = membership == null ? virAttrHander.getValues(user, virSchema) : virAttrHander.getValues(user, membership, virSchema);
                    email = virAttrValues.isEmpty() ? null : virAttrValues.get(0);
                }
                break;
            default:
        }
    }
    return email;
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) Optional(java.util.Optional) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) List(java.util.List) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName)

Example 17 with VirSchema

use of org.apache.syncope.core.persistence.api.entity.VirSchema 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 18 with VirSchema

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

the class AnyObjectDataBinderImpl method getAnyObjectTO.

@Override
public AnyObjectTO getAnyObjectTO(final AnyObject anyObject, final boolean details) {
    AnyObjectTO anyObjectTO = new AnyObjectTO();
    anyObjectTO.setType(anyObject.getType().getKey());
    BeanUtils.copyProperties(anyObject, anyObjectTO, IGNORE_PROPERTIES);
    Map<VirSchema, List<String>> virAttrValues = details ? virAttrHandler.getValues(anyObject) : Collections.<VirSchema, List<String>>emptyMap();
    fillTO(anyObjectTO, anyObject.getRealm().getFullPath(), anyObject.getAuxClasses(), anyObject.getPlainAttrs(), derAttrHandler.getValues(anyObject), virAttrValues, anyObjectDAO.findAllResources(anyObject), details);
    if (details) {
        // dynamic realms
        anyObjectTO.getDynRealms().addAll(userDAO.findDynRealms(anyObject.getKey()));
        // relationships
        anyObjectTO.getRelationships().addAll(anyObjectDAO.findAllRelationships(anyObject).stream().map(relationship -> getRelationshipTO(relationship.getType().getKey(), relationship.getLeftEnd().getKey().equals(anyObject.getKey()) ? relationship.getRightEnd() : relationship.getLeftEnd())).collect(Collectors.toList()));
        // memberships
        anyObjectTO.getMemberships().addAll(anyObject.getMemberships().stream().map(membership -> {
            return getMembershipTO(anyObject.getPlainAttrs(membership), derAttrHandler.getValues(anyObject, membership), virAttrHandler.getValues(anyObject, membership), membership);
        }).collect(Collectors.toList()));
        // dynamic memberships
        anyObjectTO.getDynMemberships().addAll(anyObjectDAO.findDynGroups(anyObject.getKey()).stream().map(group -> {
            return new MembershipTO.Builder().group(group.getKey(), group.getName()).build();
        }).collect(Collectors.toList()));
    }
    return anyObjectTO;
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) List(java.util.List)

Example 19 with VirSchema

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

the class AnyTypeClassDataBinderImpl method update.

@Override
public void update(final AnyTypeClass anyTypeClass, final AnyTypeClassTO anyTypeClassTO) {
    if (anyTypeClass.getKey() == null) {
        anyTypeClass.setKey(anyTypeClassTO.getKey());
    }
    plainSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach(schema -> {
        schema.setAnyTypeClass(null);
    });
    anyTypeClass.getPlainSchemas().clear();
    anyTypeClassTO.getPlainSchemas().forEach(schemaName -> {
        PlainSchema schema = plainSchemaDAO.find(schemaName);
        if (schema == null || schema.getAnyTypeClass() != null) {
            LOG.debug("Invalid or already in use" + PlainSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
        } else {
            anyTypeClass.add(schema);
        }
    });
    derSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach((schema) -> {
        schema.setAnyTypeClass(null);
    });
    anyTypeClass.getDerSchemas().clear();
    anyTypeClassTO.getDerSchemas().forEach(schemaName -> {
        DerSchema schema = derSchemaDAO.find(schemaName);
        if (schema == null || schema.getAnyTypeClass() != null) {
            LOG.debug("Invalid or already in use" + DerSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
        } else {
            anyTypeClass.add(schema);
        }
    });
    virSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach(schema -> {
        schema.setAnyTypeClass(null);
    });
    anyTypeClass.getVirSchemas().clear();
    anyTypeClassTO.getVirSchemas().forEach(schemaName -> {
        VirSchema schema = virSchemaDAO.find(schemaName);
        if (schema == null || schema.getAnyTypeClass() != null) {
            LOG.debug("Invalid or already in use" + VirSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
        } else {
            anyTypeClass.add(schema);
        }
    });
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema)

Example 20 with VirSchema

use of org.apache.syncope.core.persistence.api.entity.VirSchema 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)

Aggregations

VirSchema (org.apache.syncope.core.persistence.api.entity.VirSchema)26 DerSchema (org.apache.syncope.core.persistence.api.entity.DerSchema)10 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)10 List (java.util.List)9 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)9 HashSet (java.util.HashSet)6 AnyTypeClass (org.apache.syncope.core.persistence.api.entity.AnyTypeClass)6 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)6 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 Date (java.util.Date)5 OrgUnit (org.apache.syncope.core.persistence.api.entity.resource.OrgUnit)5 ParseException (java.text.ParseException)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)4 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)4 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)3 VirSchemaDAO (org.apache.syncope.core.persistence.api.dao.VirSchemaDAO)3 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)3