Search in sources :

Example 16 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class CorrelationConfirmationEvaluator method findFocusesByCorrelationRule.

public <F extends FocusType> List<PrismObject<F>> findFocusesByCorrelationRule(Class<F> focusType, ShadowType currentShadow, List<ConditionalSearchFilterType> conditionalFilters, ResourceType resourceType, SystemConfigurationType configurationType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    if (conditionalFilters == null || conditionalFilters.isEmpty()) {
        LOGGER.warn("Correlation rule for resource '{}' doesn't contain query, " + "returning empty list of users.", resourceType);
        return null;
    }
    List<PrismObject<F>> users = null;
    if (conditionalFilters.size() == 1) {
        if (satisfyCondition(currentShadow, conditionalFilters.get(0), resourceType, configurationType, "Condition expression", task, result)) {
            LOGGER.trace("Condition {} in correlation expression evaluated to true", conditionalFilters.get(0).getCondition());
            users = findUsersByCorrelationRule(focusType, currentShadow, conditionalFilters.get(0), resourceType, configurationType, task, result);
        }
    } else {
        for (ConditionalSearchFilterType conditionalFilter : conditionalFilters) {
            //TODO: better description
            if (satisfyCondition(currentShadow, conditionalFilter, resourceType, configurationType, "Condition expression", task, result)) {
                LOGGER.trace("Condition {} in correlation expression evaluated to true", conditionalFilter.getCondition());
                List<PrismObject<F>> foundUsers = findUsersByCorrelationRule(focusType, currentShadow, conditionalFilter, resourceType, configurationType, task, result);
                if (foundUsers == null && users == null) {
                    continue;
                }
                if (foundUsers != null && foundUsers.isEmpty() && users == null) {
                    users = new ArrayList<PrismObject<F>>();
                }
                if (users == null && foundUsers != null) {
                    users = foundUsers;
                }
                if (users != null && !users.isEmpty() && foundUsers != null && !foundUsers.isEmpty()) {
                    for (PrismObject<F> foundUser : foundUsers) {
                        if (!contains(users, foundUser)) {
                            users.add(foundUser);
                        }
                    }
                }
            }
        }
    }
    if (users != null) {
        LOGGER.debug("SYNCHRONIZATION: CORRELATION: expression for {} returned {} users: {}", new Object[] { currentShadow, users.size(), PrettyPrinter.prettyPrint(users, 3) });
        if (users.size() > 1) {
            // remove duplicates
            Set<PrismObject<F>> usersWithoutDups = new HashSet<>();
            usersWithoutDups.addAll(users);
            users.clear();
            users.addAll(usersWithoutDups);
            LOGGER.debug("SYNCHRONIZATION: CORRELATION: found {} users without duplicates", users.size());
        }
    }
    return users;
}
Also used : ConditionalSearchFilterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConditionalSearchFilterType) HashSet(java.util.HashSet)

Example 17 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class CorrelationConfirmationEvaluator method matchUserCorrelationRule.

public <F extends FocusType> boolean matchUserCorrelationRule(Class<F> focusType, PrismObject<ShadowType> currentShadow, PrismObject<F> userType, ObjectSynchronizationType synchronization, ResourceType resourceType, SystemConfigurationType configurationType, Task task, OperationResult result) {
    if (synchronization == null) {
        LOGGER.warn("Resource does not support synchronization. Skipping evaluation correlation/confirmation for  {} and  {}", userType, currentShadow);
        return false;
    }
    List<ConditionalSearchFilterType> conditionalFilters = synchronization.getCorrelation();
    try {
        for (ConditionalSearchFilterType conditionalFilter : conditionalFilters) {
            if (matchUserCorrelationRule(focusType, currentShadow, userType, resourceType, configurationType, conditionalFilter, task, result)) {
                LOGGER.debug("SYNCHRONIZATION: CORRELATION: expression for {} match user: {}", currentShadow, userType);
                return true;
            }
        }
    } catch (SchemaException ex) {
        throw new SystemException("Failed to match user using correlation rule. " + ex.getMessage(), ex);
    }
    LOGGER.debug("SYNCHRONIZATION: CORRELATION: expression for {} does not match user: {}", new Object[] { currentShadow, userType });
    return false;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConditionalSearchFilterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConditionalSearchFilterType)

Example 18 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class AssignExecutor method execute.

@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
    boolean raw = getParamRaw(expression, input, context, globalResult);
    boolean dryRun = getParamDryRun(expression, input, context, globalResult);
    ActionParameterValueType resourceParameterValue = expressionHelper.getArgument(expression.getParameter(), PARAM_RESOURCE, false, false, NAME);
    ActionParameterValueType roleParameterValue = expressionHelper.getArgument(expression.getParameter(), PARAM_ROLE, false, false, NAME);
    Collection<ObjectReferenceType> resources;
    if (resourceParameterValue != null) {
        PipelineData data = expressionHelper.evaluateParameter(resourceParameterValue, null, input, context, globalResult);
        resources = data.getDataAsReferences(ResourceType.COMPLEX_TYPE);
    } else {
        resources = null;
    }
    Collection<ObjectReferenceType> roles;
    if (roleParameterValue != null) {
        PipelineData data = expressionHelper.evaluateParameter(roleParameterValue, null, input, context, globalResult);
        roles = data.getDataAsReferences(RoleType.COMPLEX_TYPE);
    } else {
        roles = null;
    }
    if (resources == null && roles == null) {
        throw new ScriptExecutionException("Nothing to assign: neither resource nor role specified");
    }
    for (PipelineItem item : input.getData()) {
        PrismValue value = item.getValue();
        OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
        context.checkTaskStop();
        if (value instanceof PrismObjectValue && ((PrismObjectValue) value).asObjectable() instanceof FocusType) {
            PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
            ObjectType objectType = prismObject.asObjectable();
            long started = operationsHelper.recordStart(context, objectType);
            Throwable exception = null;
            try {
                operationsHelper.applyDelta(createDelta(objectType, resources, roles), operationsHelper.createExecutionOptions(raw), dryRun, context, result);
                operationsHelper.recordEnd(context, objectType, started, null);
            } catch (Throwable ex) {
                operationsHelper.recordEnd(context, objectType, started, ex);
                exception = processActionException(ex, NAME, value, context);
            }
            context.println((exception != null ? "Attempted to modify " : "Modified ") + prismObject.toString() + rawDrySuffix(raw, dryRun) + exceptionSuffix(exception));
        } else {
            //noinspection ThrowableNotThrown
            processActionException(new ScriptExecutionException("Item is not a PrismObject of FocusType"), NAME, value, context);
        }
        operationsHelper.trimAndCloneResult(result, globalResult, context);
    }
    // TODO updated objects?
    return input;
}
Also used : ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ActionParameterValueType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionParameterValueType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)

Example 19 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class SecurityHelper method resolveGlobalSecurityPolicy.

private <F extends FocusType> SecurityPolicyType resolveGlobalSecurityPolicy(PrismObject<F> user, SystemConfigurationType systemConfiguration, Task task, OperationResult result) {
    ObjectReferenceType globalSecurityPolicyRef = systemConfiguration.getGlobalSecurityPolicyRef();
    if (globalSecurityPolicyRef != null) {
        try {
            SecurityPolicyType globalSecurityPolicyType = objectResolver.resolve(globalSecurityPolicyRef, SecurityPolicyType.class, null, "global security policy reference in system configuration", task, result);
            LOGGER.trace("Using global security policy: {}", globalSecurityPolicyType);
            postProcessSecurityPolicy(globalSecurityPolicyType, task, result);
            traceSecurityPolicy(globalSecurityPolicyType, user);
            return globalSecurityPolicyType;
        } catch (ObjectNotFoundException | SchemaException e) {
            LOGGER.error(e.getMessage(), e);
            traceSecurityPolicy(null, user);
            return null;
        }
    }
    return null;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SecurityPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType)

Example 20 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class SecurityHelper method resolveGlobalPasswordPolicy.

private <F extends FocusType> SecurityPolicyType resolveGlobalPasswordPolicy(PrismObject<F> user, SystemConfigurationType systemConfiguration, Task task, OperationResult result) {
    ObjectReferenceType globalPasswordPolicyRef = systemConfiguration.getGlobalPasswordPolicyRef();
    if (globalPasswordPolicyRef != null) {
        try {
            ValuePolicyType globalPasswordPolicyType = objectResolver.resolve(globalPasswordPolicyRef, ValuePolicyType.class, null, "global security policy reference in system configuration", task, result);
            LOGGER.trace("Using global password policy: {}", globalPasswordPolicyType);
            SecurityPolicyType policy = postProcessPasswordPolicy(globalPasswordPolicyType);
            traceSecurityPolicy(policy, user);
            return policy;
        } catch (ObjectNotFoundException | SchemaException e) {
            LOGGER.error(e.getMessage(), e);
            traceSecurityPolicy(null, user);
            return null;
        }
    }
    return null;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SecurityPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType)

Aggregations

ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)27 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 FocusType (com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)22 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)18 PrismObject (com.evolveum.midpoint.prism.PrismObject)16 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)15 ArrayList (java.util.ArrayList)15 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)8 QName (javax.xml.namespace.QName)8 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)7 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)7 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)7 ActivationStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType)7