Search in sources :

Example 1 with StringPatchItem

use of org.apache.syncope.common.lib.patch.StringPatchItem in project syncope by apache.

the class AnyOperations method patch.

public static UserTO patch(final UserTO userTO, final UserPatch userPatch) {
    UserTO result = SerializationUtils.clone(userTO);
    patch(userTO, userPatch, result);
    // 1. password
    if (userPatch.getPassword() != null) {
        result.setPassword(userPatch.getPassword().getValue());
    }
    // 2. username
    if (userPatch.getUsername() != null) {
        result.setUsername(userPatch.getUsername().getValue());
    }
    // 3. relationships
    userPatch.getRelationships().forEach(relPatch -> {
        if (relPatch.getRelationshipTO() == null) {
            LOG.warn("Invalid {} specified: {}", RelationshipPatch.class.getName(), relPatch);
        } else {
            result.getRelationships().remove(relPatch.getRelationshipTO());
            if (relPatch.getOperation() == PatchOperation.ADD_REPLACE) {
                result.getRelationships().add(relPatch.getRelationshipTO());
            }
        }
    });
    // 4. memberships
    userPatch.getMemberships().forEach(membPatch -> {
        if (membPatch.getGroup() == null) {
            LOG.warn("Invalid {} specified: {}", MembershipPatch.class.getName(), membPatch);
        } else {
            Optional<MembershipTO> memb = result.getMemberships().stream().filter(membership -> membPatch.getGroup().equals(membership.getGroupKey())).findFirst();
            if (memb.isPresent()) {
                result.getMemberships().remove(memb.get());
            }
            if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) {
                MembershipTO newMembershipTO = new MembershipTO.Builder().group(membPatch.getGroup()).build();
                // 3. plain attributes
                newMembershipTO.getPlainAttrs().addAll(membPatch.getPlainAttrs());
                // 4. virtual attributes
                newMembershipTO.getVirAttrs().addAll(membPatch.getVirAttrs());
                result.getMemberships().add(newMembershipTO);
            }
        }
    });
    // 5. roles
    for (StringPatchItem rolePatch : userPatch.getRoles()) {
        switch(rolePatch.getOperation()) {
            case ADD_REPLACE:
                result.getRoles().add(rolePatch.getValue());
                break;
            case DELETE:
            default:
                result.getRoles().remove(rolePatch.getValue());
        }
    }
    return result;
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) LoggerFactory(org.slf4j.LoggerFactory) AnyTO(org.apache.syncope.common.lib.to.AnyTO) HashMap(java.util.HashMap) SerializationUtils(org.apache.commons.lang3.SerializationUtils) BooleanReplacePatchItem(org.apache.syncope.common.lib.patch.BooleanReplacePatchItem) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) RelationshipPatch(org.apache.syncope.common.lib.patch.RelationshipPatch) StringUtils(org.apache.commons.lang3.StringUtils) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) AbstractReplacePatchItem(org.apache.syncope.common.lib.patch.AbstractReplacePatchItem) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) Optional(java.util.Optional) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) RelationshipPatch(org.apache.syncope.common.lib.patch.RelationshipPatch)

Example 2 with StringPatchItem

use of org.apache.syncope.common.lib.patch.StringPatchItem in project syncope by apache.

the class AbstractAnyDataBinder method fill.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected PropagationByResource fill(final Any any, final AnyPatch anyPatch, final AnyUtils anyUtils, final SyncopeClientCompositeException scce) {
    PropagationByResource propByRes = new PropagationByResource();
    // 1. anyTypeClasses
    for (StringPatchItem patch : anyPatch.getAuxClasses()) {
        AnyTypeClass auxClass = anyTypeClassDAO.find(patch.getValue());
        if (auxClass == null) {
            LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", patch.getValue());
        } else {
            switch(patch.getOperation()) {
                case ADD_REPLACE:
                    any.add(auxClass);
                    break;
                case DELETE:
                default:
                    any.getAuxClasses().remove(auxClass);
            }
        }
    }
    // 2. resources
    for (StringPatchItem patch : anyPatch.getResources()) {
        ExternalResource resource = resourceDAO.find(patch.getValue());
        if (resource == null) {
            LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", patch.getValue());
        } else {
            switch(patch.getOperation()) {
                case ADD_REPLACE:
                    propByRes.add(ResourceOperation.CREATE, resource.getKey());
                    any.add(resource);
                    break;
                case DELETE:
                default:
                    propByRes.add(ResourceOperation.DELETE, resource.getKey());
                    any.getResources().remove(resource);
            }
        }
    }
    Set<ExternalResource> resources = anyUtils.getAllResources(any);
    SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
    // 3. plain attributes
    anyPatch.getPlainAttrs().stream().filter(patch -> patch.getAttrTO() != null).forEach(patch -> {
        PlainSchema schema = getPlainSchema(patch.getAttrTO().getSchema());
        if (schema == null) {
            LOG.debug("Invalid " + PlainSchema.class.getSimpleName() + " {}, ignoring...", patch.getAttrTO().getSchema());
        } else {
            PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null);
            if (attr == null) {
                LOG.debug("No plain attribute found for schema {}", schema);
                if (patch.getOperation() == PatchOperation.ADD_REPLACE) {
                    attr = anyUtils.newPlainAttr();
                    ((PlainAttr) attr).setOwner(any);
                    attr.setSchema(schema);
                    any.add(attr);
                }
            }
            if (attr != null) {
                processAttrPatch(any, patch, schema, attr, anyUtils, resources, propByRes, invalidValues);
            }
        }
    });
    if (!invalidValues.isEmpty()) {
        scce.addException(invalidValues);
    }
    SyncopeClientException requiredValuesMissing = checkMandatory(any, anyUtils);
    if (!requiredValuesMissing.isEmpty()) {
        scce.addException(requiredValuesMissing);
    }
    requiredValuesMissing = checkMandatoryOnResources(any, resources);
    if (!requiredValuesMissing.isEmpty()) {
        scce.addException(requiredValuesMissing);
    }
    return propByRes;
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) PlainAttr(org.apache.syncope.core.persistence.api.entity.PlainAttr) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) AllowedSchemas(org.apache.syncope.core.persistence.api.dao.AllowedSchemas) JexlUtils(org.apache.syncope.core.provisioning.java.jexl.JexlUtils) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Map(java.util.Map) SchemaDataBinder(org.apache.syncope.core.provisioning.api.data.SchemaDataBinder) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) ParseException(java.text.ParseException) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) RelationshipTypeDAO(org.apache.syncope.core.persistence.api.dao.RelationshipTypeDAO) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Collection(java.util.Collection) DerAttrHandler(org.apache.syncope.core.provisioning.api.DerAttrHandler) Set(java.util.Set) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Optional(java.util.Optional) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyUtilsFactory(org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory) GroupableRelatable(org.apache.syncope.core.persistence.api.entity.GroupableRelatable) AnyTO(org.apache.syncope.common.lib.to.AnyTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) MappingManager(org.apache.syncope.core.provisioning.api.MappingManager) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) Logger(org.slf4j.Logger) PlainSchemaDAO(org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO) VirAttrHandler(org.apache.syncope.core.provisioning.api.VirAttrHandler) Membership(org.apache.syncope.core.persistence.api.entity.Membership) PlainAttrValueDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) IntAttrNameParser(org.apache.syncope.core.provisioning.java.IntAttrNameParser) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) Any(org.apache.syncope.core.persistence.api.entity.Any) PlainAttrDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrDAO) GroupablePlainAttr(org.apache.syncope.core.persistence.api.entity.GroupablePlainAttr) PlainAttr(org.apache.syncope.core.persistence.api.entity.PlainAttr) GroupablePlainAttr(org.apache.syncope.core.persistence.api.entity.GroupablePlainAttr) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)

Example 3 with StringPatchItem

use of org.apache.syncope.common.lib.patch.StringPatchItem in project syncope by apache.

the class UserDataBinderImpl method update.

@Override
public PropagationByResource update(final User toBeUpdated, final UserPatch userPatch) {
    // Re-merge any pending change from workflow tasks
    User user = userDAO.save(toBeUpdated);
    PropagationByResource propByRes = new PropagationByResource();
    SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
    AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.USER);
    Collection<String> currentResources = userDAO.findAllResourceKeys(user.getKey());
    // fetch connObjectKeys before update
    Map<String, String> oldConnObjectKeys = getConnObjectKeys(user, anyUtils);
    // realm
    setRealm(user, userPatch);
    // password
    if (userPatch.getPassword() != null && StringUtils.isNotBlank(userPatch.getPassword().getValue())) {
        if (userPatch.getPassword().isOnSyncope()) {
            setPassword(user, userPatch.getPassword().getValue(), scce);
            user.setChangePwdDate(new Date());
        }
        propByRes.addAll(ResourceOperation.UPDATE, userPatch.getPassword().getResources());
    }
    // username
    if (userPatch.getUsername() != null && StringUtils.isNotBlank(userPatch.getUsername().getValue())) {
        String oldUsername = user.getUsername();
        user.setUsername(userPatch.getUsername().getValue());
        if (oldUsername.equals(AuthContextUtils.getUsername())) {
            AuthContextUtils.updateUsername(userPatch.getUsername().getValue());
        }
        AccessToken accessToken = accessTokenDAO.findByOwner(oldUsername);
        if (accessToken != null) {
            accessToken.setOwner(userPatch.getUsername().getValue());
            accessTokenDAO.save(accessToken);
        }
        propByRes.addAll(ResourceOperation.UPDATE, currentResources);
    }
    // security question / answer:
    if (userPatch.getSecurityQuestion() != null) {
        if (userPatch.getSecurityQuestion().getValue() == null) {
            user.setSecurityQuestion(null);
            user.setSecurityAnswer(null);
        } else {
            SecurityQuestion securityQuestion = securityQuestionDAO.find(userPatch.getSecurityQuestion().getValue());
            if (securityQuestion != null) {
                user.setSecurityQuestion(securityQuestion);
                user.setSecurityAnswer(userPatch.getSecurityAnswer().getValue());
            }
        }
    }
    if (userPatch.getMustChangePassword() != null) {
        user.setMustChangePassword(userPatch.getMustChangePassword().getValue());
    }
    // roles
    for (StringPatchItem patch : userPatch.getRoles()) {
        Role role = roleDAO.find(patch.getValue());
        if (role == null) {
            LOG.warn("Ignoring unknown role with key {}", patch.getValue());
        } else {
            switch(patch.getOperation()) {
                case ADD_REPLACE:
                    user.add(role);
                    break;
                case DELETE:
                default:
                    user.getRoles().remove(role);
            }
        }
    }
    // attributes and resources
    propByRes.merge(fill(user, userPatch, anyUtils, scce));
    // relationships
    userPatch.getRelationships().stream().filter(patch -> patch.getRelationshipTO() != null).forEachOrdered((patch) -> {
        RelationshipType relationshipType = relationshipTypeDAO.find(patch.getRelationshipTO().getType());
        if (relationshipType == null) {
            LOG.debug("Ignoring invalid relationship type {}", patch.getRelationshipTO().getType());
        } else {
            Optional<? extends URelationship> relationship = user.getRelationship(relationshipType, patch.getRelationshipTO().getOtherEndKey());
            if (relationship.isPresent()) {
                user.getRelationships().remove(relationship.get());
                relationship.get().setLeftEnd(null);
            }
            if (patch.getOperation() == PatchOperation.ADD_REPLACE) {
                AnyObject otherEnd = anyObjectDAO.find(patch.getRelationshipTO().getOtherEndKey());
                if (otherEnd == null) {
                    LOG.debug("Ignoring invalid any object {}", patch.getRelationshipTO().getOtherEndKey());
                } else if (user.getRealm().getFullPath().startsWith(otherEnd.getRealm().getFullPath())) {
                    URelationship newRelationship = entityFactory.newEntity(URelationship.class);
                    newRelationship.setType(relationshipType);
                    newRelationship.setRightEnd(otherEnd);
                    newRelationship.setLeftEnd(user);
                    user.add(newRelationship);
                } else {
                    LOG.error("{} cannot be assigned to {}", otherEnd, user);
                    SyncopeClientException unassignable = SyncopeClientException.build(ClientExceptionType.InvalidRelationship);
                    unassignable.getElements().add("Cannot be assigned: " + otherEnd);
                    scce.addException(unassignable);
                }
            }
        }
    });
    // prepare for membership-related resource management
    Collection<ExternalResource> resources = userDAO.findAllResources(user);
    Map<String, Set<String>> reasons = new HashMap<>();
    user.getResources().forEach(resource -> {
        reasons.put(resource.getKey(), new HashSet<>(Collections.singleton(user.getKey())));
    });
    userDAO.findAllGroupKeys(user).forEach(group -> {
        groupDAO.findAllResourceKeys(group).forEach(resource -> {
            if (!reasons.containsKey(resource)) {
                reasons.put(resource, new HashSet<>());
            }
            reasons.get(resource).add(group);
        });
    });
    Set<String> toBeDeprovisioned = new HashSet<>();
    Set<String> toBeProvisioned = new HashSet<>();
    SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
    // memberships
    userPatch.getMemberships().stream().filter(membPatch -> membPatch.getGroup() != null).forEachOrdered((membPatch) -> {
        Optional<? extends UMembership> membership = user.getMembership(membPatch.getGroup());
        if (membership.isPresent()) {
            user.getMemberships().remove(membership.get());
            membership.get().setLeftEnd(null);
            user.getPlainAttrs(membership.get()).forEach(attr -> {
                user.remove(attr);
                attr.setOwner(null);
                attr.setMembership(null);
            });
            if (membPatch.getOperation() == PatchOperation.DELETE) {
                groupDAO.findAllResourceKeys(membership.get().getRightEnd().getKey()).stream().filter(resource -> reasons.containsKey(resource)).forEach(resource -> {
                    reasons.get(resource).remove(membership.get().getRightEnd().getKey());
                    toBeProvisioned.add(resource);
                });
            }
        }
        if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) {
            Group group = groupDAO.find(membPatch.getGroup());
            if (group == null) {
                LOG.debug("Ignoring invalid group {}", membPatch.getGroup());
            } else if (user.getRealm().getFullPath().startsWith(group.getRealm().getFullPath())) {
                UMembership newMembership = entityFactory.newEntity(UMembership.class);
                newMembership.setRightEnd(group);
                newMembership.setLeftEnd(user);
                user.add(newMembership);
                membPatch.getPlainAttrs().forEach(attrTO -> {
                    PlainSchema schema = getPlainSchema(attrTO.getSchema());
                    if (schema == null) {
                        LOG.debug("Invalid " + PlainSchema.class.getSimpleName() + "{}, ignoring...", attrTO.getSchema());
                    } else {
                        UPlainAttr attr = user.getPlainAttr(schema.getKey(), newMembership).orElse(null);
                        if (attr == null) {
                            LOG.debug("No plain attribute found for {} and membership of {}", schema, newMembership.getRightEnd());
                            attr = anyUtils.newPlainAttr();
                            attr.setOwner(user);
                            attr.setMembership(newMembership);
                            attr.setSchema(schema);
                            user.add(attr);
                            AttrPatch patch = new AttrPatch.Builder().attrTO(attrTO).build();
                            processAttrPatch(user, patch, schema, attr, anyUtils, resources, propByRes, invalidValues);
                        }
                    }
                });
                if (!invalidValues.isEmpty()) {
                    scce.addException(invalidValues);
                }
                toBeProvisioned.addAll(groupDAO.findAllResourceKeys(group.getKey()));
                // ensure that they are counted for password propagation
                if (toBeUpdated.canDecodePassword()) {
                    if (userPatch.getPassword() == null) {
                        userPatch.setPassword(new PasswordPatch());
                    }
                    group.getResources().stream().filter(resource -> isPasswordMapped(resource)).forEachOrdered(resource -> {
                        userPatch.getPassword().getResources().add(resource.getKey());
                    });
                }
            } else {
                LOG.error("{} cannot be assigned to {}", group, user);
                SyncopeClientException unassignabled = SyncopeClientException.build(ClientExceptionType.InvalidMembership);
                unassignabled.getElements().add("Cannot be assigned: " + group);
                scce.addException(unassignabled);
            }
        }
    });
    // finalize resource management
    reasons.entrySet().stream().filter(entry -> entry.getValue().isEmpty()).forEach(entry -> toBeDeprovisioned.add(entry.getKey()));
    propByRes.addAll(ResourceOperation.DELETE, toBeDeprovisioned);
    propByRes.addAll(ResourceOperation.UPDATE, toBeProvisioned);
    // attribute values.
    if (!toBeDeprovisioned.isEmpty() || !toBeProvisioned.isEmpty()) {
        currentResources.removeAll(toBeDeprovisioned);
        propByRes.addAll(ResourceOperation.UPDATE, currentResources);
    }
    // check if some connObjectKey was changed by the update above
    Map<String, String> newcCnnObjectKeys = getConnObjectKeys(user, anyUtils);
    oldConnObjectKeys.entrySet().stream().filter(entry -> newcCnnObjectKeys.containsKey(entry.getKey()) && !entry.getValue().equals(newcCnnObjectKeys.get(entry.getKey()))).forEach(entry -> {
        propByRes.addOldConnObjectKey(entry.getKey(), entry.getValue());
        propByRes.add(ResourceOperation.UPDATE, entry.getKey());
    });
    Pair<Set<String>, Set<String>> dynGroupMembs = userDAO.saveAndGetDynGroupMembs(user);
    // finally check if any resource assignment is to be processed due to dynamic group membership change
    dynGroupMembs.getLeft().stream().filter(group -> !dynGroupMembs.getRight().contains(group)).forEach(delete -> {
        groupDAO.find(delete).getResources().stream().filter(resource -> !propByRes.contains(resource.getKey())).forEach(resource -> {
            propByRes.add(ResourceOperation.DELETE, resource.getKey());
        });
    });
    dynGroupMembs.getLeft().stream().filter(group -> dynGroupMembs.getRight().contains(group)).forEach(update -> {
        groupDAO.find(update).getResources().stream().filter(resource -> !propByRes.contains(resource.getKey())).forEach(resource -> {
            propByRes.add(ResourceOperation.UPDATE, resource.getKey());
        });
    });
    dynGroupMembs.getRight().stream().filter(group -> !dynGroupMembs.getLeft().contains(group)).forEach(create -> {
        groupDAO.find(create).getResources().stream().filter(resource -> !propByRes.contains(resource.getKey())).forEach(resource -> {
            propByRes.add(ResourceOperation.CREATE, resource.getKey());
        });
    });
    // Throw composite exception if there is at least one element set in the composing exceptions
    if (scce.hasExceptions()) {
        throw scce;
    }
    return propByRes;
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) SecurityQuestionDAO(org.apache.syncope.core.persistence.api.dao.SecurityQuestionDAO) Date(java.util.Date) Realm(org.apache.syncope.core.persistence.api.entity.Realm) Autowired(org.springframework.beans.factory.annotation.Autowired) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Entity(org.apache.syncope.core.persistence.api.entity.Entity) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) RoleDAO(org.apache.syncope.core.persistence.api.dao.RoleDAO) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) UserDataBinder(org.apache.syncope.core.provisioning.api.data.UserDataBinder) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Role(org.apache.syncope.core.persistence.api.entity.Role) Collection(java.util.Collection) Resource(javax.annotation.Resource) Set(java.util.Set) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) Group(org.apache.syncope.core.persistence.api.entity.group.Group) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Optional(java.util.Optional) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) AccessToken(org.apache.syncope.core.persistence.api.entity.AccessToken) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) BeanUtils(org.apache.syncope.core.spring.BeanUtils) URelationship(org.apache.syncope.core.persistence.api.entity.user.URelationship) HashSet(java.util.HashSet) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) CipherAlgorithm(org.apache.syncope.common.lib.types.CipherAlgorithm) Encryptor(org.apache.syncope.core.spring.security.Encryptor) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) User(org.apache.syncope.core.persistence.api.entity.user.User) AccessTokenDAO(org.apache.syncope.core.persistence.api.dao.AccessTokenDAO) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Component(org.springframework.stereotype.Component) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) RelationshipType(org.apache.syncope.core.persistence.api.entity.RelationshipType) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) SecurityQuestion(org.apache.syncope.core.persistence.api.entity.user.SecurityQuestion) Transactional(org.springframework.transaction.annotation.Transactional) Group(org.apache.syncope.core.persistence.api.entity.group.Group) User(org.apache.syncope.core.persistence.api.entity.user.User) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) RelationshipType(org.apache.syncope.core.persistence.api.entity.RelationshipType) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) SecurityQuestion(org.apache.syncope.core.persistence.api.entity.user.SecurityQuestion) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) AccessToken(org.apache.syncope.core.persistence.api.entity.AccessToken) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) URelationship(org.apache.syncope.core.persistence.api.entity.user.URelationship) HashSet(java.util.HashSet) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Date(java.util.Date) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) Role(org.apache.syncope.core.persistence.api.entity.Role) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils)

Example 4 with StringPatchItem

use of org.apache.syncope.common.lib.patch.StringPatchItem in project syncope by apache.

the class AnyOperations method patch.

private static <T extends AnyTO, K extends AnyPatch> void patch(final T to, final K patch, final T result) {
    // check same key
    if (to.getKey() == null || !to.getKey().equals(patch.getKey())) {
        throw new IllegalArgumentException(to.getClass().getSimpleName() + " and " + patch.getClass().getSimpleName() + " keys must be the same");
    }
    // 0. realm
    if (patch.getRealm() != null) {
        result.setRealm(patch.getRealm().getValue());
    }
    // 1. auxiliary classes
    for (StringPatchItem auxClassPatch : patch.getAuxClasses()) {
        switch(auxClassPatch.getOperation()) {
            case ADD_REPLACE:
                result.getAuxClasses().add(auxClassPatch.getValue());
                break;
            case DELETE:
            default:
                result.getAuxClasses().remove(auxClassPatch.getValue());
        }
    }
    // 2. plain attributes
    result.getPlainAttrs().clear();
    result.getPlainAttrs().addAll(patch(EntityTOUtils.buildAttrMap(to.getPlainAttrs()), patch.getPlainAttrs()));
    // 3. virtual attributes
    result.getVirAttrs().clear();
    result.getVirAttrs().addAll(patch.getVirAttrs());
    // 4. resources
    for (StringPatchItem resourcePatch : patch.getResources()) {
        switch(resourcePatch.getOperation()) {
            case ADD_REPLACE:
                result.getResources().add(resourcePatch.getValue());
                break;
            case DELETE:
            default:
                result.getResources().remove(resourcePatch.getValue());
        }
    }
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem)

Aggregations

StringPatchItem (org.apache.syncope.common.lib.patch.StringPatchItem)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Set (java.util.Set)3 StringUtils (org.apache.commons.lang3.StringUtils)3 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)3 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)3 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)3 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Pair (org.apache.commons.lang3.tuple.Pair)2 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 AnyPatch (org.apache.syncope.common.lib.patch.AnyPatch)2 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)2 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)2 AnyTO (org.apache.syncope.common.lib.to.AnyTO)2