use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class ShadowCache method applyDefinition.
private void applyDefinition(final ProvisioningContext ctx, final ObjectQuery query) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
if (query == null) {
return;
}
ObjectFilter filter = query.getFilter();
if (filter == null) {
return;
}
final RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
final ItemPath attributesPath = new ItemPath(ShadowType.F_ATTRIBUTES);
com.evolveum.midpoint.prism.query.Visitor visitor = subfilter -> {
if (subfilter instanceof PropertyValueFilter) {
PropertyValueFilter<?> valueFilter = (PropertyValueFilter<?>) subfilter;
ItemDefinition definition = valueFilter.getDefinition();
if (definition instanceof ResourceAttributeDefinition) {
return;
}
if (!attributesPath.equivalent(valueFilter.getParentPath())) {
return;
}
QName attributeName = valueFilter.getElementName();
ResourceAttributeDefinition attributeDefinition = objectClassDefinition.findAttributeDefinition(attributeName);
if (attributeDefinition == null) {
throw new TunnelException(new SchemaException("No definition for attribute " + attributeName + " in query " + query));
}
valueFilter.setDefinition(attributeDefinition);
}
};
try {
filter.accept(visitor);
} catch (TunnelException te) {
SchemaException e = (SchemaException) te.getCause();
throw e;
}
}
use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class ShadowCache method reapplyDefinitions.
/**
* Reapplies definition to the shadow if needed. The definition needs to be
* reapplied e.g. if the shadow has auxiliary object classes, it if subclass
* of the object class that was originally requested, etc.
*/
private ProvisioningContext reapplyDefinitions(ProvisioningContext ctx, PrismObject<ShadowType> rawResourceShadow) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
ShadowType rawResourceShadowType = rawResourceShadow.asObjectable();
QName objectClassQName = rawResourceShadowType.getObjectClass();
List<QName> auxiliaryObjectClassQNames = rawResourceShadowType.getAuxiliaryObjectClass();
if (auxiliaryObjectClassQNames.isEmpty() && objectClassQName.equals(ctx.getObjectClassDefinition().getTypeName())) {
// shortcut, no need to reapply anything
return ctx;
}
ProvisioningContext shadowCtx = ctx.spawn(rawResourceShadow);
shadowCtx.assertDefinition();
RefinedObjectClassDefinition shadowDef = shadowCtx.getObjectClassDefinition();
ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(rawResourceShadow);
attributesContainer.applyDefinition(shadowDef.toResourceAttributeContainerDefinition());
return shadowCtx;
}
use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class ShadowCache method applyAttributesDefinition.
private ProvisioningContext applyAttributesDefinition(ProvisioningContext ctx, PrismObject<ShadowType> shadow) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
ProvisioningContext subctx = ctx.spawn(shadow);
subctx.assertDefinition();
RefinedObjectClassDefinition objectClassDefinition = subctx.getObjectClassDefinition();
PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer != null) {
if (attributesContainer instanceof ResourceAttributeContainer) {
if (attributesContainer.getDefinition() == null) {
attributesContainer.applyDefinition(objectClassDefinition.toResourceAttributeContainerDefinition());
}
} else {
try {
// We need to convert <attributes> to
// ResourceAttributeContainer
ResourceAttributeContainer convertedContainer = ResourceAttributeContainer.convertFromContainer(attributesContainer, objectClassDefinition);
shadow.getValue().replace(attributesContainer, convertedContainer);
} catch (SchemaException e) {
throw new SchemaException(e.getMessage() + " in " + shadow, e);
}
}
}
// We also need to replace the entire object definition to inject
// correct object class definition here
// If we don't do this then the patch (delta.applyTo) will not work
// correctly because it will not be able to
// create the attribute container if needed.
PrismObjectDefinition<ShadowType> objectDefinition = shadow.getDefinition();
PrismContainerDefinition<ShadowAttributesType> origAttrContainerDef = objectDefinition.findContainerDefinition(ShadowType.F_ATTRIBUTES);
if (origAttrContainerDef == null || !(origAttrContainerDef instanceof ResourceAttributeContainerDefinition)) {
PrismObjectDefinition<ShadowType> clonedDefinition = objectDefinition.cloneWithReplacedDefinition(ShadowType.F_ATTRIBUTES, objectClassDefinition.toResourceAttributeContainerDefinition());
shadow.setDefinition(clonedDefinition);
}
return subctx;
}
use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class ShadowCache method modifyShadow.
public String modifyShadow(PrismObject<ShadowType> repoShadow, String oid, Collection<? extends ItemDelta> modifications, OperationProvisioningScriptsType scripts, ProvisioningOperationOptions options, Task task, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, ObjectNotFoundException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(repoShadow, "Object to modify must not be null.");
Validate.notNull(oid, "OID must not be null.");
Validate.notNull(modifications, "Object modification must not be null.");
InternalMonitor.recordShadowChangeOperation();
Collection<QName> additionalAuxiliaryObjectClassQNames = new ArrayList<>();
ItemPath auxPath = new ItemPath(ShadowType.F_AUXILIARY_OBJECT_CLASS);
for (ItemDelta modification : modifications) {
if (auxPath.equals(modification.getPath())) {
PropertyDelta<QName> auxDelta = (PropertyDelta<QName>) modification;
for (PrismPropertyValue<QName> pval : auxDelta.getValues(QName.class)) {
additionalAuxiliaryObjectClassQNames.add(pval.getValue());
}
}
}
ProvisioningContext ctx = ctxFactory.create(repoShadow, additionalAuxiliaryObjectClassQNames, task, parentResult);
AsynchronousOperationReturnValue<Collection<PropertyDelta<PrismPropertyValue>>> asyncReturnValue;
try {
ctx.assertDefinition();
RefinedObjectClassDefinition rOCDef = ctx.getObjectClassDefinition();
applyAttributesDefinition(ctx, repoShadow);
accessChecker.checkModify(ctx.getResource(), repoShadow, modifications, ctx.getObjectClassDefinition(), parentResult);
modifications = beforeModifyOnResource(repoShadow, options, modifications);
preprocessEntitlements(ctx, modifications, "delta for shadow " + oid, parentResult);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Applying change: {}", DebugUtil.debugDump(modifications));
}
asyncReturnValue = resouceObjectConverter.modifyResourceObject(ctx, repoShadow, scripts, modifications, parentResult);
} catch (Exception ex) {
LOGGER.debug("Provisioning exception: {}:{}, attempting to handle it", new Object[] { ex.getClass(), ex.getMessage(), ex });
try {
repoShadow = handleError(ctx, ex, repoShadow, FailedOperation.MODIFY, modifications, isDoDiscovery(ctx.getResource(), options), isCompensate(options), parentResult);
parentResult.computeStatus();
} catch (ObjectAlreadyExistsException e) {
parentResult.recordFatalError("While compensating communication problem for modify operation got: " + ex.getMessage(), ex);
throw new SystemException(e);
}
return repoShadow.getOid();
}
Collection<PropertyDelta<PrismPropertyValue>> sideEffectChanges = asyncReturnValue.getReturnValue();
if (sideEffectChanges != null) {
ItemDelta.addAll(modifications, sideEffectChanges);
}
afterModifyOnResource(ctx, repoShadow, modifications, asyncReturnValue.getOperationResult(), parentResult);
ObjectDelta<ShadowType> delta = ObjectDelta.createModifyDelta(repoShadow.getOid(), modifications, repoShadow.getCompileTimeClass(), prismContext);
ResourceOperationDescription operationDescription = createSuccessOperationDescription(ctx, repoShadow, delta, parentResult);
if (asyncReturnValue.isInProgress()) {
operationListener.notifyInProgress(operationDescription, task, parentResult);
parentResult.recordInProgress();
parentResult.setAsynchronousOperationReference(asyncReturnValue.getOperationResult().getAsynchronousOperationReference());
} else {
operationListener.notifySuccess(operationDescription, task, parentResult);
parentResult.recordSuccess();
}
return oid;
}
use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class ShadowManager method extractRepoShadowChanges.
@SuppressWarnings("rawtypes")
private Collection<? extends ItemDelta> extractRepoShadowChanges(ProvisioningContext ctx, PrismObject<ShadowType> shadow, Collection<? extends ItemDelta> objectChange) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
Collection<ItemDelta> repoChanges = new ArrayList<ItemDelta>();
for (ItemDelta itemDelta : objectChange) {
if (new ItemPath(ShadowType.F_ATTRIBUTES).equivalent(itemDelta.getParentPath())) {
QName attrName = itemDelta.getElementName();
if (objectClassDefinition.isSecondaryIdentifier(attrName)) {
// Change of secondary identifier means object rename. We also need to change $shadow/name
// TODO: change this to displayName attribute later
String newName = null;
if (itemDelta.getValuesToReplace() != null && !itemDelta.getValuesToReplace().isEmpty()) {
newName = ((PrismPropertyValue) itemDelta.getValuesToReplace().iterator().next()).getValue().toString();
} else if (itemDelta.getValuesToAdd() != null && !itemDelta.getValuesToAdd().isEmpty()) {
newName = ((PrismPropertyValue) itemDelta.getValuesToAdd().iterator().next()).getValue().toString();
}
PropertyDelta<PolyString> nameDelta = PropertyDelta.createReplaceDelta(shadow.getDefinition(), ShadowType.F_NAME, new PolyString(newName));
repoChanges.add(nameDelta);
}
if (!ProvisioningUtil.shouldStoreAtributeInShadow(objectClassDefinition, attrName, cachingStrategy)) {
continue;
}
} else if (new ItemPath(ShadowType.F_ACTIVATION).equivalent(itemDelta.getParentPath())) {
if (!ProvisioningUtil.shouldStoreActivationItemInShadow(itemDelta.getElementName(), cachingStrategy)) {
continue;
}
} else if (new ItemPath(ShadowType.F_ACTIVATION).equivalent(itemDelta.getPath())) {
// should not occur, but for completeness...
for (PrismContainerValue<ActivationType> valueToAdd : ((ContainerDelta<ActivationType>) itemDelta).getValuesToAdd()) {
ProvisioningUtil.cleanupShadowActivation(valueToAdd.asContainerable());
}
for (PrismContainerValue<ActivationType> valueToReplace : ((ContainerDelta<ActivationType>) itemDelta).getValuesToReplace()) {
ProvisioningUtil.cleanupShadowActivation(valueToReplace.asContainerable());
}
} else if (SchemaConstants.PATH_PASSWORD.equivalent(itemDelta.getParentPath())) {
continue;
}
normalizeDelta(itemDelta, objectClassDefinition);
repoChanges.add(itemDelta);
}
return repoChanges;
}
Aggregations