Search in sources :

Example 21 with ConfigurationException

use of com.evolveum.midpoint.util.exception.ConfigurationException 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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 22 with ConfigurationException

use of com.evolveum.midpoint.util.exception.ConfigurationException 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;
    }
}
Also used : NoneFilter(com.evolveum.midpoint.prism.query.NoneFilter) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) OrFilter(com.evolveum.midpoint.prism.query.OrFilter) ObjectSecurityConstraints(com.evolveum.midpoint.security.api.ObjectSecurityConstraints) AllFilter(com.evolveum.midpoint.prism.query.AllFilter) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 23 with ConfigurationException

use of com.evolveum.midpoint.util.exception.ConfigurationException 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;
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectSecurityConstraints(com.evolveum.midpoint.security.api.ObjectSecurityConstraints) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 24 with ConfigurationException

use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.

the class AbstractSearchExpressionEvaluator method executeSearchAttempt.

private <O extends ObjectType> List<V> executeSearchAttempt(final List<PrismObject> rawResult, Class<O> targetTypeClass, final QName targetTypeQName, ObjectQuery query, boolean searchOnResource, boolean tryAlsoRepository, final List<ItemDelta<V, D>> additionalAttributeDeltas, final ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    final List<V> list = new ArrayList<V>();
    Collection<SelectorOptions<GetOperationOptions>> options = new ArrayList<>();
    if (!searchOnResource) {
        options.add(SelectorOptions.create(GetOperationOptions.createNoFetch()));
    }
    extendOptions(options, searchOnResource);
    ResultHandler<O> handler = new ResultHandler<O>() {

        @Override
        public boolean handle(PrismObject<O> object, OperationResult parentResult) {
            if (rawResult != null) {
                rawResult.add(object);
            }
            list.add(createPrismValue(object.getOid(), targetTypeQName, additionalAttributeDeltas, params));
            return true;
        }
    };
    try {
        objectResolver.searchIterative(targetTypeClass, query, options, handler, task, result);
    } catch (IllegalStateException e) {
        // this comes from checkConsistence methods
        throw new IllegalStateException(e.getMessage() + " in " + contextDescription, e);
    } catch (SchemaException e) {
        throw new SchemaException(e.getMessage() + " in " + contextDescription, e);
    } catch (SystemException e) {
        throw new SystemException(e.getMessage() + " in " + contextDescription, e);
    } catch (CommunicationException | ConfigurationException | SecurityViolationException e) {
        if (searchOnResource && tryAlsoRepository) {
            options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
            try {
                objectResolver.searchIterative(targetTypeClass, query, options, handler, task, result);
            } catch (SchemaException e1) {
                throw new SchemaException(e1.getMessage() + " in " + contextDescription, e1);
            } catch (CommunicationException | ConfigurationException | SecurityViolationException e1) {
                // shadow for group doesn't exist? (MID-2107)
                throw new ExpressionEvaluationException("Unexpected expression exception " + e + ": " + e.getMessage(), e);
            }
        } else {
            throw new ExpressionEvaluationException("Unexpected expression exception " + e + ": " + e.getMessage(), e);
        }
    } catch (ObjectNotFoundException e) {
        throw e;
    }
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Assignment expression resulted in {} objects, using query:\n{}", list.size(), query.debugDump());
    }
    return list;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 25 with ConfigurationException

use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.

the class ResourceObjectReferenceResolver method fetchResourceObject.

public PrismObject<ShadowType> fetchResourceObject(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, AttributesToReturn attributesToReturn, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
    ResourceType resource = ctx.getResource();
    ConnectorInstance connector = ctx.getConnector(ReadCapabilityType.class, parentResult);
    RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
    try {
        if (!ResourceTypeUtil.isReadCapabilityEnabled(resource)) {
            throw new UnsupportedOperationException("Resource does not support 'read' operation");
        }
        ResourceObjectIdentification identification = ResourceObjectIdentification.create(objectClassDefinition, identifiers);
        identification = resolvePrimaryIdentifiers(ctx, identification, parentResult);
        identification.validatePrimaryIdenfiers();
        return connector.fetchObject(ShadowType.class, identification, attributesToReturn, ctx, parentResult);
    } catch (ObjectNotFoundException e) {
        parentResult.recordFatalError("Object not found. Identifiers: " + identifiers + ". Reason: " + e.getMessage(), e);
        throw new ObjectNotFoundException("Object not found. identifiers=" + identifiers + ", objectclass=" + PrettyPrinter.prettyPrint(objectClassDefinition.getTypeName()) + ": " + e.getMessage(), e);
    } catch (CommunicationException e) {
        parentResult.recordFatalError("Error communication with the connector " + connector + ": " + e.getMessage(), e);
        throw e;
    } catch (GenericFrameworkException e) {
        parentResult.recordFatalError("Generic error in the connector " + connector + ". Reason: " + e.getMessage(), e);
        throw new GenericConnectorException("Generic error in the connector " + connector + ". Reason: " + e.getMessage(), e);
    } catch (SchemaException ex) {
        parentResult.recordFatalError("Can't get resource object, schema error: " + ex.getMessage(), ex);
        throw ex;
    } catch (ExpressionEvaluationException ex) {
        parentResult.recordFatalError("Can't get resource object, expression error: " + ex.getMessage(), ex);
        throw ex;
    } catch (ConfigurationException e) {
        parentResult.recordFatalError(e);
        throw e;
    }
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) ResourceObjectIdentification(com.evolveum.midpoint.schema.processor.ResourceObjectIdentification) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)

Aggregations

ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)110 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)86 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)84 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)81 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)81 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)71 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)65 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)33 SystemException (com.evolveum.midpoint.util.exception.SystemException)29 Task (com.evolveum.midpoint.task.api.Task)27 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)26 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)25 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)24 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)20 QName (javax.xml.namespace.QName)20 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)18 ArrayList (java.util.ArrayList)15 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)13 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)13