Search in sources :

Example 16 with ObjectDeltaType

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

the class ShadowManager method addPendingOperationDelta.

private void addPendingOperationDelta(ProvisioningContext ctx, PrismObject<ShadowType> shadow, ObjectDelta<ShadowType> pendingDelta, OperationResult resourceOperationResult, OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
    ObjectDeltaType pendingDeltaType = DeltaConvertor.toObjectDeltaType(pendingDelta);
    PendingOperationType pendingOperation = new PendingOperationType();
    pendingOperation.setDelta(pendingDeltaType);
    pendingOperation.setRequestTimestamp(clock.currentTimeXMLGregorianCalendar());
    pendingOperation.setResultStatus(OperationResultStatusType.IN_PROGRESS);
    pendingOperation.setAsynchronousOperationReference(resourceOperationResult.getAsynchronousOperationReference());
    Collection repoDeltas = new ArrayList<>(1);
    ContainerDelta<PendingOperationType> cdelta = ContainerDelta.createDelta(ShadowType.F_PENDING_OPERATION, shadow.getDefinition());
    cdelta.addValuesToAdd(pendingOperation.asPrismContainerValue());
    repoDeltas.add(cdelta);
    try {
        repositoryService.modifyObject(ShadowType.class, shadow.getOid(), repoDeltas, parentResult);
    } catch (ObjectAlreadyExistsException ex) {
        throw new SystemException(ex);
    }
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 17 with ObjectDeltaType

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

the class TestSanityLegacy method test029ModifyAccountDjBadPath.

@Test
public void test029ModifyAccountDjBadPath() throws Exception {
    final String TEST_NAME = "test029ModifyAccountDjBadPath";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    assertNoRepoCache();
    ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_ACCOUNT_MODIFY_BAD_PATH_FILE, ObjectDeltaType.class);
    objectChange.setOid(accountShadowOidOpendj);
    OperationResultType result;
    try {
        // WHEN
        result = modifyObjectViaModelWS(objectChange);
        AssertJUnit.fail("Unexpected success");
    } catch (FaultMessage f) {
        // this is expected
        FaultType faultInfo = f.getFaultInfo();
        result = faultInfo.getOperationResult();
    }
    // THEN
    assertNoRepoCache();
    displayJaxb("modifyObject result:", result, SchemaConstants.C_RESULT);
    TestUtil.assertFailure(result);
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidOpendj, null, repoResult);
    repoResult.computeStatus();
    TestUtil.assertSuccess("getObject(repo) has failed", repoResult);
    display("repository shadow", repoShadow);
    AssertJUnit.assertNotNull(repoShadow);
    ShadowType repoShadowType = repoShadow.asObjectable();
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());
    // check attributes in the shadow: should be only identifiers (ICF UID)
    String uid = checkRepoShadow(repoShadow);
    // Check if LDAP account was updated
    Entry jackLdapEntry = assertOpenDJAccountJack(uid, "jack");
    OpenDJController.assertAttribute(jackLdapEntry, "roomNumber", "upperdeck");
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) 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) ObjectAlreadyExistsFaultType(com.evolveum.midpoint.xml.ns._public.common.fault_3.ObjectAlreadyExistsFaultType) FaultType(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 18 with ObjectDeltaType

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

the class TestSanityLegacy method test105ModifyAccount.

@Test
public void test105ModifyAccount() throws Exception {
    final String TEST_NAME = "test105ModifyAccount";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_ACCOUNT_MODIFY_ATTRS_FILE, ObjectDeltaType.class);
    objectChange.setOid(accountShadowOidGuybrushOpendj);
    // WHEN ObjectTypes.SHADOW.getTypeQName(), 
    OperationResultType result = modifyObjectViaModelWS(objectChange);
    Task task = taskManager.createTaskInstance();
    OperationResult parentResult = new OperationResult(TEST_NAME + "-get after first modify");
    PrismObject<ShadowType> shadow = modelService.getObject(ShadowType.class, accountShadowOidGuybrushOpendj, null, task, parentResult);
    assertNotNull("shadow must not be null", shadow);
    ShadowType shadowType = shadow.asObjectable();
    QName employeeTypeQName = new QName(resourceTypeOpenDjrepo.getNamespace(), "employeeType");
    ItemPath employeeTypePath = new ItemPath(ShadowType.F_ATTRIBUTES, employeeTypeQName);
    PrismProperty item = shadow.findProperty(employeeTypePath);
    PropertyDelta deleteDelta = new PropertyDelta(new ItemPath(ShadowType.F_ATTRIBUTES), item.getDefinition().getName(), item.getDefinition(), prismContext);
    //        PropertyDelta deleteDelta = PropertyDelta.createDelta(employeeTypePath, shadow.getDefinition());
    //        PrismPropertyValue valToDelte = new PrismPropertyValue("A");
    //        valToDelte.setParent(deleteDelta);
    Collection<PrismPropertyValue> values = item.getValues();
    for (PrismPropertyValue val : values) {
        if ("A".equals(val.getValue())) {
            deleteDelta.addValueToDelete(val.clone());
        }
    }
    ObjectDelta delta = new ObjectDelta(ShadowType.class, ChangeType.MODIFY, prismContext);
    delta.addModification(deleteDelta);
    delta.setOid(accountShadowOidGuybrushOpendj);
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    deltas.add(delta);
    LOGGER.info("-------->>EXECUTE DELETE MODIFICATION<<------------");
    modelService.executeChanges(deltas, null, task, parentResult);
    // THEN
    assertNoRepoCache();
    displayJaxb("modifyObject result", result, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("modifyObject has failed", result);
    // check if LDAP account was modified
    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");
    OpenDJController.assertAttribute(entry, "roomNumber", "captain's cabin");
    // Set by the role
    OpenDJController.assertAttribute(entry, "employeeType", "sailor");
    OpenDJController.assertAttribute(entry, "title", "Bloody Pirate", "Honorable Captain");
    OpenDJController.assertAttribute(entry, "carLicense", "C4PT41N");
    OpenDJController.assertAttribute(entry, "businessCategory", "loot", "murder", "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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) 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) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 19 with ObjectDeltaType

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

the class TestSanityLegacy method test013AddOpenDjAccountToUser.

/**
     * Add account to user. This should result in account provisioning. Check if
     * that happens in repo and in LDAP.
     */
@Test
public void test013AddOpenDjAccountToUser() throws Exception {
    final String TEST_NAME = "test013AddOpenDjAccountToUser";
    TestUtil.displayTestTile(TEST_NAME);
    try {
        // GIVEN
        checkRepoOpenDjResource();
        assertNoRepoCache();
        // IMPORTANT! SWITCHING OFF ASSIGNMENT ENFORCEMENT HERE!
        setAssignmentEnforcement(AssignmentPolicyEnforcementType.NONE);
        // This is not redundant. It checks that the previous command set the policy correctly
        assertSyncSettingsAssignmentPolicyEnforcement(AssignmentPolicyEnforcementType.NONE);
        ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_USER_MODIFY_ADD_ACCOUNT_OPENDJ_FILENAME, ObjectDeltaType.class);
        // WHEN
        TestUtil.displayWhen(TEST_NAME);
        OperationResultType result = modifyObjectViaModelWS(objectChange);
        // THEN
        TestUtil.displayThen(TEST_NAME);
        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);
        UserType repoUserType = repoUser.asObjectable();
        repoResult.computeStatus();
        TestUtil.assertSuccess("getObject has failed", repoResult);
        display("User (repository)", repoUser);
        List<ObjectReferenceType> accountRefs = repoUserType.getLinkRef();
        assertEquals("No accountRefs", 1, accountRefs.size());
        ObjectReferenceType accountRef = accountRefs.get(0);
        accountShadowOidOpendj = accountRef.getOid();
        assertFalse(accountShadowOidOpendj.isEmpty());
        // Check if shadow was created in the repo
        repoResult = new OperationResult("getObject");
        PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidOpendj, null, repoResult);
        ShadowType repoShadowType = repoShadow.asObjectable();
        repoResult.computeStatus();
        TestUtil.assertSuccess("getObject has failed", repoResult);
        display("Shadow (repository)", repoShadow);
        assertNotNull(repoShadowType);
        assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());
        assertNotNull("Shadow stored in repository has no name", repoShadowType.getName());
        // Check the "name" property, it should be set to DN, not entryUUID
        assertEquals("Wrong name property", USER_JACK_LDAP_DN.toLowerCase(), repoShadowType.getName().getOrig().toLowerCase());
        // check attributes in the shadow: should be only identifiers (ICF UID)
        String uid = checkRepoShadow(repoShadow);
        // check if account was created in LDAP
        Entry entry = openDJController.searchAndAssertByEntryUuid(uid);
        display("LDAP account", entry);
        OpenDJController.assertAttribute(entry, "uid", "jack");
        OpenDJController.assertAttribute(entry, "givenName", "Jack");
        OpenDJController.assertAttribute(entry, "sn", "Sparrow");
        OpenDJController.assertAttribute(entry, "cn", "Jack Sparrow");
        OpenDJController.assertAttribute(entry, "displayName", "Jack Sparrow");
        // The "l" attribute is assigned indirectly through schemaHandling and
        // config object
        OpenDJController.assertAttribute(entry, "l", "Black Pearl");
        assertTrue("LDAP account is not enabled", openDJController.isAccountEnabled(entry));
        originalJacksLdapPassword = OpenDJController.getAttributeValue(entry, "userPassword");
        assertNotNull("Pasword was not set on create", originalJacksLdapPassword);
        System.out.println("password after create: " + originalJacksLdapPassword);
        // Use getObject to test fetch of complete shadow
        assertNoRepoCache();
        Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
        Holder<ObjectType> objectHolder = new Holder<ObjectType>();
        SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
        // 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", "Jack Sparrow");
        assertAttribute(resourceTypeOpenDjrepo, modelShadow, "displayName", "Jack Sparrow");
        assertAttribute(resourceTypeOpenDjrepo, modelShadow, "l", "Black Pearl");
        assertNull("carLicense attribute sneaked to LDAP", OpenDJController.getAttributeValue(entry, "carLicense"));
        assertNull("postalAddress attribute sneaked to LDAP", OpenDJController.getAttributeValue(entry, "postalAddress"));
        assertNotNull("Activation is null (model)", modelShadow.getActivation());
        assertEquals("Wrong administrativeStatus in the shadow (model)", ActivationStatusType.ENABLED, modelShadow.getActivation().getAdministrativeStatus());
    } catch (Exception ex) {
        LOGGER.info("ERROR: {}", ex);
        throw ex;
    }
}
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) JAXBException(javax.xml.bind.JAXBException) TaskManagerException(com.evolveum.midpoint.task.api.TaskManagerException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) 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) 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) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 20 with ObjectDeltaType

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

the class TestSanityLegacy method addObjectViaModelWS.

private void addObjectViaModelWS(ObjectType objectType, ModelExecuteOptionsType options, Holder<String> oidHolder, Holder<OperationResultType> resultHolder) throws FaultMessage {
    ObjectDeltaListType deltaList = new ObjectDeltaListType();
    ObjectDeltaType objectDelta = new ObjectDeltaType();
    objectDelta.setObjectToAdd(objectType);
    QName type = objectType.asPrismObject().getDefinition().getTypeName();
    objectDelta.setObjectType(type);
    objectDelta.setChangeType(ChangeTypeType.ADD);
    deltaList.getDelta().add(objectDelta);
    ObjectDeltaOperationListType objectDeltaOperationListType = modelWeb.executeChanges(deltaList, options);
    ObjectDeltaOperationType objectDeltaOperationType = getOdoFromDeltaOperationList(objectDeltaOperationListType, objectDelta);
    resultHolder.value = objectDeltaOperationType.getExecutionResult();
    oidHolder.value = ((ObjectType) objectDeltaOperationType.getObjectDelta().getObjectToAdd()).getOid();
}
Also used : ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) QName(javax.xml.namespace.QName) ObjectDeltaOperationListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType) ObjectDeltaListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)

Aggregations

ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)165 Test (org.testng.annotations.Test)54 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)44 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 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)33 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)30 ChangeRecordEntry (org.opends.server.util.ChangeRecordEntry)30 ObjectDeltaOperationListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)23 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)21 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)18 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)18 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)17 QName (javax.xml.namespace.QName)16 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)15 SystemException (com.evolveum.midpoint.util.exception.SystemException)13