use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestSegregationOfDuties method test142SimpleExclusionBoth2Deprecated.
@Test
public void test142SimpleExclusionBoth2Deprecated() throws Exception {
final String TEST_NAME = "test142SimpleExclusionBoth2Deprecated";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestSegregationOfDuties.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
modifications.add((createAssignmentModification(ROLE_PIRATE_OID, RoleType.COMPLEX_TYPE, null, null, null, true)));
modifications.add((createAssignmentModification(ROLE_JUDGE_DEPRECATED_OID, RoleType.COMPLEX_TYPE, null, null, null, true)));
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
try {
modelService.executeChanges(MiscSchemaUtil.createCollection(userDelta), null, task, result);
AssertJUnit.fail("Expected policy violation, but it went well");
} catch (PolicyViolationException e) {
// This is expected
}
assertAssignedNoRole(USER_JACK_OID, task, result);
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class ShadowManager method lookupShadowInRepository.
/**
* Locates the appropriate Shadow in repository that corresponds to the
* provided resource object.
*
* DEAD flag is cleared - in memory as well as in repository.
*
* @param parentResult
*
* @return current shadow object that corresponds to provided
* resource object or null if the object does not exist
*/
public PrismObject<ShadowType> lookupShadowInRepository(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
ObjectQuery query = createSearchShadowQuery(ctx, resourceShadow, prismContext, parentResult);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Searching for shadow using filter:\n{}", query.debugDump());
}
// PagingType paging = new PagingType();
// TODO: check for errors
List<PrismObject<ShadowType>> results = repositoryService.searchObjects(ShadowType.class, query, null, parentResult);
MiscSchemaUtil.reduceSearchResult(results);
LOGGER.trace("lookupShadow found {} objects", results.size());
if (results.size() == 0) {
return null;
}
if (results.size() > 1) {
for (PrismObject<ShadowType> result : results) {
LOGGER.trace("Search result:\n{}", result.debugDump());
}
LOGGER.error("More than one shadow found for " + resourceShadow);
// TODO: Better error handling later
throw new IllegalStateException("More than one shadow found for " + resourceShadow);
}
PrismObject<ShadowType> shadow = results.get(0);
checkConsistency(shadow);
if (Boolean.TRUE.equals(shadow.asObjectable().isDead())) {
LOGGER.debug("Repository shadow {} is marked as dead - resetting the flag", ObjectTypeUtil.toShortString(shadow));
shadow.asObjectable().setDead(false);
List<ItemDelta<?, ?>> deltas = DeltaBuilder.deltaFor(ShadowType.class, prismContext).item(ShadowType.F_DEAD).replace().asItemDeltas();
try {
repositoryService.modifyObject(ShadowType.class, shadow.getOid(), deltas, parentResult);
} catch (ObjectAlreadyExistsException e) {
throw new SystemException("Unexpected exception when resetting 'dead' flag: " + e.getMessage(), e);
}
}
return shadow;
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class ShadowCacheReconciler method beforeModifyOnResource.
@Override
public Collection<? extends ItemDelta> beforeModifyOnResource(PrismObject<ShadowType> shadow, ProvisioningOperationOptions options, Collection<? extends ItemDelta> modifications) throws SchemaException {
ObjectDeltaType shadowDelta = shadow.asObjectable().getObjectChange();
//TODO: error handling
if (shadowDelta != null) {
modifications = DeltaConvertor.toModifications(shadowDelta.getItemDelta(), shadow.getDefinition());
}
// for the older versions
ObjectDelta<? extends ObjectType> objectDelta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, ShadowType.class, getPrismContext());
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Storing delta to shadow:\n{}", objectDelta.debugDump());
}
ContainerDelta<ShadowAssociationType> associationDelta = objectDelta.findContainerDelta(ShadowType.F_ASSOCIATION);
if (associationDelta != null) {
normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToAdd());
normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToReplace());
normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToDelete());
}
if (modifications == null) {
modifications = new ArrayList<ItemDelta>();
}
return modifications;
}
use of com.evolveum.midpoint.prism.delta.ItemDelta 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;
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class ShadowManager method updateShadow.
@SuppressWarnings("unchecked")
public Collection<ItemDelta> updateShadow(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow, Collection<? extends ItemDelta> aprioriDeltas, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, resourceShadow.getOid(), null, result);
RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
Collection<ItemDelta> repoShadowChanges = new ArrayList<ItemDelta>();
CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
for (RefinedAttributeDefinition attrDef : objectClassDefinition.getAttributeDefinitions()) {
if (ProvisioningUtil.shouldStoreAtributeInShadow(objectClassDefinition, attrDef.getName(), cachingStrategy)) {
ResourceAttribute<Object> resourceAttr = ShadowUtil.getAttribute(resourceShadow, attrDef.getName());
PrismProperty<Object> repoAttr = repoShadow.findProperty(new ItemPath(ShadowType.F_ATTRIBUTES, attrDef.getName()));
PropertyDelta attrDelta;
if (repoAttr == null && repoAttr == null) {
continue;
}
if (repoAttr == null) {
attrDelta = attrDef.createEmptyDelta(new ItemPath(ShadowType.F_ATTRIBUTES, attrDef.getName()));
attrDelta.setValuesToReplace(PrismValue.cloneCollection(resourceAttr.getValues()));
} else {
attrDelta = repoAttr.diff(resourceAttr);
// LOGGER.trace("DIFF:\n{}\n-\n{}\n=:\n{}", repoAttr==null?null:repoAttr.debugDump(1), resourceAttr==null?null:resourceAttr.debugDump(1), attrDelta==null?null:attrDelta.debugDump(1));
}
if (attrDelta != null && !attrDelta.isEmpty()) {
normalizeDelta(attrDelta, attrDef);
repoShadowChanges.add(attrDelta);
}
}
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Updating repo shadow {}:\n{}", resourceShadow.getOid(), DebugUtil.debugDump(repoShadowChanges));
}
try {
repositoryService.modifyObject(ShadowType.class, resourceShadow.getOid(), repoShadowChanges, result);
} catch (ObjectAlreadyExistsException e) {
// We are not renaming the object here. This should not happen.
throw new SystemException(e.getMessage(), e);
}
return repoShadowChanges;
}
Aggregations