use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.
the class BaseCertificationHandler method revokeAssignmentCase.
// @NotNull
// protected <F extends FocusType> FocusType castToFocus(PrismObject<F> objectPrism) {
// ObjectType object = objectPrism.asObjectable();
// if (!(object instanceof FocusType)) {
// throw new IllegalStateException(ExclusionCertificationHandler.class.getSimpleName() + " cannot be run against non-focal object: " + ObjectTypeUtil
// .toShortString(object));
// }
// return (FocusType) object;
// }
// TODO move to some helper?
protected void revokeAssignmentCase(AccessCertificationAssignmentCaseType assignmentCase, AccessCertificationCampaignType campaign, OperationResult caseResult, Task task) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
String objectOid = assignmentCase.getObjectRef().getOid();
Class<? extends Objectable> clazz = ObjectTypes.getObjectTypeFromTypeQName(assignmentCase.getObjectRef().getType()).getClassDefinition();
PrismContainerValue<AssignmentType> cval = assignmentCase.getAssignment().asPrismContainerValue().clone();
ContainerDelta assignmentDelta;
if (Boolean.TRUE.equals(assignmentCase.isIsInducement())) {
assignmentDelta = ContainerDelta.createModificationDelete(AbstractRoleType.F_INDUCEMENT, clazz, prismContext, cval);
} else {
assignmentDelta = ContainerDelta.createModificationDelete(FocusType.F_ASSIGNMENT, clazz, prismContext, cval);
}
@SuppressWarnings({ "unchecked", "raw" }) ObjectDelta<? extends ObjectType> objectDelta = (ObjectDelta<? extends ObjectType>) ObjectDelta.createModifyDelta(objectOid, Collections.singletonList(assignmentDelta), clazz, prismContext);
LOGGER.info("Going to execute delta: {}", objectDelta.debugDump());
modelService.executeChanges(Collections.singletonList(objectDelta), null, task, caseResult);
LOGGER.info("Case {} in {} ({} {} of {}) was successfully revoked", assignmentCase.asPrismContainerValue().getId(), ObjectTypeUtil.toShortString(campaign), Boolean.TRUE.equals(assignmentCase.isIsInducement()) ? "inducement" : "assignment", cval.getId(), objectOid);
}
use of com.evolveum.midpoint.prism.delta.ContainerDelta 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);
}
}
}
}
use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.
the class PageRegistrationConfirmation method assignDefaultRoles.
private OperationResult assignDefaultRoles(final String userOid) {
List<ContainerDelta<AssignmentType>> assignments = new ArrayList<>();
for (ObjectReferenceType defaultRole : getSelfRegistrationConfiguration().getDefaultRoles()) {
AssignmentType assignment = new AssignmentType();
assignment.setTargetRef(defaultRole);
try {
getPrismContext().adopt(assignment);
assignments.add(ContainerDelta.createModificationAdd(UserType.F_ASSIGNMENT, UserType.class, getPrismContext(), assignment));
} catch (SchemaException e) {
//nothing to do
}
}
final ObjectDelta<UserType> delta = ObjectDelta.createModifyDelta(userOid, assignments, UserType.class, getPrismContext());
return runPrivileged(new Producer<OperationResult>() {
@Override
public OperationResult run() {
OperationResult result = new OperationResult(OPERATION_ASSIGN_DEFAULT_ROLES);
Task task = createAnonymousTask(OPERATION_ASSIGN_DEFAULT_ROLES);
WebModelServiceUtils.save(delta, result, task, PageRegistrationConfirmation.this);
result.computeStatusIfUnknown();
return result;
}
});
}
use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.
the class PageAssignmentsList method handleAssignmentDeltas.
private ContainerDelta handleAssignmentDeltas(ObjectDelta<UserType> focusDelta, List<AssignmentEditorDto> assignments, PrismContainerDefinition def) throws SchemaException {
ContainerDelta assDelta = new ContainerDelta(new ItemPath(), def.getName(), def, getPrismContext());
for (AssignmentEditorDto assDto : assignments) {
PrismContainerValue newValue = assDto.getNewValue(getPrismContext());
switch(assDto.getStatus()) {
case ADD:
newValue.applyDefinition(def, false);
assDelta.addValueToAdd(newValue.clone());
break;
case DELETE:
PrismContainerValue oldValue = assDto.getOldValue();
oldValue.applyDefinition(def);
assDelta.addValueToDelete(oldValue.clone());
break;
case MODIFY:
if (!assDto.isModified(getPrismContext())) {
LOGGER.trace("Assignment '{}' not modified.", new Object[] { assDto.getName() });
continue;
}
handleModifyAssignmentDelta(assDto, def, newValue, focusDelta);
break;
default:
warn(getString("pageAdminUser.message.illegalAssignmentState", assDto.getStatus()));
}
}
if (!assDelta.isEmpty()) {
assDelta = focusDelta.addModification(assDelta);
}
return assDelta;
}
use of com.evolveum.midpoint.prism.delta.ContainerDelta 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