Search in sources :

Example 51 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class TestSanityLegacy method test030DisableUser.

/**
     * Try to disable user. As the user has an account, the account should be disabled as well.
     */
@Test
public void test030DisableUser() throws Exception {
    final String TEST_NAME = "test030DisableUser";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_USER_MODIFY_ACTIVATION_DISABLE_FILENAME, ObjectDeltaType.class);
    Entry entry = openDJController.searchByUid("jack");
    assertOpenDJAccountJack(entry, "jack");
    String pwpAccountDisabled = OpenDJController.getAttributeValue(entry, "ds-pwp-account-disabled");
    display("ds-pwp-account-disabled before change", pwpAccountDisabled);
    assertTrue("LDAP account is not enabled (precondition)", openDJController.isAccountEnabled(entry));
    assertNoRepoCache();
    // WHEN ObjectTypes.USER.getTypeQName(), 
    OperationResultType result = modifyObjectViaModelWS(objectChange);
    // THEN
    assertNoRepoCache();
    displayJaxb("modifyObject result:", result, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("modifyObject has failed", result);
    // Check if user object was modified in the repo
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<UserType> repoUser = repositoryService.getObject(UserType.class, USER_JACK_OID, null, repoResult);
    display("repository user", repoUser);
    UserType repoUserType = repoUser.asObjectable();
    // Check if nothing else was modified
    assertEqualsPolyString("wrong repo fullName", "Cpt. Jack Sparrow", repoUserType.getFullName());
    assertEqualsPolyString("wrong repo locality", "somewhere", repoUserType.getLocality());
    // Check if appropriate accountRef is still there
    List<ObjectReferenceType> accountRefs = repoUserType.getLinkRef();
    assertEquals(1, accountRefs.size());
    for (ObjectReferenceType accountRef : accountRefs) {
        assertTrue("No OID in " + accountRef + " in " + repoUserType, accountRef.getOid().equals(accountShadowOidOpendj));
    }
    // Check if shadow is still in the repo and that it is untouched
    repoResult = new OperationResult("getObject");
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidOpendj, null, repoResult);
    display("repo shadow", repoShadow);
    ShadowType repoShadowType = repoShadow.asObjectable();
    repoResult.computeStatus();
    TestUtil.assertSuccess("getObject(repo) has failed", repoResult);
    AssertJUnit.assertNotNull(repoShadowType);
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());
    // check attributes in the shadow: should be only identifiers (ICF UID)
    String uid = checkRepoShadow(repoShadow);
    // Use getObject to test fetch of complete shadow
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    assertNoRepoCache();
    // WHEN
    modelWeb.getObject(ObjectTypes.SHADOW.getTypeQName(), accountShadowOidOpendj, options, objectHolder, resultHolder);
    // THEN
    assertNoRepoCache();
    displayJaxb("getObject result", resultHolder.value, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("getObject has failed", resultHolder.value);
    ShadowType modelShadow = (ShadowType) objectHolder.value;
    display("Shadow (model)", modelShadow);
    AssertJUnit.assertNotNull(modelShadow);
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, modelShadow.getResourceRef().getOid());
    assertAttributeNotNull(modelShadow, SchemaConstants.ICFS_UID);
    assertAttribute(resourceTypeOpenDjrepo, modelShadow, "uid", "jack");
    assertAttribute(resourceTypeOpenDjrepo, modelShadow, "givenName", "Jack");
    assertAttribute(resourceTypeOpenDjrepo, modelShadow, "sn", "Sparrow");
    assertAttribute(resourceTypeOpenDjrepo, modelShadow, "cn", "Cpt. Jack Sparrow");
    assertAttribute(resourceTypeOpenDjrepo, modelShadow, "displayName", "Cpt. Jack Sparrow");
    assertAttribute(resourceTypeOpenDjrepo, modelShadow, "l", "somewhere");
    assertNotNull("The account activation is null in the shadow", modelShadow.getActivation());
    assertNotNull("The account activation status was not present in shadow", modelShadow.getActivation().getAdministrativeStatus());
    assertEquals("The account was not disabled in the shadow", ActivationStatusType.DISABLED, modelShadow.getActivation().getAdministrativeStatus());
    // Check if LDAP account was updated
    entry = openDJController.searchAndAssertByEntryUuid(uid);
    assertOpenDJAccountJack(entry, "jack");
    pwpAccountDisabled = OpenDJController.getAttributeValue(entry, "ds-pwp-account-disabled");
    display("ds-pwp-account-disabled after change", pwpAccountDisabled);
    assertFalse("LDAP account was not disabled", openDJController.isAccountEnabled(entry));
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Holder(javax.xml.ws.Holder) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GenericObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 52 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class TestSanityLegacy method test107UnassignRolePirate.

@Test
public void test107UnassignRolePirate() throws Exception {
    final String TEST_NAME = "test107UnassignRolePirate";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResultType result = new OperationResultType();
    assertNoRepoCache();
    ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_USER_MODIFY_DELETE_ROLE_PIRATE_FILENAME, ObjectDeltaType.class);
    // WHEN ObjectTypes.USER.getTypeQName(), 
    result = modifyObjectViaModelWS(objectChange);
    // THEN
    assertNoRepoCache();
    displayJaxb("modifyObject result", result, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("modifyObject has failed", result);
    // Check if user object was modified in the repo
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<UserType> repoUser = repositoryService.getObject(UserType.class, USER_GUYBRUSH_OID, null, repoResult);
    UserType repoUserType = repoUser.asObjectable();
    repoResult.computeStatus();
    display("User (repository)", repoUser);
    List<ObjectReferenceType> accountRefs = repoUserType.getLinkRef();
    assertEquals(1, accountRefs.size());
    ObjectReferenceType accountRef = accountRefs.get(0);
    assertEquals(accountShadowOidGuybrushOpendj, accountRef.getOid());
    // Check if shadow is still in the repo
    repoResult = new OperationResult("getObject");
    PrismObject<ShadowType> aObject = repositoryService.getObject(ShadowType.class, accountShadowOidGuybrushOpendj, null, repoResult);
    ShadowType repoShadow = aObject.asObjectable();
    repoResult.computeStatus();
    TestUtil.assertSuccess("getObject has failed", repoResult);
    display("Shadow (repository)", repoShadow);
    assertNotNull(repoShadow);
    assertEquals(RESOURCE_OPENDJ_OID, repoShadow.getResourceRef().getOid());
    // check if account is still in LDAP
    Entry entry = openDJController.searchAndAssertByEntryUuid(accountGuybrushOpendjEntryUuuid);
    display("LDAP account", entry);
    OpenDJController.assertAttribute(entry, "uid", "guybrush");
    OpenDJController.assertAttribute(entry, "givenName", "Guybrush");
    OpenDJController.assertAttribute(entry, "sn", "Threepwood");
    OpenDJController.assertAttribute(entry, "cn", "Guybrush Threepwood");
    OpenDJController.assertAttribute(entry, "displayName", "Guybrush Threepwood");
    // The "l" attribute is assigned indirectly through schemaHandling and
    // config object
    OpenDJController.assertAttribute(entry, "l", "Deep in the Caribbean");
    // Set by the role
    OpenDJController.assertAttribute(entry, "employeeType", "sailor");
    OpenDJController.assertAttribute(entry, "title", "Honorable Captain");
    OpenDJController.assertAttribute(entry, "carLicense", "C4PT41N");
    OpenDJController.assertAttribute(entry, "businessCategory", "cruise", "fighting", "capsize");
    // Expression in the role taking that from the user
    OpenDJController.assertAttribute(entry, "destinationIndicator", "Guybrush Threepwood");
    OpenDJController.assertAttribute(entry, "departmentNumber", "Department of Guybrush");
    // Expression in the role taking that from the assignments (both of them)
    OpenDJController.assertAttribute(entry, "physicalDeliveryOfficeName", "The Sea Monkey", "The Dainty Lady");
    String guybrushPassword = OpenDJController.getAttributeValue(entry, "userPassword");
    assertNotNull("Pasword disappeared", guybrushPassword);
// TODO: Derby        
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 53 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class TestSanityLegacy method test109UnassignRoleCaptainAgain.

/**
     * Captain role was assigned twice. It has to also be unassigned twice.
     */
@Test
public void test109UnassignRoleCaptainAgain() throws Exception {
    final String TEST_NAME = "test109UnassignRoleCaptainAgain";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResultType result = new OperationResultType();
    assertNoRepoCache();
    ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_USER_MODIFY_DELETE_ROLE_CAPTAIN_2_FILENAME, ObjectDeltaType.class);
    // WHEN ObjectTypes.USER.getTypeQName(), 
    result = modifyObjectViaModelWS(objectChange);
    // THEN
    assertNoRepoCache();
    displayJaxb("modifyObject result", result, SchemaConstants.C_RESULT);
    //TODO TODO TODO TODO operation result from repostiory.getObject is unknown...find out why..
    //        assertSuccess("modifyObject has failed", result);
    // Check if user object was modified in the repo
    OperationResult repoResult = new OperationResult("getObject");
    PropertyReferenceListType resolve = new PropertyReferenceListType();
    PrismObject<UserType> repoUser = repositoryService.getObject(UserType.class, USER_GUYBRUSH_OID, null, repoResult);
    UserType repoUserType = repoUser.asObjectable();
    repoResult.computeStatus();
    display("User (repository)", repoUserType);
    List<ObjectReferenceType> accountRefs = repoUserType.getLinkRef();
    assertEquals(0, accountRefs.size());
    // Check if shadow was deleted from the repo
    repoResult = new OperationResult("getObject");
    try {
        PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidGuybrushOpendj, null, repoResult);
        AssertJUnit.fail("Account shadow was not deleted from repo");
    } catch (ObjectNotFoundException ex) {
    // This is expected
    }
    // check if account was deleted from LDAP
    Entry entry = openDJController.searchByEntryUuid(accountGuybrushOpendjEntryUuuid);
    display("LDAP account", entry);
    assertNull("LDAP account was not deleted", entry);
// TODO: Derby
}
Also used : PropertyReferenceListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.PropertyReferenceListType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 54 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class ObjectNotFoundHandler 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, ExpressionEvaluationException {
    if (!doDiscovery) {
        parentResult.recordFatalError(ex);
        if (ex instanceof ObjectNotFoundException) {
            throw (ObjectNotFoundException) ex;
        } else {
            throw new ObjectNotFoundException(ex.getMessage(), ex);
        }
    }
    OperationResult result = parentResult.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.ObjectNotFoundHandler.handleError." + op.name());
    result.addParam("shadow", shadow);
    result.addParam("currentOperation", op);
    if (ex.getMessage() != null) {
        result.addParam("exception", ex.getMessage());
    }
    LOGGER.trace("Start compensating object not found situation while execution operation: {}", op.name(), ex);
    //		Task task = taskManager.createTaskInstance();
    ObjectDelta delta = null;
    switch(op) {
        case DELETE:
            LOGGER.debug("DISCOVERY: cannot find object {}. The operation in progress is DELETE, therefore just deleting the shadow", shadow);
            LOGGER.trace("Deleting shadow from the repository.");
            for (OperationResult subResult : parentResult.getSubresults()) {
                subResult.muteError();
            }
            try {
                cacheRepositoryService.deleteObject(ShadowType.class, shadow.getOid(), result);
            } catch (ObjectNotFoundException e) {
                LOGGER.debug("Cannot delete {} in consistency compensation (discovery): {} - this is probably harmless", shadow, e.getMessage());
            }
            String message = "Object was not found on the " + ObjectTypeUtil.toShortString(shadow.getResource()) + ". Shadow deleted from the repository to equalize the state on the resource and in the repository.";
            parentResult.recordHandledError(message);
            LOGGER.trace("Shadow deleted from the repository. Inconsistencies are now removed.");
            result.computeStatus();
            // parentResult status can be recomputed by the caller method
            result.setStatus(OperationResultStatus.HANDLED_ERROR);
            delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
            ResourceOperationDescription operationDescritpion = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, result);
            changeNotificationDispatcher.notifySuccess(operationDescritpion, task, result);
            LOGGER.debug("DISCOVERY: cannot find object {}: DELETE operation handler done", shadow);
            return shadow;
        case MODIFY:
            LOGGER.debug("DISCOVERY: cannot find object {}. The operation in progress is MODIFY, therefore initiating synchronization", shadow);
            LOGGER.trace("Starting discovery to find out if the object should exist or not.");
            OperationResult handleErrorResult = result.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.ObjectNotFoundHandler.handleError.discovery");
            handleErrorResult.addContext(OperationResult.CONTEXT_RESOURCE, shadow.getResource());
            ObjectDeltaType shadowModifications = shadow.getObjectChange();
            Collection<? extends ItemDelta> modifications = DeltaConvertor.toModifications(shadowModifications.getItemDelta(), shadow.asPrismObject().getDefinition());
            shadow.setDead(true);
            Collection<? extends ItemDelta> deadDeltas = PropertyDelta.createModificationReplacePropertyCollection(ShadowType.F_DEAD, shadow.asPrismObject().getDefinition(), true);
            ConstraintsChecker.onShadowModifyOperation(deadDeltas);
            cacheRepositoryService.modifyObject(ShadowType.class, shadow.getOid(), deadDeltas, result);
            ResourceObjectShadowChangeDescription change = createResourceObjectShadowChangeDescription(shadow, result);
            try {
                changeNotificationDispatcher.notifyChange(change, task, handleErrorResult);
            } catch (RuntimeException e) {
                handleErrorResult.recordFatalError(e);
                result.computeStatus();
                throw e;
            }
            handleErrorResult.computeStatus();
            String oidVal = null;
            String oid = findCreatedAccountOid(handleErrorResult, oidVal);
            if (oid != null) {
                LOGGER.trace("Found new oid {} as a return param from model. Probably the new shadow was created.", oid);
                LOGGER.debug("DISCOVERY: object {} re-created, applying pending changes", shadow);
                LOGGER.trace("Modifying re-created object by applying pending changes:\n{}", DebugUtil.debugDump(modifications));
                try {
                    ProvisioningOperationOptions options = new ProvisioningOperationOptions();
                    options.setCompletePostponed(false);
                    options.setDoNotDiscovery(true);
                    provisioningService.modifyObject(ShadowType.class, oid, modifications, null, options, task, result);
                    parentResult.recordHandledError("Object was recreated and modifications were applied to newly created object.");
                } catch (ObjectNotFoundException e) {
                    parentResult.recordHandledError("Modifications were not applied, because shadow was deleted by discovery. Repository state were refreshed and unused shadow was deleted.");
                }
            } else {
                LOGGER.debug("DISCOVERY: object {} deleted, application of pending changes skipped", shadow);
                parentResult.recordHandledError("Object was deleted by discovery. Modification were not applied.");
            }
            // We do not need the old shadow any more. Even if the object was re-created it has a new shadow now.
            try {
                cacheRepositoryService.deleteObject(ShadowType.class, shadow.getOid(), parentResult);
            } catch (ObjectNotFoundException e) {
                // delete the old shadow that was probably deleted from the
                // user, or the new one was assigned
                LOGGER.debug("Cannot delete {} in consistency compensation (discovery): {} - this is probably harmless", shadow, e.getMessage());
            }
            result.computeStatus();
            if (parentResult.isHandledError()) {
                // Ugly hack. We shouldn't set parentResult status in the first place, as it can be overriden by computeStatus/recomputeStatus called in the parent.
                result.setStatus(OperationResultStatus.HANDLED_ERROR);
            }
            if (oid != null) {
                shadowModifications.setOid(oid);
                shadow.setOid(oid);
            }
            LOGGER.debug("DISCOVERY: cannot find object {}: MODIFY operation handler done", shadow);
            return shadow;
        case GET:
            if (!compensate) {
                LOGGER.trace("DISCOVERY: cannot find object {}, GET operation: handling skipped because discovery is disabled", shadow);
                result.recordFatalError(ex.getMessage(), ex);
                throw new ObjectNotFoundException(ex.getMessage(), ex);
            }
            LOGGER.debug("DISCOVERY: cannot find object {}. The operation in progress is GET, therefore initiating synchronization", shadow);
            OperationResult handleGetErrorResult = result.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.ObjectNotFoundHandler.handleError.discovery");
            handleGetErrorResult.addContext(OperationResult.CONTEXT_RESOURCE, shadow.getResource());
            Collection<? extends ItemDelta> deadModification = PropertyDelta.createModificationReplacePropertyCollection(ShadowType.F_DEAD, shadow.asPrismObject().getDefinition(), true);
            ConstraintsChecker.onShadowModifyOperation(deadModification);
            try {
                cacheRepositoryService.modifyObject(ShadowType.class, shadow.getOid(), deadModification, result);
            } catch (ObjectNotFoundException e) {
                // The shadow is not there. So we cannot mark it as dead.
                LOGGER.debug("Cannot modify shadow {} in consistency compensation (discovery): {} - this is probably harmless", shadow, e.getMessage());
            }
            shadow.setDead(true);
            ResourceObjectShadowChangeDescription getChange = createResourceObjectShadowChangeDescription(shadow, result);
            if (task == null) {
                task = taskManager.createTaskInstance();
            }
            try {
                changeNotificationDispatcher.notifyChange(getChange, task, handleGetErrorResult);
            } catch (RuntimeException e) {
                LOGGER.trace("DISCOVERY: synchronization invoked for  {} ended with an error {}", shadow, e);
                handleGetErrorResult.recordFatalError(e);
                result.computeStatus();
                throw e;
            }
            // String oidVal = null;
            handleGetErrorResult.computeStatus();
            LOGGER.trace("DISCOVERY: synchronization invoked for  {} finished with status {}", shadow, handleGetErrorResult.getStatus());
            oid = findCreatedAccountOid(handleGetErrorResult, null);
            try {
                LOGGER.trace("DISCOVERY: deleting  {}", shadow);
                cacheRepositoryService.deleteObject(ShadowType.class, shadow.getOid(), result);
            } catch (ObjectNotFoundException e) {
                // delete the old shadow that was probably deleted from the
                // user, or the new one was assigned
                LOGGER.debug("Cannot delete {} in consistency compensation (discovery): {} - this is probably harmless", shadow, e.getMessage());
            }
            for (OperationResult subResult : parentResult.getSubresults()) {
                subResult.muteError();
            }
            if (oid != null) {
                PrismObject newShadow;
                try {
                    LOGGER.trace("DISCOVERY: retrieving shadow  {}", oid);
                    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createDoNotDiscovery());
                    newShadow = provisioningService.getObject(shadow.getClass(), oid, options, task, result);
                    LOGGER.trace("DISCOVERY: retrieved {}", newShadow);
                } catch (ObjectNotFoundException e) {
                    String msg = "Strange thing did happen: new shadow (" + oid + ") was supposedly created for old shadow " + shadow + ", however the new shadow was not found: " + e.getMessage();
                    LOGGER.error(msg);
                    result.recordFatalError(msg, e);
                    parentResult.recordFatalError(msg);
                    throw new ObjectNotFoundException(msg, ex);
                } finally {
                    result.computeStatus();
                }
                LOGGER.debug("DISCOVERY: object {} re-created as {}. GET operation handler done: returning new shadow", shadow, newShadow);
                shadow = (T) newShadow.asObjectable();
                parentResult.recordHandledError("Object was re-created by the discovery.");
                // parentResult status can be recomputed by the caller method
                result.setStatus(OperationResultStatus.HANDLED_ERROR);
                return shadow;
            } else {
                parentResult.recordHandledError("Object was deleted by the discovery and the invalid link was removed from the user.");
                result.computeStatus();
                // parentResult status can be recomputed by the caller method
                result.setStatus(OperationResultStatus.HANDLED_ERROR);
                LOGGER.debug("DISCOVERY: object {} was deleted. GET operation handler done: throwing ObjectNotFoundException", shadow);
                throw new ObjectNotFoundException(ex.getMessage(), ex);
            }
        default:
            throw new ObjectNotFoundException(ex.getMessage(), ex);
    }
}
Also used : ProvisioningOperationOptions(com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) PrismObject(com.evolveum.midpoint.prism.PrismObject) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 55 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class ConsistencyTest method test124AddAccountDirectAlreadyExists.

//MID-1595, MID-1577
@Test
public void test124AddAccountDirectAlreadyExists() throws Exception {
    final String TEST_NAME = "test124AddAccountDirectAlreadyExists";
    TestUtil.displayTestTile(TEST_NAME);
    OperationResult parentResult = new OperationResult(TEST_NAME);
    Task task = taskManager.createTaskInstance();
    SchemaHandlingType oldSchemaHandling = resourceTypeOpenDjrepo.getSchemaHandling();
    SynchronizationType oldSynchronization = resourceTypeOpenDjrepo.getSynchronization();
    try {
        // we will reapply this schema handling after this test finish
        ItemDefinition syncDef = resourceTypeOpenDjrepo.asPrismObject().getDefinition().findItemDefinition(ResourceType.F_SYNCHRONIZATION);
        assertNotNull("null definition for sync delta", syncDef);
        ObjectDeltaType omt = unmarshallValueFromFile(REQUEST_RESOURCE_MODIFY_SYNCHRONIZATION, ObjectDeltaType.class);
        ObjectDelta objectDelta = DeltaConvertor.createObjectDelta(omt, prismContext);
        repositoryService.modifyObject(ResourceType.class, RESOURCE_OPENDJ_OID, objectDelta.getModifications(), parentResult);
        requestToExecuteChanges(REQUEST_RESOURCE_MODIFY_RESOURCE_SCHEMA, RESOURCE_OPENDJ_OID, ResourceType.class, task, null, parentResult);
        PrismObject<ResourceType> res = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, parentResult);
        // LOGGER.trace("resource schema handling after modify: {}",
        // prismContext.silentMarshalObject(res.asObjectable(), LOGGER));
        repoAddObjectFromFile(USER_ABOMBA_FILENAME, parentResult);
        requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOMBA_OID, UserType.class, task, null, parentResult);
        String abombaOid = assertUserOneAccountRef(USER_ABOMBA_OID);
        ShadowType abombaShadow = repositoryService.getObject(ShadowType.class, abombaOid, null, parentResult).asObjectable();
        assertShadowName(abombaShadow, "uid=abomba,OU=people,DC=example,DC=com");
        repoAddObjectFromFile(USER_ABOM_FILENAME, parentResult);
        requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOM_OID, UserType.class, task, null, parentResult);
        String abomOid = assertUserOneAccountRef(USER_ABOM_OID);
        ShadowType abomShadow = repositoryService.getObject(ShadowType.class, abomOid, null, parentResult).asObjectable();
        assertShadowName(abomShadow, "uid=abomba1,OU=people,DC=example,DC=com");
        ReferenceDelta abombaDeleteAccDelta = ReferenceDelta.createModificationDelete(ShadowType.class, UserType.F_LINK_REF, prismContext, new PrismReferenceValue(abombaOid));
        ObjectDelta d = ObjectDelta.createModifyDelta(USER_ABOMBA_OID, abombaDeleteAccDelta, UserType.class, prismContext);
        modelService.executeChanges(MiscSchemaUtil.createCollection(d), null, task, parentResult);
        assertUserNoAccountRef(USER_ABOMBA_OID, parentResult);
        repositoryService.getObject(ShadowType.class, abombaOid, null, parentResult);
        ReferenceDelta abomDeleteAccDelta = ReferenceDelta.createModificationDelete(ShadowType.class, UserType.F_LINK_REF, prismContext, abomShadow.asPrismObject());
        ObjectDelta d2 = ObjectDelta.createModifyDelta(USER_ABOM_OID, abomDeleteAccDelta, UserType.class, prismContext);
        modelService.executeChanges(MiscSchemaUtil.createCollection(d2), null, task, parentResult);
        assertUserNoAccountRef(USER_ABOM_OID, parentResult);
        try {
            repositoryService.getObject(ShadowType.class, abomOid, null, parentResult);
            fail("Expected that shadow abom does not exist, but it is");
        } catch (ObjectNotFoundException ex) {
        // this is expected
        } catch (Exception ex) {
            fail("Expected object not found exception but got " + ex);
        }
        LOGGER.info("starting second execution request for user abomba");
        OperationResult result = new OperationResult("Add account already exist result.");
        requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOMBA_OID, UserType.class, task, null, result);
        String abombaOid2 = assertUserOneAccountRef(USER_ABOMBA_OID);
        ShadowType abombaShadow2 = repositoryService.getObject(ShadowType.class, abombaOid2, null, result).asObjectable();
        assertShadowName(abombaShadow2, "uid=abomba,OU=people,DC=example,DC=com");
        result.computeStatus();
        LOGGER.info("Displaying execute changes result");
        display(result);
        // return the previous changes of resource back
        Collection<? extends ItemDelta> schemaHandlingDelta = ContainerDelta.createModificationReplaceContainerCollection(ResourceType.F_SCHEMA_HANDLING, resourceTypeOpenDjrepo.asPrismObject().getDefinition(), oldSchemaHandling.asPrismContainerValue().clone());
        PropertyDelta syncDelta = PropertyDelta.createModificationReplaceProperty(ResourceType.F_SYNCHRONIZATION, resourceTypeOpenDjrepo.asPrismObject().getDefinition(), oldSynchronization);
        ((Collection) schemaHandlingDelta).add(syncDelta);
        repositoryService.modifyObject(ResourceType.class, RESOURCE_OPENDJ_OID, schemaHandlingDelta, parentResult);
    } catch (Exception ex) {
        LOGGER.info("error: " + ex.getMessage(), ex);
        throw ex;
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SchemaHandlingType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SystemException(com.evolveum.midpoint.util.exception.SystemException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) IOException(java.io.IOException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) JAXBException(javax.xml.bind.JAXBException) TaskManagerException(com.evolveum.midpoint.task.api.TaskManagerException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) SynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Aggregations

ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)136 Test (org.testng.annotations.Test)55 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)53 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)50 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)47 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)47 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)42 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)41 ObjectDeltaListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)37 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)30 ChangeRecordEntry (org.opends.server.util.ChangeRecordEntry)30 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)29 ObjectDeltaOperationListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)23 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)17 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)16 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)16 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)14 QName (javax.xml.namespace.QName)14 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)12