Search in sources :

Example 56 with PrismContainerValue

use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.

the class CredentialPolicyEvaluator method createDeleteHistoryDeltasIfNeeded.

// TODO: generalize for other credentials
private <F extends FocusType> void createDeleteHistoryDeltasIfNeeded(int historyLength, int addedValues, PrismContainer<R> currentCredentialContainer) throws SchemaException {
    PrismContainer<PasswordHistoryEntryType> historyEntries = currentCredentialContainer.findOrCreateContainer(PasswordType.F_HISTORY_ENTRY);
    List<PrismContainerValue<PasswordHistoryEntryType>> historyEntryValues = historyEntries.getValues();
    if (historyEntries.size() == 0) {
        return;
    }
    // We need to delete one more entry than intuitively expected - because we are computing from the history entries 
    // in the old object. In the new object there will be one new history entry for the changed password.
    int numberOfHistoryEntriesToDelete = historyEntries.size() - historyLength + addedValues + 1;
    for (int i = 0; i < numberOfHistoryEntriesToDelete; i++) {
        ContainerDelta<PasswordHistoryEntryType> deleteHistoryDelta = ContainerDelta.createModificationDelete(new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_HISTORY_ENTRY), UserType.class, prismContext, historyEntryValues.get(i).clone());
        context.getFocusContext().swallowToSecondaryDelta(deleteHistoryDelta);
    }
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PasswordHistoryEntryType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordHistoryEntryType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 57 with PrismContainerValue

use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.

the class UserProfileServiceImpl method initializePrincipalFromAssignments.

private void initializePrincipalFromAssignments(MidPointPrincipal principal, PrismObject<SystemConfigurationType> systemConfiguration) throws SchemaException {
    UserType userType = principal.getUser();
    Collection<Authorization> authorizations = principal.getAuthorities();
    List<AdminGuiConfigurationType> adminGuiConfigurations = new ArrayList<>();
    Task task = taskManager.createTaskInstance(UserProfileServiceImpl.class.getName() + ".initializePrincipalFromAssignments");
    OperationResult result = task.getResult();
    principal.setApplicableSecurityPolicy(securityHelper.locateSecurityPolicy(userType.asPrismObject(), systemConfiguration, task, result));
    if (!userType.getAssignment().isEmpty()) {
        LensContext<UserType> lensContext = new LensContextPlaceholder<>(userType.asPrismObject(), prismContext);
        AssignmentEvaluator.Builder<UserType> builder = new AssignmentEvaluator.Builder<UserType>().repository(repositoryService).focusOdo(new ObjectDeltaObject<>(userType.asPrismObject(), null, userType.asPrismObject())).channel(null).objectResolver(objectResolver).systemObjectCache(systemObjectCache).prismContext(prismContext).mappingFactory(mappingFactory).mappingEvaluator(mappingEvaluator).activationComputer(activationComputer).now(clock.currentTimeXMLGregorianCalendar()).loginMode(true).lensContext(lensContext);
        AssignmentEvaluator<UserType> assignmentEvaluator = builder.build();
        try {
            RepositoryCache.enter();
            for (AssignmentType assignmentType : userType.getAssignment()) {
                try {
                    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
                    assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
                    assignmentIdi.recompute();
                    EvaluatedAssignment<UserType> assignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userType, userType.toString(), task, result);
                    if (assignment.isValid()) {
                        authorizations.addAll(assignment.getAuthorizations());
                        adminGuiConfigurations.addAll(assignment.getAdminGuiConfigurations());
                    }
                    for (EvaluatedAssignmentTarget target : assignment.getRoles().getNonNegativeValues()) {
                        if (target.getTarget() != null && target.getTarget().asObjectable() instanceof UserType && DeputyUtils.isDelegationPath(target.getAssignmentPath())) {
                            List<OtherPrivilegesLimitationType> limitations = DeputyUtils.extractLimitations(target.getAssignmentPath());
                            principal.addDelegatorWithOtherPrivilegesLimitations(new DelegatorWithOtherPrivilegesLimitations((UserType) target.getTarget().asObjectable(), limitations));
                        }
                    }
                } catch (SchemaException e) {
                    LOGGER.error("Schema violation while processing assignment of {}: {}; assignment: {}", userType, e.getMessage(), assignmentType, e);
                } catch (ObjectNotFoundException e) {
                    LOGGER.error("Object not found while processing assignment of {}: {}; assignment: {}", userType, e.getMessage(), assignmentType, e);
                } catch (ExpressionEvaluationException e) {
                    LOGGER.error("Evaluation error while processing assignment of {}: {}; assignment: {}", userType, e.getMessage(), assignmentType, e);
                } catch (PolicyViolationException e) {
                    LOGGER.error("Policy violation while processing assignment of {}: {}; assignment: {}", userType, e.getMessage(), assignmentType, e);
                }
            }
        } finally {
            RepositoryCache.exit();
        }
    }
    if (userType.getAdminGuiConfiguration() != null) {
        // config from the user object should go last (to be applied as the last one)
        adminGuiConfigurations.add(userType.getAdminGuiConfiguration());
    }
    principal.setAdminGuiConfiguration(AdminGuiConfigTypeUtil.compileAdminGuiConfiguration(adminGuiConfigurations, systemConfiguration));
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) QueryBuilder(com.evolveum.midpoint.prism.query.builder.QueryBuilder) ArrayList(java.util.ArrayList) LensContextPlaceholder(com.evolveum.midpoint.model.impl.lens.LensContextPlaceholder) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Authorization(com.evolveum.midpoint.security.api.Authorization) AssignmentEvaluator(com.evolveum.midpoint.model.impl.lens.AssignmentEvaluator) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) EvaluatedAssignmentTarget(com.evolveum.midpoint.model.api.context.EvaluatedAssignmentTarget) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) DelegatorWithOtherPrivilegesLimitations(com.evolveum.midpoint.security.api.DelegatorWithOtherPrivilegesLimitations)

Example 58 with PrismContainerValue

use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.

the class FilterContentEvaluator method evaluate.

public PipelineData evaluate(FilterContentExpressionType expression, PipelineData input, ExecutionContext context, OperationResult result) throws ScriptExecutionException {
    List<ItemPath> keep = convert(expression.getKeep());
    List<ItemPath> remove = convert(expression.getRemove());
    if (keep.isEmpty() && remove.isEmpty()) {
        // nothing to do here
        return input;
    }
    for (PipelineItem pipelineItem : input.getData()) {
        PrismValue value = pipelineItem.getValue();
        if (!(value instanceof PrismContainerValue)) {
            String message = "In 'select' commands in keep/remove mode, we can act only on prism container values, not on " + value;
            if (context.isContinueOnAnyError()) {
                LOGGER.error(message);
            } else {
                throw new ScriptExecutionException(message);
            }
        } else {
            PrismContainerValue<?> pcv = (PrismContainerValue) value;
            if (!keep.isEmpty()) {
                pcv.keepPaths(keep);
            } else {
                pcv.removePaths(remove);
            }
        }
    }
    return input;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 59 with PrismContainerValue

use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.

the class AddAssignmentAspect method getApprovalRequestsFromFocusModify.

private List<ApprovalRequest<AssignmentType>> getApprovalRequestsFromFocusModify(PcpAspectConfigurationType config, PrismObject<?> focusOld, ObjectDelta<? extends ObjectType> change, ModelContext<?> modelContext, Task taskFromModel, OperationResult result) {
    LOGGER.trace("Relevant assignments in focus modify delta:");
    List<ApprovalRequest<AssignmentType>> approvalRequestList = new ArrayList<>();
    Iterator<? extends ItemDelta> deltaIterator = change.getModifications().iterator();
    final ItemPath ASSIGNMENT_PATH = new ItemPath(FocusType.F_ASSIGNMENT);
    while (deltaIterator.hasNext()) {
        ItemDelta delta = deltaIterator.next();
        if (!ASSIGNMENT_PATH.equivalent(delta.getPath())) {
            continue;
        }
        if (delta.getValuesToAdd() != null && !delta.getValuesToAdd().isEmpty()) {
            Iterator<PrismContainerValue<AssignmentType>> valueIterator = delta.getValuesToAdd().iterator();
            while (valueIterator.hasNext()) {
                PrismContainerValue<AssignmentType> assignmentValue = valueIterator.next();
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Assignment to add = {}", assignmentValue.debugDump());
                }
                ApprovalRequest<AssignmentType> req = processAssignmentToAdd(config, assignmentValue, modelContext, taskFromModel, result);
                if (req != null) {
                    approvalRequestList.add(req);
                    valueIterator.remove();
                }
            }
        }
        if (delta.getValuesToReplace() != null && !delta.getValuesToReplace().isEmpty()) {
            Iterator<PrismContainerValue<AssignmentType>> valueIterator = delta.getValuesToReplace().iterator();
            while (valueIterator.hasNext()) {
                PrismContainerValue<AssignmentType> assignmentValue = valueIterator.next();
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Assignment to replace = {}", assignmentValue.debugDump());
                }
                if (existsEquivalentValue(focusOld, assignmentValue)) {
                    continue;
                }
                ApprovalRequest<AssignmentType> req = processAssignmentToAdd(config, assignmentValue, modelContext, taskFromModel, result);
                if (req != null) {
                    approvalRequestList.add(req);
                    valueIterator.remove();
                }
            }
        }
        // let's sanitize the delta
        if (delta.getValuesToAdd() != null && delta.getValuesToAdd().isEmpty()) {
            // empty set of values to add is an illegal state
            delta.resetValuesToAdd();
        }
        if (delta.getValuesToAdd() == null && delta.getValuesToReplace() == null && delta.getValuesToDelete() == null) {
            deltaIterator.remove();
        }
    }
    return approvalRequestList;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ArrayList(java.util.ArrayList) ApprovalRequest(com.evolveum.midpoint.wf.impl.processes.itemApproval.ApprovalRequest) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)59 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)22 Task (com.evolveum.midpoint.task.api.Task)22 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)22 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)21 Test (org.testng.annotations.Test)18 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)17 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)15 ItemDeltaItem (com.evolveum.midpoint.repo.common.expression.ItemDeltaItem)15 ArrayList (java.util.ArrayList)14 ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)13 PrismObject (com.evolveum.midpoint.prism.PrismObject)10 QName (javax.xml.namespace.QName)10 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)9 PrismReference (com.evolveum.midpoint.prism.PrismReference)9 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)8 ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)6 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)6