Search in sources :

Example 16 with AnyUtils

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

the class AbstractAnySearchDAO method check.

protected Pair<PlainSchema, PlainAttrValue> check(final AttributeCond cond, final AnyTypeKind kind) {
    AnyUtils attrUtils = anyUtilsFactory.getInstance(kind);
    PlainSchema schema = schemaDAO.find(cond.getSchema());
    if (schema == null) {
        LOG.warn("Ignoring invalid schema '{}'", cond.getSchema());
        throw new IllegalArgumentException();
    }
    PlainAttrValue attrValue = attrUtils.newPlainAttrValue();
    try {
        if (cond.getType() != AttributeCond.Type.LIKE && cond.getType() != AttributeCond.Type.ILIKE && cond.getType() != AttributeCond.Type.ISNULL && cond.getType() != AttributeCond.Type.ISNOTNULL) {
            ((JPAPlainSchema) schema).validator().validate(cond.getExpression(), attrValue);
        }
    } catch (ValidationException e) {
        LOG.error("Could not validate expression '" + cond.getExpression() + "'", e);
        throw new IllegalArgumentException();
    }
    return Pair.of(schema, attrValue);
}
Also used : ValidationException(javax.validation.ValidationException) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) JPAPlainSchema(org.apache.syncope.core.persistence.jpa.entity.JPAPlainSchema) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils)

Example 17 with AnyUtils

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

the class GoogleAppsPullActions method afterAll.

@Transactional
@Override
public void afterAll(final ProvisioningProfile<?, ?> profile) throws JobExecutionException {
    googleAppsIds.forEach((key, value) -> {
        User user = userDAO.find(key);
        if (user == null) {
            LOG.error("Could not find user {}, skipping", key);
        } else {
            AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
            // 1. stores the __UID__ received by Google
            PlainSchema googleAppsId = plainSchemaDAO.find(getGoogleAppsIdSchema());
            if (googleAppsId == null) {
                LOG.error("Could not find schema googleAppsId, skipping");
            } else {
                UPlainAttr attr = user.getPlainAttr(getGoogleAppsIdSchema()).orElse(null);
                if (attr == null) {
                    attr = entityFactory.newEntity(UPlainAttr.class);
                    attr.setSchema(googleAppsId);
                    attr.setOwner(user);
                    user.add(attr);
                    try {
                        attr.add(value, anyUtils);
                        userDAO.save(user);
                    } catch (InvalidPlainAttrValueException e) {
                        LOG.error("Invalid value for attribute {}: {}", googleAppsId.getKey(), value, e);
                    }
                } else {
                    LOG.debug("User {} has already a googleAppsId assigned: {}", user, attr.getValuesAsStrings());
                }
            }
        }
    });
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with AnyUtils

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

the class ElasticsearchAnySearchDAO method addSort.

private void addSort(final SearchRequestBuilder builder, final AnyTypeKind kind, final List<OrderByClause> orderBy) {
    AnyUtils attrUtils = anyUtilsFactory.getInstance(kind);
    orderBy.forEach(clause -> {
        String sortName = null;
        // Manage difference among external key attribute and internal JPA @Id
        String fieldName = "key".equals(clause.getField()) ? "id" : clause.getField();
        Field anyField = ReflectionUtils.findField(attrUtils.anyClass(), fieldName);
        if (anyField == null) {
            PlainSchema schema = schemaDAO.find(fieldName);
            if (schema != null) {
                sortName = fieldName;
            }
        } else {
            sortName = fieldName;
        }
        if (sortName == null) {
            LOG.warn("Cannot build any valid clause from {}", clause);
        } else {
            builder.addSort(sortName, SortOrder.valueOf(clause.getDirection().name()));
        }
    });
}
Also used : Field(java.lang.reflect.Field) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils)

Example 19 with AnyUtils

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

the class GoogleAppsPropagationActions method after.

@Transactional
@Override
public void after(final PropagationTask task, final TaskExec execution, final ConnectorObject afterObj) {
    if (task.getOperation() == ResourceOperation.DELETE || task.getOperation() == ResourceOperation.NONE) {
        return;
    }
    if (AnyTypeKind.USER != task.getAnyTypeKind()) {
        return;
    }
    User user = userDAO.find(task.getEntityKey());
    if (user == null) {
        LOG.error("Could not find user {}, skipping", task.getEntityKey());
    } else {
        boolean modified = false;
        AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
        PlainSchema googleAppsId = plainSchemaDAO.find(getGoogleAppsIdSchema());
        if (googleAppsId == null) {
            LOG.error("Could not find schema {}, skipping", getGoogleAppsIdSchema());
        } else {
            // set back the __UID__ received by Google
            UPlainAttr attr = user.getPlainAttr(getGoogleAppsIdSchema()).orElse(null);
            if (attr == null) {
                attr = entityFactory.newEntity(UPlainAttr.class);
                attr.setSchema(googleAppsId);
                attr.setOwner(user);
                user.add(attr);
                try {
                    attr.add(afterObj.getUid().getUidValue(), anyUtils);
                    modified = true;
                } catch (InvalidPlainAttrValueException e) {
                    LOG.error("Invalid value for attribute {}: {}", googleAppsId.getKey(), afterObj.getUid().getUidValue(), e);
                }
            } else {
                LOG.debug("User {} has already {} assigned: {}", user, googleAppsId.getKey(), attr.getValuesAsStrings());
            }
        }
        if (modified) {
            userDAO.save(user);
        }
    }
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with AnyUtils

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

Aggregations

AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)25 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)15 Realm (org.apache.syncope.core.persistence.api.entity.Realm)11 List (java.util.List)10 StringUtils (org.apache.commons.lang3.StringUtils)10 User (org.apache.syncope.core.persistence.api.entity.user.User)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 Collections (java.util.Collections)9 Set (java.util.Set)9 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)9 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)9 VirSchema (org.apache.syncope.core.persistence.api.entity.VirSchema)9 Transactional (org.springframework.transaction.annotation.Transactional)9 HashMap (java.util.HashMap)8 Group (org.apache.syncope.core.persistence.api.entity.group.Group)8 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 Optional (java.util.Optional)7 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)7