use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType 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;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType 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);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType in project midpoint by Evolveum.
the class SynchronizationUtils method isPolicyApplicable.
public static boolean isPolicyApplicable(QName objectClass, ShadowKindType kind, String intent, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
List<QName> policyObjectClasses = synchronizationPolicy.getObjectClass();
if (policyObjectClasses == null || policyObjectClasses.isEmpty()) {
String policyIntent = synchronizationPolicy.getIntent();
ShadowKindType policyKind = synchronizationPolicy.getKind();
ObjectClassComplexTypeDefinition policyObjectClass = null;
RefinedResourceSchema schema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
if (schema == null) {
throw new SchemaException("No schema defined in resource. Possible configuration problem?");
}
if (policyKind == null && policyIntent == null) {
policyObjectClass = schema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
}
if (policyKind != null) {
if (StringUtils.isEmpty(policyIntent)) {
policyObjectClass = schema.findDefaultObjectClassDefinition(policyKind);
} else {
policyObjectClass = schema.findObjectClassDefinition(policyKind, policyIntent);
}
}
if (policyObjectClass != null && !policyObjectClass.getTypeName().equals(objectClass)) {
return false;
}
}
if (policyObjectClasses != null && !policyObjectClasses.isEmpty()) {
if (!QNameUtil.contains(policyObjectClasses, objectClass)) {
return false;
}
}
// kind
ShadowKindType policyKind = synchronizationPolicy.getKind();
if (policyKind != null && kind != null && !policyKind.equals(kind)) {
return false;
}
// intent
// TODO is the intent always present in shadow at this time? [med]
String policyIntent = synchronizationPolicy.getIntent();
if (policyIntent != null && intent != null && !MiscSchemaUtil.equalsIntent(intent, policyIntent)) {
return false;
}
return true;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType in project midpoint by Evolveum.
the class ExpressionHandlerImplTest method testEvaluateExpression.
@SuppressWarnings("unchecked")
@Test
public void testEvaluateExpression() throws Exception {
PrismObject<ShadowType> account = PrismTestUtil.parseObject(new File(TEST_FOLDER, "account.xml"));
ShadowType accountType = account.asObjectable();
PrismObject<ResourceType> resource = PrismTestUtil.parseObject(new File(TEST_FOLDER_COMMON, "resource-dummy.xml"));
ResourceType resourceType = resource.asObjectable();
accountType.setResource(resourceType);
ObjectSynchronizationType synchronization = resourceType.getSynchronization().getObjectSynchronization().get(0);
for (ConditionalSearchFilterType filter : synchronization.getCorrelation()) {
MapXNode clauseXNode = filter.getFilterClauseXNode();
// key = q:equal, value = map (path + expression)
RootXNode expressionNode = ((MapXNode) clauseXNode.getSingleSubEntry("filter value").getValue()).getEntryAsRoot(new QName(SchemaConstants.NS_C, "expression"));
ExpressionType expression = PrismTestUtil.getPrismContext().parserFor(expressionNode).parseRealValue(ExpressionType.class);
LOGGER.debug("Expression: {}", SchemaDebugUtil.prettyPrint(expression));
OperationResult result = new OperationResult("testCorrelationRule");
String name = expressionHandler.evaluateExpression(accountType, expression, "test expression", null, result);
LOGGER.info(result.debugDump());
assertEquals("Wrong expression result", "hbarbossa", name);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType in project midpoint by Evolveum.
the class SynchronizationServiceImpl method notifyChange.
@Override
public void notifyChange(ResourceObjectShadowChangeDescription change, Task task, OperationResult parentResult) {
validate(change);
Validate.notNull(parentResult, "Parent operation result must not be null.");
boolean logDebug = isLogDebug(change);
if (logDebug) {
LOGGER.debug("SYNCHRONIZATION: received change notification {}", change);
} else {
LOGGER.trace("SYNCHRONIZATION: received change notification {}", change);
}
OperationResult subResult = parentResult.createSubresult(NOTIFY_CHANGE);
PrismObject<? extends ShadowType> currentShadow = change.getCurrentShadow();
PrismObject<? extends ShadowType> applicableShadow = currentShadow;
if (applicableShadow == null) {
// We need this e.g. in case of delete
applicableShadow = change.getOldShadow();
}
SynchronizationEventInformation eventInfo = new SynchronizationEventInformation(applicableShadow, change.getSourceChannel(), task);
try {
ResourceType resourceType = change.getResource().asObjectable();
PrismObject<SystemConfigurationType> configuration = systemObjectCache.getSystemConfiguration(subResult);
ObjectSynchronizationType synchronizationPolicy = determineSynchronizationPolicy(resourceType, applicableShadow, configuration, task, subResult);
if (LOGGER.isTraceEnabled()) {
String policyDesc = null;
if (synchronizationPolicy != null) {
if (synchronizationPolicy.getName() == null) {
policyDesc = "(kind=" + synchronizationPolicy.getKind() + ", intent=" + synchronizationPolicy.getIntent() + ", objectclass=" + synchronizationPolicy.getObjectClass() + ")";
} else {
policyDesc = synchronizationPolicy.getName();
}
}
LOGGER.trace("SYNCHRONIZATION determined policy: {}", policyDesc);
}
if (synchronizationPolicy == null) {
String message = "SYNCHRONIZATION no matching policy for " + applicableShadow + " (" + applicableShadow.asObjectable().getObjectClass() + ") " + " on " + resourceType + ", ignoring change from channel " + change.getSourceChannel();
LOGGER.debug(message);
subResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, message);
eventInfo.setNoSynchronizationPolicy();
eventInfo.record(task);
return;
}
if (!isSynchronizationEnabled(synchronizationPolicy)) {
String message = "SYNCHRONIZATION is not enabled for " + resourceType + " ignoring change from channel " + change.getSourceChannel();
LOGGER.debug(message);
subResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, message);
eventInfo.setSynchronizationNotEnabled();
eventInfo.record(task);
return;
}
// defined in task
if (!satisfyTaskConstraints(synchronizationPolicy, task)) {
LOGGER.trace("SYNCHRONIZATION skipping {} because it does not match kind/intent defined in task", new Object[] { applicableShadow });
subResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Skipped because it does not match objectClass/kind/intent");
eventInfo.setDoesNotMatchTaskSpecification();
eventInfo.record(task);
return;
}
if (isProtected((PrismObject<ShadowType>) currentShadow)) {
if (StringUtils.isNotBlank(synchronizationPolicy.getIntent())) {
List<PropertyDelta<?>> modifications = SynchronizationUtils.createSynchronizationTimestampsDelta(currentShadow);
PropertyDelta<String> intentDelta = PropertyDelta.createModificationReplaceProperty(ShadowType.F_INTENT, currentShadow.getDefinition(), synchronizationPolicy.getIntent());
modifications.add(intentDelta);
try {
repositoryService.modifyObject(ShadowType.class, currentShadow.getOid(), modifications, subResult);
task.recordObjectActionExecuted(currentShadow, ChangeType.MODIFY, null);
} catch (Throwable t) {
task.recordObjectActionExecuted(currentShadow, ChangeType.MODIFY, t);
} finally {
task.markObjectActionExecutedBoundary();
}
}
subResult.recordSuccess();
eventInfo.record(task);
LOGGER.debug("SYNCHRONIZATION: DONE (dry run) for protected shadow {}", currentShadow);
return;
}
Class<? extends FocusType> focusType = determineFocusClass(synchronizationPolicy, resourceType);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Synchronization is enabled, focus class: {}, found applicable policy: {}", focusType, Utils.getPolicyDesc(synchronizationPolicy));
}
SynchronizationSituation situation = determineSituation(focusType, change, synchronizationPolicy, configuration.asObjectable(), task, subResult);
if (logDebug) {
LOGGER.debug("SYNCHRONIZATION: SITUATION: '{}', currentOwner={}, correlatedOwner={}", situation.getSituation().value(), situation.getCurrentOwner(), situation.getCorrelatedOwner());
} else {
LOGGER.trace("SYNCHRONIZATION: SITUATION: '{}', currentOwner={}, correlatedOwner={}", situation.getSituation().value(), situation.getCurrentOwner(), situation.getCorrelatedOwner());
}
eventInfo.setOriginalSituation(situation.getSituation());
// overwritten
eventInfo.setNewSituation(situation.getSituation());
if (change.isUnrelatedChange() || Utils.isDryRun(task)) {
PrismObject object = null;
if (change.getCurrentShadow() != null) {
object = change.getCurrentShadow();
} else if (change.getOldShadow() != null) {
object = change.getOldShadow();
}
Collection modifications = SynchronizationUtils.createSynchronizationSituationAndDescriptionDelta(object, situation.getSituation(), task.getChannel(), false);
if (StringUtils.isNotBlank(synchronizationPolicy.getIntent())) {
modifications.add(PropertyDelta.createModificationReplaceProperty(ShadowType.F_INTENT, object.getDefinition(), synchronizationPolicy.getIntent()));
}
try {
repositoryService.modifyObject(ShadowType.class, object.getOid(), modifications, subResult);
task.recordObjectActionExecuted(object, ChangeType.MODIFY, null);
} catch (Throwable t) {
task.recordObjectActionExecuted(object, ChangeType.MODIFY, t);
} finally {
task.markObjectActionExecutedBoundary();
}
subResult.recordSuccess();
eventInfo.record(task);
LOGGER.debug("SYNCHRONIZATION: DONE (dry run/unrelated) for {}", object);
return;
}
// must be here, because when the reaction has no action, the
// situation will be not set.
PrismObject<ShadowType> newCurrentShadow = saveSyncMetadata((PrismObject<ShadowType>) currentShadow, situation, change, synchronizationPolicy, task, parentResult);
if (newCurrentShadow != null) {
change.setCurrentShadow(newCurrentShadow);
}
SynchronizationSituationType newSituation = reactToChange(focusType, change, synchronizationPolicy, situation, resourceType, logDebug, configuration, task, subResult);
eventInfo.setNewSituation(newSituation);
eventInfo.record(task);
subResult.computeStatus();
} catch (SystemException ex) {
// avoid unnecessary re-wrap
eventInfo.setException(ex);
eventInfo.record(task);
subResult.recordFatalError(ex);
throw ex;
} catch (Exception ex) {
eventInfo.setException(ex);
eventInfo.record(task);
subResult.recordFatalError(ex);
throw new SystemException(ex);
} finally {
task.markObjectActionExecutedBoundary();
// if (LOGGER.isTraceEnabled()) {
// LOGGER.trace(subResult.dump());
// }
}
LOGGER.debug("SYNCHRONIZATION: DONE for {}", currentShadow);
}
Aggregations