Search in sources :

Example 76 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class CredentialsProcessor method transformFocusExectionDeltaCredential.

private <O extends ObjectType> void transformFocusExectionDeltaCredential(LensContext<O> context, CredentialsPolicyType credsType, CredentialPolicyType credPolicyType, ItemPath valuePropertyPath, ObjectDelta<O> delta) throws SchemaException, EncryptionException {
    if (delta.isDelete()) {
        return;
    }
    CredentialPolicyType defaltCredPolicyType = credsType.getDefault();
    CredentialsStorageMethodType storageMethod = SecurityUtil.getCredPolicyItem(defaltCredPolicyType, credPolicyType, pol -> pol.getStorageMethod());
    if (storageMethod == null) {
        return;
    }
    CredentialsStorageTypeType storageType = storageMethod.getStorageType();
    if (storageType == null || storageType == CredentialsStorageTypeType.ENCRYPTION) {
        return;
    } else if (storageType == CredentialsStorageTypeType.HASHING) {
        PrismPropertyValue<ProtectedStringType> pval = null;
        if (delta.isAdd()) {
            PrismProperty<ProtectedStringType> prop = delta.getObjectToAdd().findProperty(valuePropertyPath);
            hashValues(prop.getValues(), storageMethod);
        } else {
            PropertyDelta<ProtectedStringType> propDelta = delta.findPropertyDelta(valuePropertyPath);
            if (propDelta != null) {
                hashValues(propDelta.getValuesToAdd(), storageMethod);
                hashValues(propDelta.getValuesToReplace(), storageMethod);
                hashValues(propDelta.getValuesToDelete(), storageMethod);
            }
        }
    } else if (storageType == CredentialsStorageTypeType.NONE) {
        if (delta.isAdd()) {
            delta.getObjectToAdd().removeProperty(valuePropertyPath);
        } else {
            PropertyDelta<ProtectedStringType> propDelta = delta.findPropertyDelta(valuePropertyPath);
            if (propDelta != null) {
                // Replace with nothing. We need this to clear any existing value that there might be.
                propDelta.setValueToReplace();
            }
        }
    } else {
        throw new SchemaException("Unkwnon storage type " + storageType);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) CredentialsStorageTypeType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsStorageTypeType) CredentialsStorageMethodType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsStorageMethodType) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) CredentialPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialPolicyType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 77 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class TestReconScript method test005TestDryRunDelete.

@Test
public void test005TestDryRunDelete() throws Exception {
    final String TEST_NAME = "test005TestDryRunDelete";
    TestUtil.displayTestTile(this, TEST_NAME);
    PrismObject<TaskType> task = getTask(TASK_RECON_DUMMY_OID);
    OperationResult parentResult = new OperationResult(TEST_NAME);
    PropertyDelta dryRunDelta = PropertyDelta.createModificationReplaceProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_DRY_RUN), task.getDefinition(), true);
    Collection<PropertyDelta> modifications = new ArrayList<>();
    modifications.add(dryRunDelta);
    repositoryService.modifyObject(TaskType.class, TASK_RECON_DUMMY_OID, modifications, parentResult);
    getDummyResource().deleteAccountByName("beforeScript");
    waitForTaskStart(TASK_RECON_DUMMY_OID, false);
    waitForTaskNextRunAssertSuccess(TASK_RECON_DUMMY_OID, false);
    waitForTaskFinish(TASK_RECON_DUMMY_OID, false);
    PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, ACCOUNT_BEFORE_SCRIPT_OID, null, parentResult);
    AssertJUnit.assertNotNull(shadow);
    PrismObject<FocusType> user = repositoryService.searchShadowOwner(ACCOUNT_BEFORE_SCRIPT_OID, null, parentResult);
    AssertJUnit.assertNotNull("Owner for account " + shadow + " not found. Some probelm in dry run occured.", user);
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 78 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class TestTolerantAttributes method test104modifyReplaceAttributeTolerantPattern.

@Test
public void test104modifyReplaceAttributeTolerantPattern() throws Exception {
    TestUtil.displayTestTile(this, "test104modifyReplaceAttributeTolerantPattern");
    // GIVEN
    Task task = taskManager.createTaskInstance(TestTolerantAttributes.class.getName() + ".test104modifyReplaceAttributeTolerantPattern");
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
    ItemPath drinkItemPath = new ItemPath(new QName(getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME).getNamespace(), "drink"));
    PropertyDelta propertyDelta = PropertyDelta.createModificationReplaceProperty(new ItemPath(UserType.F_EMPLOYEE_NUMBER), getUserDefinition(), "thiIsOk");
    userDelta.addModification(propertyDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
    modelService.executeChanges(deltas, ModelExecuteOptions.createReconcile(), task, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    // Check value in "quote attribute"
    PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
    //	        assertUserJack(userJack);
    UserType userJackType = userJack.asObjectable();
    assertEquals("Unexpected number of accountRefs", 1, userJackType.getLinkRef().size());
    ObjectReferenceType accountRefType = userJackType.getLinkRef().get(0);
    accountOid = accountRefType.getOid();
    assertFalse("No accountRef oid", StringUtils.isBlank(accountOid));
    PrismReferenceValue accountRefValue = accountRefType.asReferenceValue();
    assertEquals("OID mismatch in accountRefValue", accountOid, accountRefValue.getOid());
    assertNull("Unexpected object in accountRefValue", accountRefValue.getObject());
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    assertAccountShadowRepo(accountShadow, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertAccountShadowModel(accountModel, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
    // Check account in dummy resource
    assertAccount(userJack, RESOURCE_DUMMY_BLACK_OID);
    // Check value of drink attribute
    assertDummyAccountAttribute(RESOURCE_DUMMY_BLACK_NAME, "jack", "gossip", "thiIsOk");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) Collection(java.util.Collection) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 79 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class TestTolerantAttributes method test103modifyReplaceAttributeIntolerant.

@Test
public void test103modifyReplaceAttributeIntolerant() throws Exception {
    TestUtil.displayTestTile(this, "test103modifyReplaceAttributeIntolerant");
    // GIVEN
    Task task = taskManager.createTaskInstance(TestTolerantAttributes.class.getName() + ".test103modifyReplaceAttributeIntolerant");
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
    PropertyDelta propertyDelta = PropertyDelta.createModificationReplaceProperty(new ItemPath(UserType.F_EMPLOYEE_NUMBER), getUserDefinition(), "gossip-thiIsNotOk");
    userDelta.addModification(propertyDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
    modelService.executeChanges(deltas, ModelExecuteOptions.createReconcile(), task, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    // Check value in "quote attribute"
    PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
    //	        assertUserJack(userJack);
    UserType userJackType = userJack.asObjectable();
    assertEquals("Unexpected number of accountRefs", 1, userJackType.getLinkRef().size());
    ObjectReferenceType accountRefType = userJackType.getLinkRef().get(0);
    accountOid = accountRefType.getOid();
    assertFalse("No accountRef oid", StringUtils.isBlank(accountOid));
    PrismReferenceValue accountRefValue = accountRefType.asReferenceValue();
    assertEquals("OID mismatch in accountRefValue", accountOid, accountRefValue.getOid());
    assertNull("Unexpected object in accountRefValue", accountRefValue.getObject());
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    assertAccountShadowRepo(accountShadow, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertAccountShadowModel(accountModel, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
    // Check account in dummy resource
    assertAccount(userJack, RESOURCE_DUMMY_BLACK_OID);
    // Check value of drink attribute
    assertDummyAccountAttribute(RESOURCE_DUMMY_BLACK_NAME, "jack", "gossip", null);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) Collection(java.util.Collection) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 80 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class TestTolerantAttributes method test105modifyAddNonTolerantAttribute.

@Test
public void test105modifyAddNonTolerantAttribute() throws Exception {
    TestUtil.displayTestTile(this, "test105modifyAddNonTolerantAttribute");
    // GIVEN
    Task task = taskManager.createTaskInstance(TestTolerantAttributes.class.getName() + ".test105modifyAddNonTolerantAttribute");
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
    ObjectDelta<ShadowType> userDelta = ObjectDelta.createEmptyModifyDelta(ShadowType.class, accountOid, prismContext);
    ItemPath drinkItemPath = new ItemPath(ShadowType.F_ATTRIBUTES, new QName(RESOURCE_DUMMY_BLACK_NAMESPACE, "drink"));
    assertNotNull("null definition for drink attribute ", accountDefinition.findPropertyDefinition(drinkItemPath));
    PropertyDelta propertyDelta = PropertyDelta.createModificationAddProperty(drinkItemPath, accountDefinition.findPropertyDefinition(drinkItemPath), "This should be ignored");
    userDelta.addModification(propertyDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
    try {
        modelService.executeChanges(deltas, ModelExecuteOptions.createReconcile(), task, result);
        fail("Expected Policy violation exception, because non-tolerant attribute is modified, but haven't got one.");
    } catch (PolicyViolationException ex) {
    //this is expected
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) Collection(java.util.Collection) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)83 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)51 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)36 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)25 QName (javax.xml.namespace.QName)24 Test (org.testng.annotations.Test)24 ArrayList (java.util.ArrayList)22 Task (com.evolveum.midpoint.task.api.Task)21 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)18 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)16 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)11 SystemException (com.evolveum.midpoint.util.exception.SystemException)11 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)11 Collection (java.util.Collection)11 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)10 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)10 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)10 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)9 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)8