Search in sources :

Example 96 with ConfigurationException

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

the class SchemaExceptionHandler method handleError.

@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, SecurityViolationException {
    if (!doDiscovery) {
        parentResult.recordFatalError(ex);
        if (ex instanceof SchemaException) {
            throw (SchemaException) ex;
        } else {
            throw new SchemaException(ex.getMessage(), ex);
        }
    }
    ObjectDelta delta = null;
    switch(op) {
        case ADD:
            delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
            break;
        case DELETE:
            delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
            break;
        case MODIFY:
            Collection<? extends ItemDelta> modifications = null;
            if (shadow.getObjectChange() != null) {
                ObjectDeltaType deltaType = shadow.getObjectChange();
                modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
            }
            delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.getClass(), prismContext);
            break;
    }
    if (op != FailedOperation.GET) {
        //			Task task = taskManager.createTaskInstance();
        ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, parentResult);
        changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
    }
    if (shadow.getOid() == null) {
        parentResult.recordFatalError("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
        throw new SchemaException("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
    }
    Collection<ItemDelta> modification = createAttemptModification(shadow, null);
    try {
        ConstraintsChecker.onShadowModifyOperation(modification);
        cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
    } catch (Exception e) {
    //this should not happen. But if it happens, we should return original exception
    //			throw new SchemaException("Schema violation during processing shadow: "
    //					+ ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
    }
    parentResult.recordFatalError("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
    throw new SchemaException("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException)

Example 97 with ConfigurationException

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

the class SecurityViolationHandler method handleError.

@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, SecurityViolationException {
    if (!doDiscovery) {
        parentResult.recordFatalError(ex);
        if (ex instanceof SecurityViolationException) {
            throw (SecurityViolationException) ex;
        } else {
            throw new SecurityViolationException(ex.getMessage(), ex);
        }
    }
    ObjectDelta delta = null;
    switch(op) {
        case ADD:
            delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
            break;
        case DELETE:
            delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
            break;
        case MODIFY:
            Collection<? extends ItemDelta> modifications = null;
            if (shadow.getObjectChange() != null) {
                ObjectDeltaType deltaType = shadow.getObjectChange();
                modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
            }
            delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.getClass(), prismContext);
            break;
    }
    if (op != FailedOperation.GET) {
        //		Task task = taskManager.createTaskInstance();
        ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, parentResult);
        changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
    }
    if (shadow.getOid() == null) {
        throw new SecurityViolationException("Security violation during processing shadow " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
    }
    Collection<ItemDelta> modification = createAttemptModification(shadow, null);
    try {
        ConstraintsChecker.onShadowModifyOperation(modification);
        cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
    } catch (Exception e) {
    //this should not happen. But if it happens, we should return original exception
    }
    throw new SecurityViolationException("Security violation during processing shadow " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException)

Example 98 with ConfigurationException

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

the class ConnectorManager method createConfiguredConnectorInstance.

private ConnectorInstance createConfiguredConnectorInstance(ConnectorSpec connectorSpec, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException {
    ConnectorType connectorType = getConnectorTypeReadOnly(connectorSpec, result);
    ConnectorFactory connectorFactory = determineConnectorFactory(connectorType);
    ConnectorInstance connector = null;
    try {
        connector = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(connectorSpec.getResource()), connectorSpec.toString());
    } catch (ObjectNotFoundException e) {
        result.recordFatalError(e.getMessage(), e);
        throw new ObjectNotFoundException(e.getMessage(), e);
    }
    PrismContainerValue<ConnectorConfigurationType> connectorConfigurationVal = connectorSpec.getConnectorConfiguration().getValue();
    if (connectorConfigurationVal == null) {
        SchemaException e = new SchemaException("No connector configuration in " + connectorSpec);
        result.recordFatalError(e);
        throw e;
    }
    try {
        connector.configure(connectorConfigurationVal, result);
        ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(connectorSpec.getResource(), prismContext);
        Collection<Object> capabilities = ResourceTypeUtil.getNativeCapabilitiesCollection(connectorSpec.getResource().asObjectable());
        connector.initialize(resourceSchema, capabilities, ResourceTypeUtil.isCaseIgnoreAttributeNames(connectorSpec.getResource().asObjectable()), result);
        InternalMonitor.recordConnectorInstanceInitialization();
    } catch (GenericFrameworkException e) {
        // Not expected. Transform to system exception
        result.recordFatalError("Generic provisioning framework error", e);
        throw new SystemException("Generic provisioning framework error: " + e.getMessage(), e);
    } catch (CommunicationException e) {
        result.recordFatalError(e);
        throw e;
    } catch (ConfigurationException e) {
        result.recordFatalError(e);
        throw e;
    }
    // This log message should be INFO level. It happens only occasionally.
    // If it happens often, it may be an
    // indication of a problem. Therefore it is good for admin to see it.
    LOGGER.info("Created new connector instance for {}: {} v{}", connectorSpec, connectorType.getConnectorType(), connectorType.getConnectorVersion());
    return connector;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) ConnectorFactory(com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 99 with ConfigurationException

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

the class AbstractSearchExpressionEvaluator method createOnDemand.

private <O extends ObjectType> String createOnDemand(Class<O> targetTypeClass, ExpressionVariables variables, ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Going to create assignment targets on demand, variables:\n{}", variables.formatVariables());
    }
    PrismObjectDefinition<O> objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(targetTypeClass);
    PrismObject<O> newObject = objectDefinition.instantiate();
    PopulateType populateObject = getExpressionEvaluatorType().getPopulateObject();
    if (populateObject == null) {
        LOGGER.warn("No populateObject in assignment expression in {}, " + "object created on demand will be empty. Subsequent operations will most likely fail", contextDescription);
    } else {
        for (PopulateItemType populateItem : populateObject.getPopulateItem()) {
            ItemDelta<?, ?> itemDelta = evaluatePopulateExpression(populateItem, variables, params, objectDefinition, contextDescription, true, task, result);
            if (itemDelta != null) {
                itemDelta.applyTo(newObject);
            }
        }
    }
    LOGGER.debug("Creating object on demand from {}: {}", contextDescription, newObject);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Creating object on demand:\n{}", newObject.debugDump());
    }
    ObjectDelta<O> addDelta = newObject.createAddDelta();
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(addDelta);
    try {
        modelService.executeChanges(deltas, null, task, result);
    } catch (ObjectAlreadyExistsException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) {
        throw new ExpressionEvaluationException(e.getMessage(), e);
    }
    return addDelta.getOid();
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) PopulateItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateItemType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PopulateType(com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateType)

Example 100 with ConfigurationException

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

the class ModelUtils method determineObjectPolicyConfiguration.

public static <O extends ObjectType> ObjectPolicyConfigurationType determineObjectPolicyConfiguration(Class<O> objectClass, List<String> objectSubtypes, SystemConfigurationType systemConfigurationType) throws ConfigurationException {
    ObjectPolicyConfigurationType applicablePolicyConfigurationType = null;
    for (ObjectPolicyConfigurationType aPolicyConfigurationType : systemConfigurationType.getDefaultObjectPolicyConfiguration()) {
        QName typeQName = aPolicyConfigurationType.getType();
        ObjectTypes objectType = ObjectTypes.getObjectTypeFromTypeQName(typeQName);
        if (objectType == null) {
            throw new ConfigurationException("Unknown type " + typeQName + " in default object policy definition in system configuration");
        }
        if (objectType.getClassDefinition() == objectClass) {
            String aSubType = aPolicyConfigurationType.getSubtype();
            if (aSubType == null) {
                if (applicablePolicyConfigurationType == null) {
                    applicablePolicyConfigurationType = aPolicyConfigurationType;
                }
            } else if (objectSubtypes != null && objectSubtypes.contains(aSubType)) {
                applicablePolicyConfigurationType = aPolicyConfigurationType;
            }
        }
    }
    if (applicablePolicyConfigurationType != null) {
        return applicablePolicyConfigurationType;
    }
    // Deprecated
    for (ObjectPolicyConfigurationType aPolicyConfigurationType : systemConfigurationType.getObjectTemplate()) {
        QName typeQName = aPolicyConfigurationType.getType();
        ObjectTypes objectType = ObjectTypes.getObjectTypeFromTypeQName(typeQName);
        if (objectType == null) {
            throw new ConfigurationException("Unknown type " + typeQName + " in object template definition in system configuration");
        }
        if (objectType.getClassDefinition() == objectClass) {
            return aPolicyConfigurationType;
        }
    }
    // Deprecated method to specify user template. For compatibility only
    if (objectClass == UserType.class) {
        ObjectReferenceType templateRef = systemConfigurationType.getDefaultUserTemplateRef();
        if (templateRef == null) {
            return null;
        }
        ObjectPolicyConfigurationType policy = new ObjectPolicyConfigurationType();
        policy.setObjectTemplateRef(templateRef.clone());
        return policy;
    }
    return null;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectPolicyConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectPolicyConfigurationType) QName(javax.xml.namespace.QName) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes)

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