Search in sources :

Example 61 with ObjectNotFoundException

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

the class AbstractSecurityTest method assertDeleteDeny.

protected <O extends ObjectType> void assertDeleteDeny(Class<O> type, String oid, ModelExecuteOptions options) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    Task task = taskManager.createTaskInstance(AbstractSecurityTest.class.getName() + ".assertDeleteDeny");
    OperationResult result = task.getResult();
    ObjectDelta<O> delta = ObjectDelta.createDeleteDelta(type, oid, prismContext);
    try {
        logAttempt("delete", type, oid, null);
        modelService.executeChanges(MiscSchemaUtil.createCollection(delta), options, task, result);
        failDeny("delete", type, oid, null);
    } catch (SecurityViolationException e) {
        // this is expected
        logDeny("delete", type, oid, null);
        result.computeStatus();
        TestUtil.assertFailure(result);
    } catch (ObjectNotFoundException e) {
        // MID-3221
        // still consider OK ... for now
        logError("delete", type, oid, null);
        result.computeStatus();
        TestUtil.assertFailure(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 62 with ObjectNotFoundException

use of com.evolveum.midpoint.util.exception.ObjectNotFoundException 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)

Example 63 with ObjectNotFoundException

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

the class ResourceObjectReferenceResolver method resolve.

PrismObject<ShadowType> resolve(ProvisioningContext ctx, ResourceObjectReferenceType resourceObjectReference, QName objectClass, final String desc, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    if (resourceObjectReference == null) {
        return null;
    }
    ObjectReferenceType shadowRef = resourceObjectReference.getShadowRef();
    if (shadowRef != null && shadowRef.getOid() != null) {
        if (resourceObjectReference.getResolutionFrequency() == null || resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.ONCE) {
            PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, shadowRef.getOid(), null, result);
            return shadow;
        }
    } else if (resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.NEVER) {
        throw new ObjectNotFoundException("No shadowRef OID in " + desc + " and resolution frequency set to NEVER");
    }
    if (resourceObjectReference.getObjectClass() != null) {
        objectClass = resourceObjectReference.getObjectClass();
        if (objectClass.getNamespaceURI() == null) {
            objectClass = new QName(ResourceTypeUtil.getResourceNamespace(ctx.getResource()), objectClass.getLocalPart());
        }
    }
    ProvisioningContext subctx = ctx.spawn(objectClass);
    // Use "raw" definitions from the original schema to avoid endless loops
    subctx.setUseRefinedDefinition(false);
    subctx.assertDefinition();
    ObjectQuery refQuery = QueryJaxbConvertor.createObjectQuery(ShadowType.class, resourceObjectReference.getFilter(), prismContext);
    ObjectFilter baseFilter = ObjectQueryUtil.createResourceAndObjectClassFilter(ctx.getResource().getOid(), objectClass, prismContext);
    ObjectFilter filter = AndFilter.createAnd(baseFilter, refQuery.getFilter());
    ObjectQuery query = ObjectQuery.createObjectQuery(filter);
    // TODO: implement "repo" search strategies
    Collection<SelectorOptions<GetOperationOptions>> options = null;
    final Holder<ShadowType> shadowHolder = new Holder<>();
    ShadowHandler<ShadowType> handler = new ShadowHandler<ShadowType>() {

        @Override
        public boolean handle(ShadowType shadow) {
            if (shadowHolder.getValue() != null) {
                throw new IllegalStateException("More than one search results for " + desc);
            }
            shadowHolder.setValue(shadow);
            return true;
        }
    };
    shadowCache.searchObjectsIterative(subctx, query, options, handler, true, result);
    // TODO: implement storage of OID (ONCE search frequency)
    ShadowType shadowType = shadowHolder.getValue();
    return shadowType == null ? null : shadowType.asPrismObject();
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) Holder(com.evolveum.midpoint.util.Holder) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ResourceObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectReferenceType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 64 with ObjectNotFoundException

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

the class ShadowManager method findOrAddShadowFromChangeGlobalContext.

public PrismObject<ShadowType> findOrAddShadowFromChangeGlobalContext(ProvisioningContext globalCtx, Change change, OperationResult parentResult) throws SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ObjectNotFoundException, ExpressionEvaluationException {
    // Try to locate existing shadow in the repository
    List<PrismObject<ShadowType>> accountList = searchShadowByIdenifiers(globalCtx, change, parentResult);
    if (accountList.size() > 1) {
        String message = "Found more than one shadow with the identifier " + change.getIdentifiers() + ".";
        LOGGER.error(message);
        parentResult.recordFatalError(message);
        throw new IllegalArgumentException(message);
    }
    PrismObject<ShadowType> newShadow = null;
    if (accountList.isEmpty()) {
        if (change.getObjectDelta() == null || change.getObjectDelta().getChangeType() != ChangeType.DELETE) {
            newShadow = createNewShadowFromChange(globalCtx, change, parentResult);
            try {
                ConstraintsChecker.onShadowAddOperation(newShadow.asObjectable());
                String oid = repositoryService.addObject(newShadow, null, parentResult);
                newShadow.setOid(oid);
                if (change.getObjectDelta() != null && change.getObjectDelta().getOid() == null) {
                    change.getObjectDelta().setOid(oid);
                }
            } catch (ObjectAlreadyExistsException e) {
                parentResult.recordFatalError("Can't add " + SchemaDebugUtil.prettyPrint(newShadow) + " to the repository. Reason: " + e.getMessage(), e);
                throw new IllegalStateException(e.getMessage(), e);
            }
            LOGGER.debug("Added new shadow (from global change): {}", newShadow);
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Added new shadow (from global change):\n{}", newShadow.debugDump());
            }
        }
    } else {
        // Account was found in repository
        newShadow = accountList.get(0);
        if (change.getObjectDelta() != null && change.getObjectDelta().getChangeType() == ChangeType.DELETE) {
            Collection<? extends ItemDelta> deadDeltas = PropertyDelta.createModificationReplacePropertyCollection(ShadowType.F_DEAD, newShadow.getDefinition(), true);
            try {
                ConstraintsChecker.onShadowModifyOperation(deadDeltas);
                repositoryService.modifyObject(ShadowType.class, newShadow.getOid(), deadDeltas, parentResult);
            } catch (ObjectAlreadyExistsException e) {
                parentResult.recordFatalError("Can't add " + SchemaDebugUtil.prettyPrint(newShadow) + " to the repository. Reason: " + e.getMessage(), e);
                throw new IllegalStateException(e.getMessage(), e);
            } catch (ObjectNotFoundException e) {
                parentResult.recordWarning("Shadow " + SchemaDebugUtil.prettyPrint(newShadow) + " was probably deleted from the repository in the meantime. Exception: " + e.getMessage(), e);
                return null;
            }
        }
    }
    return newShadow;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 65 with ObjectNotFoundException

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

the class ShadowManager method findOrAddShadowFromChange.

// beware, may return null if an shadow that was to be marked as DEAD, was deleted in the meantime
public PrismObject<ShadowType> findOrAddShadowFromChange(ProvisioningContext ctx, Change change, OperationResult parentResult) throws SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ObjectNotFoundException, ExpressionEvaluationException {
    // Try to locate existing shadow in the repository
    List<PrismObject<ShadowType>> accountList = searchShadowByIdenifiers(ctx, change, parentResult);
    if (accountList.size() > 1) {
        String message = "Found more than one shadow with the identifier " + change.getIdentifiers() + ".";
        LOGGER.error(message);
        parentResult.recordFatalError(message);
        throw new IllegalArgumentException(message);
    }
    PrismObject<ShadowType> newShadow = null;
    if (accountList.isEmpty()) {
        if (change.getObjectDelta() == null || change.getObjectDelta().getChangeType() != ChangeType.DELETE) {
            newShadow = createNewShadowFromChange(ctx, change, parentResult);
            try {
                ConstraintsChecker.onShadowAddOperation(newShadow.asObjectable());
                String oid = repositoryService.addObject(newShadow, null, parentResult);
                newShadow.setOid(oid);
                if (change.getObjectDelta() != null && change.getObjectDelta().getOid() == null) {
                    change.getObjectDelta().setOid(oid);
                }
            } catch (ObjectAlreadyExistsException e) {
                parentResult.recordFatalError("Can't add " + SchemaDebugUtil.prettyPrint(newShadow) + " to the repository. Reason: " + e.getMessage(), e);
                throw new IllegalStateException(e.getMessage(), e);
            }
            LOGGER.debug("Added new shadow (from change): {}", newShadow);
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Added new shadow (from change):\n{}", newShadow.debugDump());
            }
        }
    } else {
        // Account was found in repository
        newShadow = accountList.get(0);
        if (change.getObjectDelta() != null && change.getObjectDelta().getChangeType() == ChangeType.DELETE) {
            Collection<? extends ItemDelta> deadDeltas = PropertyDelta.createModificationReplacePropertyCollection(ShadowType.F_DEAD, newShadow.getDefinition(), true);
            try {
                ConstraintsChecker.onShadowModifyOperation(deadDeltas);
                repositoryService.modifyObject(ShadowType.class, newShadow.getOid(), deadDeltas, parentResult);
            } catch (ObjectAlreadyExistsException e) {
                parentResult.recordFatalError("Can't add " + SchemaDebugUtil.prettyPrint(newShadow) + " to the repository. Reason: " + e.getMessage(), e);
                throw new IllegalStateException(e.getMessage(), e);
            } catch (ObjectNotFoundException e) {
                parentResult.recordWarning("Shadow " + SchemaDebugUtil.prettyPrint(newShadow) + " was probably deleted from the repository in the meantime. Exception: " + e.getMessage(), e);
                return null;
            }
        }
    }
    return newShadow;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Aggregations

ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)291 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)214 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)200 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)100 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)93 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)90 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)88 Task (com.evolveum.midpoint.task.api.Task)75 SystemException (com.evolveum.midpoint.util.exception.SystemException)71 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)64 PrismObject (com.evolveum.midpoint.prism.PrismObject)52 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)42 Test (org.testng.annotations.Test)40 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)38 ArrayList (java.util.ArrayList)35 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)33 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)32 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)30 QName (javax.xml.namespace.QName)29 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)28