Search in sources :

Example 1 with ContainerDelta

use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.

the class BaseCertificationHandler method revokeAssignmentCase.

//	@NotNull
//	protected <F extends FocusType> FocusType castToFocus(PrismObject<F> objectPrism) {
//		ObjectType object = objectPrism.asObjectable();
//		if (!(object instanceof FocusType)) {
//			throw new IllegalStateException(ExclusionCertificationHandler.class.getSimpleName() + " cannot be run against non-focal object: " + ObjectTypeUtil
//					.toShortString(object));
//		}
//		return (FocusType) object;
//	}
// TODO move to some helper?
protected void revokeAssignmentCase(AccessCertificationAssignmentCaseType assignmentCase, AccessCertificationCampaignType campaign, OperationResult caseResult, Task task) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    String objectOid = assignmentCase.getObjectRef().getOid();
    Class<? extends Objectable> clazz = ObjectTypes.getObjectTypeFromTypeQName(assignmentCase.getObjectRef().getType()).getClassDefinition();
    PrismContainerValue<AssignmentType> cval = assignmentCase.getAssignment().asPrismContainerValue().clone();
    ContainerDelta assignmentDelta;
    if (Boolean.TRUE.equals(assignmentCase.isIsInducement())) {
        assignmentDelta = ContainerDelta.createModificationDelete(AbstractRoleType.F_INDUCEMENT, clazz, prismContext, cval);
    } else {
        assignmentDelta = ContainerDelta.createModificationDelete(FocusType.F_ASSIGNMENT, clazz, prismContext, cval);
    }
    @SuppressWarnings({ "unchecked", "raw" }) ObjectDelta<? extends ObjectType> objectDelta = (ObjectDelta<? extends ObjectType>) ObjectDelta.createModifyDelta(objectOid, Collections.singletonList(assignmentDelta), clazz, prismContext);
    LOGGER.info("Going to execute delta: {}", objectDelta.debugDump());
    modelService.executeChanges(Collections.singletonList(objectDelta), null, task, caseResult);
    LOGGER.info("Case {} in {} ({} {} of {}) was successfully revoked", assignmentCase.asPrismContainerValue().getId(), ObjectTypeUtil.toShortString(campaign), Boolean.TRUE.equals(assignmentCase.isIsInducement()) ? "inducement" : "assignment", cval.getId(), objectOid);
}
Also used : ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 2 with ContainerDelta

use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.

the class ProjectionCredentialsProcessor method applyMetadata.

private <F extends FocusType> void applyMetadata(LensContext<F> context, final LensProjectionContext projectionContext, XMLGregorianCalendar now, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, PolicyViolationException {
    ObjectDelta<ShadowType> accountDelta = projectionContext.getDelta();
    if (projectionContext.isDelete()) {
        return;
    }
    if (accountDelta == null) {
        LOGGER.trace("Skipping application of password metadata. Shadow delta not specified.");
        return;
    }
    PropertyDelta<ProtectedStringType> passwordValueDelta = accountDelta.findPropertyDelta(SchemaConstants.PATH_PASSWORD_VALUE);
    if (passwordValueDelta == null) {
        LOGGER.trace("Skipping application of password metadata. No password change.");
        return;
    }
    if (projectionContext.isAdd()) {
        MetadataType metadataType = operationalDataManager.createCreateMetadata(context, now, task);
        ContainerDelta<MetadataType> metadataDelta = ContainerDelta.createDelta(SchemaConstants.PATH_PASSWORD_METADATA, projectionContext.getObjectDefinition());
        PrismContainerValue cval = metadataType.asPrismContainerValue();
        cval.setOriginTypeRecursive(OriginType.OUTBOUND);
        metadataDelta.addValuesToAdd(metadataType.asPrismContainerValue());
        projectionContext.swallowToSecondaryDelta(metadataDelta);
    } else if (projectionContext.isModify()) {
        ContainerDelta<MetadataType> metadataDelta = accountDelta.findContainerDelta(SchemaConstants.PATH_PASSWORD_METADATA);
        if (metadataDelta == null) {
            Collection<? extends ItemDelta<?, ?>> modifyMetadataDeltas = operationalDataManager.createModifyMetadataDeltas(context, SchemaConstants.PATH_PASSWORD_METADATA, projectionContext.getObjectDefinition(), now, task);
            for (ItemDelta itemDelta : modifyMetadataDeltas) {
                itemDelta.setOriginTypeRecursive(OriginType.OUTBOUND);
                projectionContext.swallowToSecondaryDelta(itemDelta);
            }
        }
    }
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) MetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType) Collection(java.util.Collection) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 3 with ContainerDelta

use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.

the class PageRegistrationConfirmation method assignDefaultRoles.

private OperationResult assignDefaultRoles(final String userOid) {
    List<ContainerDelta<AssignmentType>> assignments = new ArrayList<>();
    for (ObjectReferenceType defaultRole : getSelfRegistrationConfiguration().getDefaultRoles()) {
        AssignmentType assignment = new AssignmentType();
        assignment.setTargetRef(defaultRole);
        try {
            getPrismContext().adopt(assignment);
            assignments.add(ContainerDelta.createModificationAdd(UserType.F_ASSIGNMENT, UserType.class, getPrismContext(), assignment));
        } catch (SchemaException e) {
        //nothing to do
        }
    }
    final ObjectDelta<UserType> delta = ObjectDelta.createModifyDelta(userOid, assignments, UserType.class, getPrismContext());
    return runPrivileged(new Producer<OperationResult>() {

        @Override
        public OperationResult run() {
            OperationResult result = new OperationResult(OPERATION_ASSIGN_DEFAULT_ROLES);
            Task task = createAnonymousTask(OPERATION_ASSIGN_DEFAULT_ROLES);
            WebModelServiceUtils.save(delta, result, task, PageRegistrationConfirmation.this);
            result.computeStatusIfUnknown();
            return result;
        }
    });
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) Task(com.evolveum.midpoint.task.api.Task) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 4 with ContainerDelta

use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.

the class PageAssignmentsList method handleAssignmentDeltas.

private ContainerDelta handleAssignmentDeltas(ObjectDelta<UserType> focusDelta, List<AssignmentEditorDto> assignments, PrismContainerDefinition def) throws SchemaException {
    ContainerDelta assDelta = new ContainerDelta(new ItemPath(), def.getName(), def, getPrismContext());
    for (AssignmentEditorDto assDto : assignments) {
        PrismContainerValue newValue = assDto.getNewValue(getPrismContext());
        switch(assDto.getStatus()) {
            case ADD:
                newValue.applyDefinition(def, false);
                assDelta.addValueToAdd(newValue.clone());
                break;
            case DELETE:
                PrismContainerValue oldValue = assDto.getOldValue();
                oldValue.applyDefinition(def);
                assDelta.addValueToDelete(oldValue.clone());
                break;
            case MODIFY:
                if (!assDto.isModified(getPrismContext())) {
                    LOGGER.trace("Assignment '{}' not modified.", new Object[] { assDto.getName() });
                    continue;
                }
                handleModifyAssignmentDelta(assDto, def, newValue, focusDelta);
                break;
            default:
                warn(getString("pageAdminUser.message.illegalAssignmentState", assDto.getStatus()));
        }
    }
    if (!assDelta.isEmpty()) {
        assDelta = focusDelta.addModification(assDelta);
    }
    return assDelta;
}
Also used : AssignmentEditorDto(com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 5 with ContainerDelta

use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.

the class ShadowManager method extractRepoShadowChanges.

@SuppressWarnings("rawtypes")
private Collection<? extends ItemDelta> extractRepoShadowChanges(ProvisioningContext ctx, PrismObject<ShadowType> shadow, Collection<? extends ItemDelta> objectChange) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
    CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
    Collection<ItemDelta> repoChanges = new ArrayList<ItemDelta>();
    for (ItemDelta itemDelta : objectChange) {
        if (new ItemPath(ShadowType.F_ATTRIBUTES).equivalent(itemDelta.getParentPath())) {
            QName attrName = itemDelta.getElementName();
            if (objectClassDefinition.isSecondaryIdentifier(attrName)) {
                // Change of secondary identifier means object rename. We also need to change $shadow/name
                // TODO: change this to displayName attribute later
                String newName = null;
                if (itemDelta.getValuesToReplace() != null && !itemDelta.getValuesToReplace().isEmpty()) {
                    newName = ((PrismPropertyValue) itemDelta.getValuesToReplace().iterator().next()).getValue().toString();
                } else if (itemDelta.getValuesToAdd() != null && !itemDelta.getValuesToAdd().isEmpty()) {
                    newName = ((PrismPropertyValue) itemDelta.getValuesToAdd().iterator().next()).getValue().toString();
                }
                PropertyDelta<PolyString> nameDelta = PropertyDelta.createReplaceDelta(shadow.getDefinition(), ShadowType.F_NAME, new PolyString(newName));
                repoChanges.add(nameDelta);
            }
            if (!ProvisioningUtil.shouldStoreAtributeInShadow(objectClassDefinition, attrName, cachingStrategy)) {
                continue;
            }
        } else if (new ItemPath(ShadowType.F_ACTIVATION).equivalent(itemDelta.getParentPath())) {
            if (!ProvisioningUtil.shouldStoreActivationItemInShadow(itemDelta.getElementName(), cachingStrategy)) {
                continue;
            }
        } else if (new ItemPath(ShadowType.F_ACTIVATION).equivalent(itemDelta.getPath())) {
            // should not occur, but for completeness...
            for (PrismContainerValue<ActivationType> valueToAdd : ((ContainerDelta<ActivationType>) itemDelta).getValuesToAdd()) {
                ProvisioningUtil.cleanupShadowActivation(valueToAdd.asContainerable());
            }
            for (PrismContainerValue<ActivationType> valueToReplace : ((ContainerDelta<ActivationType>) itemDelta).getValuesToReplace()) {
                ProvisioningUtil.cleanupShadowActivation(valueToReplace.asContainerable());
            }
        } else if (SchemaConstants.PATH_PASSWORD.equivalent(itemDelta.getParentPath())) {
            continue;
        }
        normalizeDelta(itemDelta, objectClassDefinition);
        repoChanges.add(itemDelta);
    }
    return repoChanges;
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)19 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)14 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)6 ArrayList (java.util.ArrayList)6 QName (javax.xml.namespace.QName)5 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)3 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Task (com.evolveum.midpoint.task.api.Task)3 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)3 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 Collection (java.util.Collection)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 PrismReference (com.evolveum.midpoint.prism.PrismReference)2 Trace (com.evolveum.midpoint.util.logging.Trace)2 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)2 PolicyConstraintsType (com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyConstraintsType)2 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)2