use of com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult in project midpoint by Evolveum.
the class ConstraintsChecker method check.
public ConstraintsCheckingResult check(Task task, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
constraintsCheckingResult = new ConstraintsCheckingResult();
constraintsCheckingResult.setSatisfiesConstraints(true);
PrismContainer<?> attributesContainer = shadowObject.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer == null) {
// No attributes no constraint violations
LOGGER.trace("Current shadow does not contain attributes, skipping checking uniqueness.");
return constraintsCheckingResult;
}
Collection<? extends ResourceAttributeDefinition> uniqueAttributeDefs = MiscUtil.unionExtends(shadowDefinition.getPrimaryIdentifiers(), shadowDefinition.getSecondaryIdentifiers());
LOGGER.trace("Secondary IDs {}", shadowDefinition.getSecondaryIdentifiers());
for (ResourceAttributeDefinition attrDef : uniqueAttributeDefs) {
PrismProperty<?> attr = attributesContainer.findProperty(attrDef.getName());
LOGGER.trace("Attempt to check uniqueness of {} (def {})", attr, attrDef);
if (attr == null) {
continue;
}
constraintsCheckingResult.getCheckedAttributes().add(attr.getElementName());
boolean unique = checkAttributeUniqueness(attr, shadowDefinition, resourceType, shadowOid, task, result);
if (!unique) {
LOGGER.debug("Attribute {} conflicts with existing object (in {})", attr, resourceShadowDiscriminator);
constraintsCheckingResult.getConflictingAttributes().add(attr.getElementName());
constraintsCheckingResult.setSatisfiesConstraints(false);
}
}
constraintsCheckingResult.setMessages(messageBuilder.toString());
return constraintsCheckingResult;
}
use of com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult in project midpoint by Evolveum.
the class ConstraintsChecker method check.
public ConstraintsCheckingResult check(OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
OperationResult result = parentResult.subresult(ConstraintsChecker.class.getName() + ".check").setMinor().build();
try {
constraintsCheckingResult = new ConstraintsCheckingResult();
constraintsCheckingResult.setSatisfiesConstraints(true);
PrismContainer<?> attributesContainer = shadowObject.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer == null) {
// No attributes no constraint violations
LOGGER.trace("Current shadow does not contain attributes, skipping checking uniqueness.");
return constraintsCheckingResult;
}
Collection<? extends ResourceAttributeDefinition<?>> uniqueAttributeDefs = getUniqueAttributesDefinitions();
LOGGER.trace("Checking uniqueness of attributes: {}", uniqueAttributeDefs);
for (ResourceAttributeDefinition<?> attrDef : uniqueAttributeDefs) {
PrismProperty<?> attr = attributesContainer.findProperty(attrDef.getItemName());
LOGGER.trace("Attempt to check uniqueness of {} (def {})", attr, attrDef);
if (attr == null) {
continue;
}
constraintsCheckingResult.getCheckedAttributes().add(attr.getElementName());
boolean unique = checkAttributeUniqueness(attr, result);
if (!unique) {
LOGGER.debug("Attribute {} conflicts with existing object (in {})", attr, provisioningContext);
constraintsCheckingResult.getConflictingAttributes().add(attr.getElementName());
constraintsCheckingResult.setSatisfiesConstraints(false);
}
}
constraintsCheckingResult.setMessages(messageBuilder.toString());
return constraintsCheckingResult;
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult in project midpoint by Evolveum.
the class ProvisioningServiceImpl method checkConstraints.
@Override
public ConstraintsCheckingResult checkConstraints(RefinedObjectClassDefinition shadowDefinition, PrismObject<ShadowType> shadowObject, ResourceType resourceType, String shadowOid, ResourceShadowDiscriminator resourceShadowDiscriminator, ConstraintViolationConfirmer constraintViolationConfirmer, Task task, OperationResult parentResult) throws CommunicationException, ObjectAlreadyExistsException, SchemaException, SecurityViolationException, ConfigurationException, ObjectNotFoundException, ExpressionEvaluationException {
OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".checkConstraints");
ConstraintsChecker checker = new ConstraintsChecker();
checker.setCacheRepositoryService(cacheRepositoryService);
checker.setProvisioningService(this);
checker.setPrismContext(prismContext);
checker.setShadowDefinition(shadowDefinition);
checker.setShadowObject(shadowObject);
checker.setResourceType(resourceType);
checker.setShadowOid(shadowOid);
checker.setResourceShadowDiscriminator(resourceShadowDiscriminator);
checker.setConstraintViolationConfirmer(constraintViolationConfirmer);
try {
ConstraintsCheckingResult retval = checker.check(task, result);
result.computeStatus();
return retval;
} catch (CommunicationException | ObjectAlreadyExistsException | SchemaException | SecurityViolationException | ConfigurationException | ObjectNotFoundException | RuntimeException e) {
result.recordFatalError(e.getMessage(), e);
throw e;
}
}
use of com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult in project midpoint by Evolveum.
the class AddHelper method checkConstraints.
private void checkConstraints(PrismObject<ShadowType> resourceObjectToAdd, ProvisioningOperationState<AsynchronousOperationReturnValue<PrismObject<ShadowType>>> opState, ProvisioningContext ctx, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException, ObjectAlreadyExistsException, SecurityViolationException {
ShadowCheckType shadowConstraintsCheck = ResourceTypeUtil.getShadowConstraintsCheck(ctx.getResource());
if (shadowConstraintsCheck == ShadowCheckType.NONE) {
return;
}
String shadowOid;
if (opState.getRepoShadow() != null) {
shadowOid = opState.getRepoShadow().getOid();
} else {
shadowOid = resourceObjectToAdd.getOid();
}
ConstraintsChecker checker = new ConstraintsChecker();
checker.setCacheConfigurationManager(cacheConfigurationManager);
// TODO ok?
checker.setShadowsFacade(shadowsFacade);
checker.setProvisioningContext(ctx);
checker.setShadowObject(resourceObjectToAdd);
checker.setShadowOid(shadowOid);
checker.setConstraintViolationConfirmer(ShadowUtil::isNotDead);
checker.setUseCache(false);
ConstraintsCheckingResult checkingResult = checker.check(result);
LOGGER.trace("Checked {} constraints, result={}", resourceObjectToAdd.debugDumpLazily(), checkingResult.isSatisfiesConstraints());
if (!checkingResult.isSatisfiesConstraints()) {
throw new ObjectAlreadyExistsException("Conflicting shadow already exists on " + ctx.getResource());
}
}
use of com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult in project midpoint by Evolveum.
the class ShadowConstraintsChecker method check.
public void check(Task task, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
CompositeObjectDefinition projOcDef = projectionContext.getCompositeObjectDefinition();
PrismObject<ShadowType> projectionNew = projectionContext.getObjectNew();
if (projectionNew == null) {
// This must be delete
LOGGER.trace("No new object in projection context. Current shadow satisfy constraints");
satisfiesConstraints = true;
return;
}
PrismContainer<?> attributesContainer = projectionNew.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer == null) {
// No attributes no constraint violations
LOGGER.trace("Current shadow does not contain attributes, skipping checking uniqueness.");
satisfiesConstraints = true;
return;
}
ConstraintViolationConfirmer confirmer = (conflictingShadowCandidate) -> {
boolean violation = true;
LensProjectionContext foundContext = context.findProjectionContextByOid(conflictingShadowCandidate.getOid());
if (foundContext != null) {
if (foundContext.isGone()) {
violation = false;
}
LOGGER.trace("Comparing with account in other context resulted to violation confirmation of {}", violation);
}
return violation;
};
constraintsCheckingResult = provisioningService.checkConstraints(projOcDef, projectionNew, projectionContext.getObjectOld(), projectionContext.getResource(), projectionContext.getOid(), projectionContext.getResourceShadowDiscriminator(), confirmer, context.getProjectionConstraintsCheckingStrategy(), task, result);
if (constraintsCheckingResult.isSatisfiesConstraints()) {
satisfiesConstraints = true;
return;
}
for (QName checkedAttributeName : constraintsCheckingResult.getCheckedAttributes()) {
if (constraintsCheckingResult.getConflictingAttributes().contains(checkedAttributeName)) {
if (isInDelta(checkedAttributeName, projectionContext.getPrimaryDelta())) {
throw new ObjectAlreadyExistsException("Attribute " + checkedAttributeName + " conflicts with existing object (and it is present in primary " + "account delta therefore no iteration is performed)");
}
}
}
if (projectionContext.isGone()) {
satisfiesConstraints = true;
} else {
satisfiesConstraints = false;
}
}
Aggregations