Search in sources :

Example 41 with ConfigurationException

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

the class ProvisioningServiceImpl method deleteObject.

@Override
public <T extends ObjectType> void deleteObject(Class<T> type, String oid, ProvisioningOperationOptions options, OperationProvisioningScriptsType scripts, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    Validate.notNull(oid, "Oid of object to delete must not be null.");
    Validate.notNull(parentResult, "Operation result must not be null.");
    LOGGER.trace("**PROVISIONING: Start to delete object with oid {}", oid);
    OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".deleteObject");
    result.addParam("oid", oid);
    result.addParam("scripts", scripts);
    result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
    //TODO: is critical when shadow does not exits anymore?? do we need to log it?? if not, change null to allowNotFound options
    PrismObject<T> object = getRepoObject(type, oid, null, result);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("**PROVISIONING: Object from repository to delete:\n{}", object.debugDump());
    }
    if (object.canRepresent(ShadowType.class) && !ProvisioningOperationOptions.isRaw(options)) {
        try {
            getShadowCache(Mode.STANDARD).deleteShadow((PrismObject<ShadowType>) object, options, scripts, task, result);
        } catch (CommunicationException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: communication problem: " + e.getMessage(), e);
            throw new CommunicationException(e.getMessage(), e);
        } catch (GenericFrameworkException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: generic error in the connector: " + e.getMessage(), e);
            throw new CommunicationException(e.getMessage(), e);
        } catch (SchemaException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: schema problem: " + e.getMessage(), e);
            throw new SchemaException(e.getMessage(), e);
        } catch (ConfigurationException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: configuration problem: " + e.getMessage(), e);
            throw e;
        } catch (SecurityViolationException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: security violation: " + e.getMessage(), e);
            throw e;
        } catch (ExpressionEvaluationException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: expression errror: " + e.getMessage(), e);
            throw e;
        } catch (RuntimeException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: " + e.getMessage(), e);
            throw new SystemException(e);
        }
    } else if (object.canRepresent(ResourceType.class)) {
        resourceManager.deleteResource(oid, options, task, result);
    } else {
        try {
            getCacheRepositoryService().deleteObject(type, oid, result);
        } catch (ObjectNotFoundException ex) {
            result.recordFatalError(ex);
            result.cleanupResult(ex);
            throw ex;
        }
    }
    LOGGER.trace("**PROVISIONING: Finished deleting object.");
    result.computeStatus();
    result.cleanupResult();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 42 with ConfigurationException

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

the class ProvisioningServiceImpl method getObject.

@SuppressWarnings("unchecked")
@Override
public <T extends ObjectType> PrismObject<T> getObject(Class<T> type, String oid, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    Validate.notNull(oid, "Oid of object to get must not be null.");
    Validate.notNull(parentResult, "Operation result must not be null.");
    // Result type for this operation
    OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".getObject");
    result.addParam(OperationResult.PARAM_OID, oid);
    result.addParam(OperationResult.PARAM_TYPE, type);
    result.addCollectionOfSerializablesAsParam("options", options);
    result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
    GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
    PrismObject<T> resultingObject = null;
    if (ResourceType.class.isAssignableFrom(type)) {
        if (GetOperationOptions.isRaw(rootOptions)) {
            try {
                resultingObject = (PrismObject<T>) cacheRepositoryService.getObject(ResourceType.class, oid, null, result);
            } catch (ObjectNotFoundException | SchemaException ex) {
                // catching an exception is important because otherwise the result is UNKNOWN
                result.recordFatalError(ex);
                throw ex;
            }
            try {
                applyDefinition(resultingObject, task, result);
            } catch (ObjectNotFoundException ex) {
                // this is almost OK, we use raw for debug pages, so we want
                // to return resource and it can be fixed
                result.muteLastSubresultError();
                ProvisioningUtil.logWarning(LOGGER, result, "Bad connector reference defined for resource:  " + ex.getMessage(), ex);
            } catch (SchemaException ex) {
                result.muteLastSubresultError();
                ProvisioningUtil.logWarning(LOGGER, result, "Schema violation:  " + ex.getMessage(), ex);
            } catch (ConfigurationException ex) {
                result.muteLastSubresultError();
                ProvisioningUtil.logWarning(LOGGER, result, "Configuration problem:  " + ex.getMessage(), ex);
            }
        } else {
            // schema
            try {
                resultingObject = (PrismObject<T>) resourceManager.getResource(oid, SelectorOptions.findRootOptions(options), task, result);
            } catch (ObjectNotFoundException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Resource object not found", ex);
                throw ex;
            } catch (SchemaException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Schema violation", ex);
                throw ex;
            } catch (CommunicationException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error communicating with resource", ex);
                throw ex;
            } catch (ConfigurationException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Bad resource configuration", ex);
                throw ex;
            } catch (ExpressionEvaluationException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Expression error", ex);
                throw ex;
            }
        }
    } else {
        // Not resource
        PrismObject<T> repositoryObject = getRepoObject(type, oid, rootOptions, result);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Retrieved repository object:\n{}", repositoryObject.debugDump());
        }
        if (repositoryObject.canRepresent(ShadowType.class)) {
            try {
                resultingObject = (PrismObject<T>) getShadowCache(Mode.STANDARD).getShadow(oid, (PrismObject<ShadowType>) (repositoryObject), options, task, result);
            } catch (ObjectNotFoundException e) {
                if (!GetOperationOptions.isAllowNotFound(rootOptions)) {
                    ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                } else {
                    result.muteLastSubresultError();
                    result.computeStatus();
                }
                throw e;
            } catch (CommunicationException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (SchemaException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (ConfigurationException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (SecurityViolationException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (SystemException e) {
                // Do NOT wrap this into SystemException again
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (RuntimeException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw new SystemException(e);
            }
        } else {
            resultingObject = repositoryObject;
        }
    }
    result.computeStatus();
    if (!GetOperationOptions.isRaw(rootOptions)) {
        resultingObject = resultingObject.cloneIfImmutable();
        resultingObject.asObjectable().setFetchResult(result.createOperationResultType());
    }
    result.cleanupResult();
    validateObject(resultingObject);
    return resultingObject;
}
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) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 43 with ConfigurationException

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

the class ProvisioningServiceImpl method handleRepoObject.

private <T extends ObjectType> boolean handleRepoObject(final Class<T> type, PrismObject<T> object, final Collection<SelectorOptions<GetOperationOptions>> options, final ResultHandler<T> handler, Task task, final OperationResult objResult) {
    PrismObject<T> completeObject;
    try {
        completeObject = completeObject(type, object, options, task, objResult);
    } catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        LOGGER.error("Error while completing {}: {}. Using non-complete object.", new Object[] { object, e.getMessage(), e });
        objResult.recordFatalError(e);
        object.asObjectable().setFetchResult(objResult.createOperationResultType());
        completeObject = object;
    }
    validateObject(completeObject);
    if (ShadowType.class.isAssignableFrom(type) && GetOperationOptions.isMaxStaleness(SelectorOptions.findRootOptions(options))) {
        CachingMetadataType cachingMetadata = ((ShadowType) completeObject.asObjectable()).getCachingMetadata();
        if (cachingMetadata == null) {
            objResult.recordFatalError("Requested cached data but no cached data are available in the shadow");
        }
    }
    objResult.computeStatus();
    objResult.recordSuccessIfUnknown();
    if (!objResult.isSuccess()) {
        OperationResultType resultType = objResult.createOperationResultType();
        completeObject.asObjectable().setFetchResult(resultType);
    }
    return handler.handle(completeObject, objResult);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) CachingMetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType)

Example 44 with ConfigurationException

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

the class ResourceManager method completeResource.

/**
	 * Make sure that the resource is complete.
	 * 
	 * It will check if the resource has a sufficiently fresh schema, etc.
	 * 
	 * Returned resource may be the same or may be a different instance, but it
	 * is guaranteed that it will be "fresher" and will correspond to the
	 * repository state (assuming that the provided resource also corresponded
	 * to the repository state).
	 * 
	 * The connector schema that was fetched before can be supplied to this
	 * method. This is just an optimization. It comes handy e.g. in test
	 * connection case.
	 * 
	 * Note: This is not really the best place for this method. Need to figure
	 * out correct place later.
	 * 
	 * @param repoResource
	 *            Resource to check
	 * @param resourceSchema
	 *            schema that was freshly pre-fetched (or null)
	 * @param parentResult
	 * 
	 * @return completed resource
	 */
private PrismObject<ResourceType> completeResource(PrismObject<ResourceType> repoResource, ResourceSchema resourceSchema, boolean fetchedSchema, Map<String, Collection<Object>> capabilityMap, GetOperationOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    // do not add as a subresult..it will be added later, if the completing
    // of resource will be successfull.if not, it will be only set as a
    // fetch result in the resource..
    OperationResult result = parentResult.createMinorSubresult(OPERATION_COMPLETE_RESOURCE);
    try {
        applyConnectorSchemaToResource(repoResource, task, result);
    } catch (SchemaException e) {
        String message = "Schema error while applying connector schema to connectorConfiguration section of " + repoResource + ": " + e.getMessage();
        result.recordPartialError(message, e);
        LOGGER.warn(message, e);
        return repoResource;
    } catch (ObjectNotFoundException e) {
        String message = "Object not found error while processing connector configuration of " + repoResource + ": " + e.getMessage();
        result.recordPartialError(message, e);
        LOGGER.warn(message, e);
        return repoResource;
    } catch (RuntimeException e) {
        String message = "Unexpected error while processing connector configuration of " + repoResource + ": " + e.getMessage();
        result.recordPartialError(message, e);
        LOGGER.warn(message, e);
        return repoResource;
    }
    PrismObject<ResourceType> newResource;
    if (isComplete(repoResource)) {
        // The resource is complete.
        newResource = repoResource;
    } else {
        if (GetOperationOptions.isNoFetch(options)) {
            // We need to fetch schema, but the noFetch option is specified. Therefore return whatever we have.
            result.recordSuccessIfUnknown();
            return repoResource;
        }
        try {
            completeSchemaAndCapabilities(repoResource, resourceSchema, fetchedSchema, capabilityMap, task, result);
        } catch (Exception ex) {
            // Catch the exceptions. There are not critical. We need to catch them all because the connector may
            // throw even undocumented runtime exceptions.
            // Even non-complete resource may still be usable. The fetchResult indicates that there was an error
            result.recordPartialError("Cannot complete resource schema and capabilities: " + ex.getMessage(), ex);
            return repoResource;
        }
        try {
            // Now we need to re-read the resource from the repository and re-aply the schemas. This ensures that we will
            // cache the correct version and that we avoid race conditions, etc.
            newResource = repositoryService.getObject(ResourceType.class, repoResource.getOid(), null, result);
            applyConnectorSchemaToResource(newResource, task, result);
        } catch (SchemaException e) {
            result.recordFatalError(e);
            throw e;
        } catch (ObjectNotFoundException e) {
            result.recordFatalError(e);
            throw e;
        } catch (RuntimeException e) {
            result.recordFatalError(e);
            throw e;
        }
    }
    try {
        // make sure it has parsed resource and refined schema. We are going to cache
        // it, so we want to cache it with the parsed schemas
        RefinedResourceSchemaImpl.getResourceSchema(newResource, prismContext);
        RefinedResourceSchemaImpl.getRefinedSchema(newResource);
    } catch (SchemaException e) {
        String message = "Schema error while processing schemaHandling section of " + newResource + ": " + e.getMessage();
        result.recordPartialError(message, e);
        LOGGER.warn(message, e);
        return newResource;
    } catch (RuntimeException e) {
        String message = "Unexpected error while processing schemaHandling section of " + newResource + ": " + e.getMessage();
        result.recordPartialError(message, e);
        LOGGER.warn(message, e);
        return newResource;
    }
    result.recordSuccessIfUnknown();
    return newResource;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SystemException(com.evolveum.midpoint.util.exception.SystemException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) TunnelException(com.evolveum.midpoint.util.exception.TunnelException)

Example 45 with ConfigurationException

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

the class ProvisioningServiceImpl method applyDefinition.

@Override
@SuppressWarnings("unchecked")
public <T extends ObjectType> void applyDefinition(PrismObject<T> object, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".applyDefinition");
    result.addParam(OperationResult.PARAM_OBJECT, object);
    result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
    try {
        if (ShadowType.class.isAssignableFrom(object.getCompileTimeClass())) {
            getShadowCache(Mode.STANDARD).applyDefinition((PrismObject<ShadowType>) object, result);
        } else if (ResourceType.class.isAssignableFrom(object.getCompileTimeClass())) {
            resourceManager.applyDefinition((PrismObject<ResourceType>) object, task, result);
        } else {
            throw new IllegalArgumentException("Could not apply definition to object type: " + object.getCompileTimeClass());
        }
        result.computeStatus();
        result.recordSuccessIfUnknown();
    } catch (ObjectNotFoundException | CommunicationException | ConfigurationException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
        throw e;
    } finally {
        result.cleanupResult();
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PrismObject(com.evolveum.midpoint.prism.PrismObject) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

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