Search in sources :

Example 1 with EvaluatedAssignmentTarget

use of com.evolveum.midpoint.model.api.context.EvaluatedAssignmentTarget in project midpoint by Evolveum.

the class PageAdminFocus method recomputeAssignmentsPerformed.

public List<AssignmentsPreviewDto> recomputeAssignmentsPerformed(AjaxRequestTarget target) {
    LOGGER.debug("Recompute user assignments");
    Task task = createSimpleTask(OPERATION_RECOMPUTE_ASSIGNMENTS);
    OperationResult result = new OperationResult(OPERATION_RECOMPUTE_ASSIGNMENTS);
    ObjectDelta<F> delta;
    Set<AssignmentsPreviewDto> assignmentDtoSet = new TreeSet<>();
    try {
        reviveModels();
        ObjectWrapper<F> userWrapper = getObjectWrapper();
        delta = userWrapper.getObjectDelta();
        if (userWrapper.getOldDelta() != null) {
            delta = ObjectDelta.summarize(userWrapper.getOldDelta(), delta);
        }
        switch(userWrapper.getStatus()) {
            case ADDING:
                PrismObject<F> focus = delta.getObjectToAdd();
                prepareObjectForAdd(focus);
                getPrismContext().adopt(focus, getCompileTimeClass());
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Delta before add user:\n{}", new Object[] { delta.debugDump(3) });
                }
                if (!delta.isEmpty()) {
                    delta.revive(getPrismContext());
                } else {
                    result.recordSuccess();
                }
                break;
            case MODIFYING:
                prepareObjectDeltaForModify(delta);
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Delta before modify user:\n{}", new Object[] { delta.debugDump(3) });
                }
                List<ObjectDelta<? extends ObjectType>> accountDeltas = getShadowModifyDeltas(result);
                Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
                if (!delta.isEmpty()) {
                    delta.revive(getPrismContext());
                    deltas.add(delta);
                }
                for (ObjectDelta accDelta : accountDeltas) {
                    if (!accDelta.isEmpty()) {
                        accDelta.revive(getPrismContext());
                        deltas.add(accDelta);
                    }
                }
                break;
            default:
                error(getString("pageAdminFocus.message.unsupportedState", userWrapper.getStatus()));
        }
        ModelContext<UserType> modelContext = null;
        try {
            modelContext = getModelInteractionService().previewChanges(WebComponentUtil.createDeltaCollection(delta), null, task, result);
        } catch (NoFocusNameSchemaException e) {
            info(getString("pageAdminFocus.message.noUserName"));
            target.add(getFeedbackPanel());
            return null;
        }
        DeltaSetTriple<? extends EvaluatedAssignment> evaluatedAssignmentTriple = modelContext.getEvaluatedAssignmentTriple();
        Collection<? extends EvaluatedAssignment> evaluatedAssignments = evaluatedAssignmentTriple.getNonNegativeValues();
        if (evaluatedAssignments.isEmpty()) {
            info(getString("pageAdminFocus.message.noAssignmentsAvailable"));
            target.add(getFeedbackPanel());
            return null;
        }
        for (EvaluatedAssignment<UserType> evaluatedAssignment : evaluatedAssignments) {
            if (!evaluatedAssignment.isValid()) {
                continue;
            }
            // roles and orgs
            DeltaSetTriple<? extends EvaluatedAssignmentTarget> evaluatedRolesTriple = evaluatedAssignment.getRoles();
            Collection<? extends EvaluatedAssignmentTarget> evaluatedRoles = evaluatedRolesTriple.getNonNegativeValues();
            for (EvaluatedAssignmentTarget role : evaluatedRoles) {
                if (role.isEvaluateConstructions()) {
                    assignmentDtoSet.add(createAssignmentsPreviewDto(role, task, result));
                }
            }
            // all resources
            DeltaSetTriple<EvaluatedConstruction> evaluatedConstructionsTriple = evaluatedAssignment.getEvaluatedConstructions(task, result);
            Collection<EvaluatedConstruction> evaluatedConstructions = evaluatedConstructionsTriple.getNonNegativeValues();
            for (EvaluatedConstruction construction : evaluatedConstructions) {
                assignmentDtoSet.add(createAssignmentsPreviewDto(construction));
            }
        }
        return new ArrayList<>(assignmentDtoSet);
    } catch (Exception e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Could not create assignments preview.", e);
        error("Could not create assignments preview. Reason: " + e);
        target.add(getFeedbackPanel());
    }
    return null;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) AssignmentsPreviewDto(com.evolveum.midpoint.web.page.admin.users.component.AssignmentsPreviewDto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) EvaluatedAssignmentTarget(com.evolveum.midpoint.model.api.context.EvaluatedAssignmentTarget) EvaluatedConstruction(com.evolveum.midpoint.model.api.context.EvaluatedConstruction)

Example 2 with EvaluatedAssignmentTarget

use of com.evolveum.midpoint.model.api.context.EvaluatedAssignmentTarget 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)

Aggregations

EvaluatedAssignmentTarget (com.evolveum.midpoint.model.api.context.EvaluatedAssignmentTarget)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 EvaluatedConstruction (com.evolveum.midpoint.model.api.context.EvaluatedConstruction)1 AssignmentEvaluator (com.evolveum.midpoint.model.impl.lens.AssignmentEvaluator)1 LensContextPlaceholder (com.evolveum.midpoint.model.impl.lens.LensContextPlaceholder)1 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)1 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)1 QueryBuilder (com.evolveum.midpoint.prism.query.builder.QueryBuilder)1 ItemDeltaItem (com.evolveum.midpoint.repo.common.expression.ItemDeltaItem)1 Authorization (com.evolveum.midpoint.security.api.Authorization)1 DelegatorWithOtherPrivilegesLimitations (com.evolveum.midpoint.security.api.DelegatorWithOtherPrivilegesLimitations)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 AssignmentsPreviewDto (com.evolveum.midpoint.web.page.admin.users.component.AssignmentsPreviewDto)1 ArrayList (java.util.ArrayList)1