Search in sources :

Example 41 with SystemConfigurationType

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

the class SynchronizationServiceImpl method determineSituationWithCorrelation.

/**
	 * account is not linked to user. you have to use correlation and
	 * confirmation rule to be sure user for this account doesn't exists
	 * resourceShadow only contains the data that were in the repository before
	 * the change. But the correlation/confirmation should work on the updated
	 * data. Therefore let's apply the changes before running
	 * correlation/confirmation
	 */
private <F extends FocusType> SynchronizationSituation determineSituationWithCorrelation(Class<F> focusType, ResourceObjectShadowChangeDescription change, ObjectSynchronizationType synchronizationPolicy, PrismObject<F> owner, SystemConfigurationType configurationType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    if (ChangeType.DELETE.equals(getModificationType(change))) {
        // account was deleted and we know it didn't have owner
        return new SynchronizationSituation<>(owner == null ? null : owner.asObjectable(), null, SynchronizationSituationType.DELETED);
    }
    PrismObject<? extends ShadowType> resourceShadow = change.getCurrentShadow();
    ObjectDelta syncDelta = change.getObjectDelta();
    if (resourceShadow == null && syncDelta != null && ChangeType.ADD.equals(syncDelta.getChangeType())) {
        LOGGER.trace("Trying to compute current shadow from change delta add.");
        PrismObject<ShadowType> shadow = syncDelta.computeChangedObject(syncDelta.getObjectToAdd());
        resourceShadow = shadow;
        change.setCurrentShadow(shadow);
    }
    Validate.notNull(resourceShadow, "Current shadow must not be null.");
    ResourceType resource = change.getResource().asObjectable();
    validateResourceInShadow(resourceShadow.asObjectable(), resource);
    SynchronizationSituationType state = null;
    LOGGER.trace("SYNCHRONIZATION: CORRELATION: Looking for list of {} objects based on correlation rule.", focusType.getSimpleName());
    List<PrismObject<F>> users = correlationConfirmationEvaluator.findFocusesByCorrelationRule(focusType, resourceShadow.asObjectable(), synchronizationPolicy.getCorrelation(), resource, configurationType, task, result);
    if (users == null) {
        users = new ArrayList<>();
    }
    if (users.size() > 1) {
        if (synchronizationPolicy.getConfirmation() == null) {
            LOGGER.trace("SYNCHRONIZATION: CONFIRMATION: no confirmation defined.");
        } else {
            LOGGER.debug("SYNCHRONIZATION: CONFIRMATION: Checking objects from correlation with confirmation rule.");
            users = correlationConfirmationEvaluator.findUserByConfirmationRule(focusType, users, resourceShadow.asObjectable(), resource, configurationType, synchronizationPolicy.getConfirmation(), task, result);
        }
    }
    F user = null;
    switch(users.size()) {
        case 0:
            state = SynchronizationSituationType.UNMATCHED;
            break;
        case 1:
            switch(getModificationType(change)) {
                case ADD:
                case MODIFY:
                    state = SynchronizationSituationType.UNLINKED;
                    break;
                case DELETE:
                    state = SynchronizationSituationType.DELETED;
                    break;
            }
            user = users.get(0).asObjectable();
            break;
        default:
            state = SynchronizationSituationType.DISPUTED;
    }
    return new SynchronizationSituation(null, user, state);
}
Also used : SynchronizationSituationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType) PrismObject(com.evolveum.midpoint.prism.PrismObject) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 42 with SystemConfigurationType

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

the class SynchronizationServiceImpl method matchUserCorrelationRule.

/**
	 * Tries to match specified focus and shadow. Return true if it matches,
	 * false otherwise.
	 */
@Override
public <F extends FocusType> boolean matchUserCorrelationRule(PrismObject<ShadowType> shadow, PrismObject<F> focus, ResourceType resourceType, PrismObject<SystemConfigurationType> configuration, Task task, OperationResult result) throws ConfigurationException, SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    ObjectSynchronizationType synchronizationPolicy = determineSynchronizationPolicy(resourceType, shadow, configuration, task, result);
    Class<F> focusClass;
    // be null...
    if (synchronizationPolicy != null) {
        focusClass = determineFocusClass(synchronizationPolicy, resourceType);
    } else {
        focusClass = (Class) focus.asObjectable().getClass();
    }
    return correlationConfirmationEvaluator.matchUserCorrelationRule(focusClass, shadow, focus, synchronizationPolicy, resourceType, configuration == null ? null : configuration.asObjectable(), task, result);
}
Also used : ObjectSynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType)

Example 43 with SystemConfigurationType

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

the class CorrelationConfirmationEvaluator method satisfyCondition.

private boolean satisfyCondition(ShadowType currentShadow, ConditionalSearchFilterType conditionalFilter, ResourceType resourceType, SystemConfigurationType configurationType, String shortDesc, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    if (conditionalFilter.getCondition() == null) {
        return true;
    }
    ExpressionType condition = conditionalFilter.getCondition();
    ExpressionVariables variables = Utils.getDefaultExpressionVariables(null, currentShadow, resourceType, configurationType);
    ItemDefinition outputDefinition = new PrismPropertyDefinitionImpl(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_BOOLEAN, prismContext);
    PrismPropertyValue<Boolean> satisfy = (PrismPropertyValue) ExpressionUtil.evaluateExpression(variables, outputDefinition, condition, expressionFactory, shortDesc, task, parentResult);
    if (satisfy.getValue() == null) {
        return false;
    }
    return satisfy.getValue();
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)

Example 44 with SystemConfigurationType

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

the class ModelTUtil method mockGetSystemConfiguration.

@SuppressWarnings("unchecked")
public static void mockGetSystemConfiguration(RepositoryService repository, File file) throws JAXBException, ObjectNotFoundException, SchemaException, IOException {
    SystemConfigurationType systemConfiguration = (SystemConfigurationType) PrismTestUtil.parseObject(file).asObjectable();
    when(repository.getObject(eq(SystemConfigurationType.class), eq(SystemObjectsType.SYSTEM_CONFIGURATION.value()), any(Collection.class), any(OperationResult.class))).thenReturn(systemConfiguration.asPrismObject());
}
Also used : Collection(java.util.Collection) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 45 with SystemConfigurationType

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

the class CustomTransport method send.

@Override
public void send(Message message, String transportName, Event event, Task task, OperationResult parentResult) {
    OperationResult result = parentResult.createSubresult(DOT_CLASS + "send");
    result.addCollectionOfSerializablesAsParam("message recipient(s)", message.getTo());
    result.addParam("message subject", message.getSubject());
    SystemConfigurationType systemConfiguration = NotificationFunctionsImpl.getSystemConfiguration(cacheRepositoryService, result);
    if (systemConfiguration == null || systemConfiguration.getNotificationConfiguration() == null) {
        String msg = "No notifications are configured. Custom notification to " + message.getTo() + " will not be sent.";
        LOGGER.warn(msg);
        result.recordWarning(msg);
        return;
    }
    // after "sms:"
    String configName = transportName.length() > NAME.length() ? transportName.substring(NAME.length() + 1) : null;
    CustomTransportConfigurationType configuration = systemConfiguration.getNotificationConfiguration().getCustomTransport().stream().filter(transportConfigurationType -> java.util.Objects.equals(configName, transportConfigurationType.getName())).findFirst().orElse(null);
    if (configuration == null) {
        String msg = "Custom configuration '" + configName + "' not found. Custom notification to " + message.getTo() + " will not be sent.";
        LOGGER.warn(msg);
        result.recordWarning(msg);
        return;
    }
    String file = configuration.getRedirectToFile();
    if (file != null) {
        writeToFile(message, file, result);
        return;
    }
    try {
        evaluateExpression(configuration.getExpression(), getDefaultVariables(message, event), "custom transport expression", task, result);
        LOGGER.trace("Custom transport expression execution finished");
        result.recordSuccess();
    } catch (Throwable t) {
        String msg = "Couldn't execute custom transport expression";
        LoggingUtils.logException(LOGGER, msg, t);
        result.recordFatalError(msg + ": " + t.getMessage(), t);
    }
}
Also used : CustomTransportConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.CustomTransportConfigurationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)

Aggregations

SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)40 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)28 Task (com.evolveum.midpoint.task.api.Task)14 Test (org.testng.annotations.Test)12 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)11 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)10 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)10 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)9 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)8 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)8 LoggingConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.LoggingConfigurationType)8 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)8 LogfileTestTailer (com.evolveum.midpoint.test.util.LogfileTestTailer)7 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)6 ObjectPolicyConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectPolicyConfigurationType)6 ValuePolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4