private void checkConstraints(ProvisioningContext ctx, PrismObject<ShadowType> shadow, ProvisioningOperationState<AsynchronousOperationReturnValue<PrismObject<ShadowType>>> opState, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException, ObjectAlreadyExistsException, SecurityViolationException {
ShadowCheckType shadowConstraintsCheck = ResourceTypeUtil.getShadowConstraintsCheck(ctx.getResource());
if (shadowConstraintsCheck == ShadowCheckType.NONE) {
return;
}
String shadowOid = shadow.getOid();
if (opState.getRepoShadow() != null) {
shadowOid = opState.getRepoShadow().getOid();
}
ConstraintsChecker checker = new ConstraintsChecker();
checker.setRepositoryService(repositoryService);
checker.setShadowCache(this);
checker.setPrismContext(prismContext);
checker.setProvisioningContext(ctx);
checker.setShadowObject(shadow);
checker.setShadowOid(shadowOid);
checker.setConstraintViolationConfirmer(conflictingShadowCandidate -> !Boolean.TRUE.equals(conflictingShadowCandidate.asObjectable().isDead()) );
checker.setUseCache(false);
ConstraintsCheckingResult retval = checker.check(task, result);
LOGGER.trace("Checked {} constraints, result={}", shadow, retval.isSatisfiesConstraints());
if (!retval.isSatisfiesConstraints()) {
throw new ObjectAlreadyExistsException("Conflicting shadow already exists on "+ctx.getResource());
}
}