Search in sources :

Example 66 with ObjectType

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

the class AbstractSecurityTest method assertModifyAllowOptions.

protected <O extends ObjectType> void assertModifyAllowOptions(Class<O> type, String oid, ItemPath itemPath, ModelExecuteOptions options, Object... newRealValue) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    Task task = taskManager.createTaskInstance(AbstractSecurityTest.class.getName() + ".assertModifyAllow");
    OperationResult result = task.getResult();
    ObjectDelta<O> objectDelta = ObjectDelta.createModificationReplaceProperty(type, oid, itemPath, prismContext, newRealValue);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
    try {
        logAttempt("modify", type, oid, itemPath);
        modelService.executeChanges(deltas, options, task, result);
    } catch (SecurityViolationException e) {
        failAllow("modify", type, oid, itemPath, e);
    }
    result.computeStatus();
    TestUtil.assertSuccess(result);
    logAllow("modify", type, oid, itemPath);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 67 with ObjectType

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

the class AbstractSecurityTest method assertModifyDenyOptions.

protected <O extends ObjectType> void assertModifyDenyOptions(Class<O> type, String oid, ItemPath itemPath, ModelExecuteOptions options, Object... newRealValue) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    Task task = taskManager.createTaskInstance(AbstractSecurityTest.class.getName() + ".assertModifyDeny");
    OperationResult result = task.getResult();
    ObjectDelta<O> objectDelta = ObjectDelta.createModificationReplaceProperty(type, oid, itemPath, prismContext, newRealValue);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
    try {
        logAttempt("modify", type, oid, itemPath);
        modelService.executeChanges(deltas, options, task, result);
        failDeny("modify", type, oid, itemPath);
    } catch (SecurityViolationException e) {
        // this is expected
        logDeny("modify", type, oid, itemPath);
        result.computeStatus();
        TestUtil.assertFailure(result);
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 68 with ObjectType

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

the class ShadowCache method extendShadow.

private PrismObject<ShadowType> extendShadow(PrismObject<ShadowType> shadow, OperationResult shadowResult, ResourceType resource, Collection<? extends ItemDelta> modifications) throws SchemaException {
    ShadowType shadowType = shadow.asObjectable();
    shadowType.setResult(shadowResult.createOperationResultType());
    shadowType.setResource(resource);
    if (modifications != null) {
        ObjectDelta<? extends ObjectType> objectDelta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadowType.getClass(), prismContext);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Storing delta to shadow:\n{}", objectDelta.debugDump());
        }
        ContainerDelta<ShadowAssociationType> associationDelta = objectDelta.findContainerDelta(ShadowType.F_ASSOCIATION);
        if (associationDelta != null) {
            normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToAdd());
            normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToReplace());
            normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToDelete());
        }
        ObjectDeltaType objectDeltaType = DeltaConvertor.toObjectDeltaType(objectDelta);
        shadowType.setObjectChange(objectDeltaType);
    }
    return shadow;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)

Example 69 with ObjectType

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

the class ShadowCacheReconciler method beforeModifyOnResource.

@Override
public Collection<? extends ItemDelta> beforeModifyOnResource(PrismObject<ShadowType> shadow, ProvisioningOperationOptions options, Collection<? extends ItemDelta> modifications) throws SchemaException {
    ObjectDeltaType shadowDelta = shadow.asObjectable().getObjectChange();
    //TODO: error handling
    if (shadowDelta != null) {
        modifications = DeltaConvertor.toModifications(shadowDelta.getItemDelta(), shadow.getDefinition());
    }
    // for the older versions
    ObjectDelta<? extends ObjectType> objectDelta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, ShadowType.class, getPrismContext());
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Storing delta to shadow:\n{}", objectDelta.debugDump());
    }
    ContainerDelta<ShadowAssociationType> associationDelta = objectDelta.findContainerDelta(ShadowType.F_ASSOCIATION);
    if (associationDelta != null) {
        normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToAdd());
        normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToReplace());
        normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToDelete());
    }
    if (modifications == null) {
        modifications = new ArrayList<ItemDelta>();
    }
    return modifications;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)

Example 70 with ObjectType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectType 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)

Aggregations

ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)371 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)297 Test (org.testng.annotations.Test)264 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)253 Task (com.evolveum.midpoint.task.api.Task)252 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)223 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)155 ArrayList (java.util.ArrayList)123 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)100 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)58 Holder (javax.xml.ws.Holder)49 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)46 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)46 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)38 QName (javax.xml.namespace.QName)38 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)37 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)33 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)33 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)32