use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ShadowIntegrityCheckResultHandler method doFixIntent.
private void doFixIntent(ShadowCheckResult checkResult, PrismObject<ShadowType> fetchedShadow, PrismObject<ShadowType> shadow, PrismObject<ResourceType> resource, Task task, OperationResult result) {
PrismObject<ShadowType> fullShadow;
if (!checkFetch) {
fullShadow = fetchShadow(checkResult, shadow, resource, task, result);
} else {
fullShadow = fetchedShadow;
}
if (fullShadow == null) {
checkResult.recordError(Statistics.CANNOT_APPLY_FIX, new SystemException("Cannot fix missing intent, because the resource object couldn't be fetched"));
return;
}
ObjectSynchronizationType synchronizationPolicy;
try {
synchronizationPolicy = synchronizationService.determineSynchronizationPolicy(resource.asObjectable(), fullShadow, configuration, task, result);
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException | RuntimeException e) {
checkResult.recordError(Statistics.CANNOT_APPLY_FIX, new SystemException("Couldn't prepare fix for missing intent, because the synchronization policy couldn't be determined", e));
return;
}
if (synchronizationPolicy != null) {
if (synchronizationPolicy.getIntent() != null) {
PropertyDelta delta = PropertyDelta.createReplaceDelta(fullShadow.getDefinition(), ShadowType.F_INTENT, synchronizationPolicy.getIntent());
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Intent fix delta (not executed now) = \n{}", delta.debugDump());
}
checkResult.addFixDelta(delta, Statistics.NO_INTENT_SPECIFIED);
} else {
LOGGER.info("Synchronization policy does not contain intent: {}", synchronizationPolicy);
}
} else {
LOGGER.info("Intent couldn't be fixed, because no synchronization policy was found");
}
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method generateValue.
@Override
public <O extends ObjectType> void generateValue(PrismObject<O> object, PolicyItemsDefinitionType policyItemsDefinition, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, PolicyViolationException {
String oid = object.getOid();
OperationResult result = parentResult.createSubresult(OPERATION_GENERATE_VALUE);
Class<O> clazz = (Class<O>) object.asObjectable().getClass();
ValuePolicyType valuePolicy = null;
try {
valuePolicy = getValuePolicy(object, task, result);
} catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
LOGGER.error("Failed to get value policy for generating value. ", e);
result.recordFatalError("Error while getting value policy. Reason: " + e.getMessage(), e);
throw e;
}
Collection<PropertyDelta<?>> deltasToExecute = new ArrayList<>();
for (PolicyItemDefinitionType policyItemDefinition : policyItemsDefinition.getPolicyItemDefinition()) {
OperationResult generateValueResult = parentResult.createSubresult(OPERATION_GENERATE_VALUE);
ItemPath path = getPath(policyItemDefinition);
if (path == null) {
LOGGER.error("No item path defined in the target for policy item definition. Cannot generate value");
generateValueResult.recordFatalError("No item path defined in the target for policy item definition. Cannot generate value");
continue;
}
result.addParam("policyItemPath", path);
PrismPropertyDefinition<?> propertyDef = getItemDefinition(object, path);
if (propertyDef == null) {
LOGGER.error("No definition for property {} in object. Is the path referencing prism property?" + path, object);
generateValueResult.recordFatalError("No definition for property " + path + " in object " + object + ". Is the path referencing prism property?");
continue;
}
LOGGER.trace("Default value policy: {}", valuePolicy);
try {
generateValue(object, valuePolicy, policyItemDefinition, task, generateValueResult);
} catch (ExpressionEvaluationException | SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
LOGGER.error("Failed to generate value for {} " + policyItemDefinition, e);
generateValueResult.recordFatalError("Failed to generate value for " + policyItemDefinition + ". Reason: " + e.getMessage(), e);
policyItemDefinition.setResult(generateValueResult.createOperationResultType());
continue;
}
collectDeltasForGeneratedValuesIfNeeded(object, policyItemDefinition, deltasToExecute, path, propertyDef);
generateValueResult.computeStatusIfUnknown();
}
result.computeStatus();
if (!result.isAcceptable()) {
return;
}
try {
if (!deltasToExecute.isEmpty()) {
modelCrudService.modifyObject(clazz, oid, deltasToExecute, null, task, result);
}
} catch (ObjectNotFoundException | SchemaException | ExpressionEvaluationException | CommunicationException | ConfigurationException | ObjectAlreadyExistsException | PolicyViolationException | SecurityViolationException e) {
LOGGER.error("Could not execute deltas for generated values. Reason: " + e.getMessage(), e);
result.recordFatalError("Could not execute deltas for gegenerated values. Reason: " + e.getMessage(), e);
throw e;
}
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method previewChanges.
@Override
public <F extends ObjectType> ModelContext<F> previewChanges(Collection<ObjectDelta<? extends ObjectType>> deltas, ModelExecuteOptions options, Task task, Collection<ProgressListener> listeners, OperationResult parentResult) throws SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectNotFoundException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Preview changes input:\n{}", DebugUtil.debugDump(deltas));
}
int size = 0;
if (deltas != null) {
size = deltas.size();
}
Collection<ObjectDelta<? extends ObjectType>> clonedDeltas = new ArrayList<>(size);
if (deltas != null) {
for (ObjectDelta delta : deltas) {
clonedDeltas.add(delta.clone());
}
}
OperationResult result = parentResult.createSubresult(PREVIEW_CHANGES);
LensContext<F> context;
try {
RepositoryCache.enter();
//used cloned deltas instead of origin deltas, because some of the values should be lost later..
context = contextFactory.createContext(clonedDeltas, options, task, result);
// context.setOptions(options);
if (LOGGER.isDebugEnabled()) {
LOGGER.trace("Preview changes context:\n{}", context.debugDump());
}
context.setProgressListeners(listeners);
projector.projectAllWaves(context, "preview", task, result);
context.distributeResource();
} catch (ConfigurationException | SecurityViolationException | ObjectNotFoundException | SchemaException | CommunicationException | PolicyViolationException | RuntimeException | ObjectAlreadyExistsException | ExpressionEvaluationException e) {
ModelUtils.recordFatalError(result, e);
throw e;
} finally {
RepositoryCache.exit();
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Preview changes output:\n{}", context.debugDump());
}
result.computeStatus();
result.cleanupResult();
return context;
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method getAssignableRoleSpecification.
@Override
public <F extends FocusType> RoleSelectionSpecification getAssignableRoleSpecification(PrismObject<F> focus, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, ConfigurationException {
OperationResult result = parentResult.createMinorSubresult(GET_ASSIGNABLE_ROLE_SPECIFICATION);
RoleSelectionSpecification spec = new RoleSelectionSpecification();
ObjectSecurityConstraints securityConstraints = securityEnforcer.compileSecurityConstraints(focus, null);
if (securityConstraints == null) {
return null;
}
AuthorizationDecisionType decision = securityConstraints.findItemDecision(new ItemPath(FocusType.F_ASSIGNMENT), ModelAuthorizationAction.MODIFY.getUrl(), AuthorizationPhaseType.REQUEST);
if (decision == AuthorizationDecisionType.ALLOW) {
getAllRoleTypesSpec(spec, result);
result.recordSuccess();
return spec;
}
if (decision == AuthorizationDecisionType.DENY) {
result.recordSuccess();
spec.setNoRoleTypes();
spec.setFilter(NoneFilter.createNone());
return spec;
}
decision = securityConstraints.getActionDecision(ModelAuthorizationAction.MODIFY.getUrl(), AuthorizationPhaseType.REQUEST);
if (decision == AuthorizationDecisionType.ALLOW) {
getAllRoleTypesSpec(spec, result);
result.recordSuccess();
return spec;
}
if (decision == AuthorizationDecisionType.DENY) {
result.recordSuccess();
spec.setNoRoleTypes();
spec.setFilter(NoneFilter.createNone());
return spec;
}
try {
ObjectFilter filter = securityEnforcer.preProcessObjectFilter(ModelAuthorizationAction.ASSIGN.getUrl(), AuthorizationPhaseType.REQUEST, AbstractRoleType.class, focus, AllFilter.createAll());
LOGGER.trace("assignableRoleSpec filter: {}", filter);
spec.setFilter(filter);
if (filter instanceof NoneFilter) {
result.recordSuccess();
spec.setNoRoleTypes();
return spec;
} else if (filter == null || filter instanceof AllFilter) {
getAllRoleTypesSpec(spec, result);
result.recordSuccess();
return spec;
} else if (filter instanceof OrFilter) {
Collection<RoleSelectionSpecEntry> allRoleTypeDvals = new ArrayList<>();
for (ObjectFilter subfilter : ((OrFilter) filter).getConditions()) {
Collection<RoleSelectionSpecEntry> roleTypeDvals = getRoleSelectionSpecEntries(subfilter);
if (roleTypeDvals == null || roleTypeDvals.isEmpty()) {
// This branch of the OR clause does not have any constraint for roleType
// therefore all role types are possible (regardless of other branches, this is OR)
spec = new RoleSelectionSpecification();
spec.setFilter(filter);
getAllRoleTypesSpec(spec, result);
result.recordSuccess();
return spec;
} else {
allRoleTypeDvals.addAll(roleTypeDvals);
}
}
addRoleTypeSpecEntries(spec, allRoleTypeDvals, result);
} else {
Collection<RoleSelectionSpecEntry> roleTypeDvals = getRoleSelectionSpecEntries(filter);
if (roleTypeDvals == null || roleTypeDvals.isEmpty()) {
getAllRoleTypesSpec(spec, result);
result.recordSuccess();
return spec;
} else {
addRoleTypeSpecEntries(spec, roleTypeDvals, result);
}
}
result.recordSuccess();
return spec;
} catch (SchemaException | ConfigurationException | ObjectNotFoundException e) {
result.recordFatalError(e);
throw e;
}
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method getEditObjectDefinition.
@Override
public <O extends ObjectType> PrismObjectDefinition<O> getEditObjectDefinition(PrismObject<O> object, AuthorizationPhaseType phase, Task task, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException {
OperationResult result = parentResult.createMinorSubresult(GET_EDIT_OBJECT_DEFINITION);
PrismObjectDefinition<O> objectDefinition = object.getDefinition().deepClone(true);
PrismObject<O> baseObject = object;
if (object.getOid() != null) {
// Re-read the object from the repository to make sure we have all the properties.
// the object from method parameters may be already processed by the security code
// and properties needed to evaluate authorizations may not be there
// MID-3126, see also MID-3435
baseObject = cacheRepositoryService.getObject(object.getCompileTimeClass(), object.getOid(), null, result);
}
// TODO: maybe we need to expose owner resolver in the interface?
ObjectSecurityConstraints securityConstraints = securityEnforcer.compileSecurityConstraints(baseObject, null);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Security constrains for {}:\n{}", object, securityConstraints == null ? "null" : securityConstraints.debugDump());
}
if (securityConstraints == null) {
// Nothing allowed => everything denied
result.setStatus(OperationResultStatus.NOT_APPLICABLE);
return null;
}
ObjectTemplateType objectTemplateType;
try {
objectTemplateType = schemaTransformer.determineObjectTemplate(object, phase, result);
} catch (ConfigurationException | ObjectNotFoundException e) {
result.recordFatalError(e);
throw e;
}
schemaTransformer.applyObjectTemplateToDefinition(objectDefinition, objectTemplateType, result);
schemaTransformer.applySecurityConstraints(objectDefinition, securityConstraints, phase);
if (object.canRepresent(ShadowType.class)) {
PrismObject<ShadowType> shadow = (PrismObject<ShadowType>) object;
String resourceOid = ShadowUtil.getResourceOid(shadow);
if (resourceOid != null) {
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createReadOnly());
PrismObject<ResourceType> resource;
try {
resource = provisioning.getObject(ResourceType.class, resourceOid, options, task, result);
} catch (CommunicationException | SecurityViolationException | ExpressionEvaluationException e) {
throw new ConfigurationException(e.getMessage(), e);
}
RefinedObjectClassDefinition refinedObjectClassDefinition = getEditObjectClassDefinition(shadow, resource, phase);
if (refinedObjectClassDefinition != null) {
((ComplexTypeDefinitionImpl) objectDefinition.getComplexTypeDefinition()).replaceDefinition(ShadowType.F_ATTRIBUTES, refinedObjectClassDefinition.toResourceAttributeContainerDefinition());
}
}
}
result.computeStatus();
return objectDefinition;
}
Aggregations