Search in sources :

Example 11 with ShadowType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType 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 12 with ShadowType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType 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 13 with ShadowType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType 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 14 with ShadowType

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

the class SynchronizationUtils method isPolicyApplicable.

public static boolean isPolicyApplicable(PrismObject<? extends ShadowType> currentShadow, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
    ShadowType currentShadowType = currentShadow.asObjectable();
    // objectClass
    QName shadowObjectClass = currentShadowType.getObjectClass();
    Validate.notNull(shadowObjectClass, "No objectClass in currentShadow");
    return isPolicyApplicable(shadowObjectClass, currentShadowType.getKind(), currentShadowType.getIntent(), synchronizationPolicy, resource);
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName)

Example 15 with ShadowType

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

the class TestRefinedSchema method assertDeprecatedProtectedAccount.

private void assertDeprecatedProtectedAccount(String message, ResourceObjectPattern protectedPattern, String identifierValue, RefinedObjectClassDefinition rAccount) throws SchemaException {
    Collection<ResourceAttribute<?>> identifiers = protectedPattern.getIdentifiers();
    assertNotNull("Null identifiers in " + message, identifiers);
    assertEquals("Wrong number identifiers in " + message, 1, identifiers.size());
    ResourceAttribute<?> identifier = identifiers.iterator().next();
    assertNotNull("Null identifier in " + message, identifier);
    assertEquals("Wrong identifier value in " + message, identifier.getRealValue(), identifierValue);
    // Try matching	
    PrismObject<ShadowType> shadow = rAccount.getObjectDefinition().instantiate();
    ResourceAttributeContainer attributesContainer = ShadowUtil.getOrCreateAttributesContainer(shadow, rAccount);
    ResourceAttribute<String> confusingAttr1 = createStringAttribute(new QName("http://whatever.com", "confuseMe"), "HowMuchWoodWouldWoodchuckChuckIfWoodchuckCouldChudkWood");
    attributesContainer.add(confusingAttr1);
    ResourceAttribute<String> nameAttr = createStringAttribute(SchemaTestConstants.ICFS_NAME, identifierValue);
    attributesContainer.add(nameAttr);
    ResourceAttribute<String> confusingAttr2 = createStringAttribute(new QName("http://whatever.com", "confuseMeAgain"), "WoodchuckWouldChuckNoWoodAsWoodchuckCannotChuckWood");
    attributesContainer.add(confusingAttr2);
    assertTrue("Test attr not matched in " + message, protectedPattern.matches(shadow, null));
    nameAttr.setRealValue("huhulumululul");
    assertFalse("Test attr nonsense was matched in " + message, protectedPattern.matches(shadow, null));
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName)

Aggregations

ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)576 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)426 Test (org.testng.annotations.Test)378 Task (com.evolveum.midpoint.task.api.Task)319 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)191 QName (javax.xml.namespace.QName)121 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)89 PrismObject (com.evolveum.midpoint.prism.PrismObject)87 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)79 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)78 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)76 ArrayList (java.util.ArrayList)74 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)72 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)69 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)64 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)61 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)50 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)47 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)47 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)46