Search in sources :

Example 26 with ItemPathType

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

the class TestUserChangeApprovalLegacy method checkAssignmentConstruction.

private void checkAssignmentConstruction(UserType jack, String attributeName, String value) throws SchemaException {
    assertEquals("jack's assignments", 1, jack.getAssignment().size());
    AssignmentType assignmentType = jack.getAssignment().get(0);
    ConstructionType constructionType = assignmentType.getConstruction();
    assertNotNull("construction is null", constructionType);
    boolean found = false;
    for (ResourceAttributeDefinitionType attributeDefinitionType : constructionType.getAttribute()) {
        if (attributeDefinitionType.getRef().equivalent(new ItemPathType(new ItemPath(new QName(attributeName))))) {
            ExpressionType expressionType = attributeDefinitionType.getOutbound().getExpression();
            assertNotNull("no expression", expressionType);
            assertEquals("wrong # of expression evaluators", 1, expressionType.getExpressionEvaluator().size());
            JAXBElement<?> element = expressionType.getExpressionEvaluator().get(0);
            PrimitiveXNode valueXNode = (PrimitiveXNode) (((RawType) element.getValue()).serializeToXNode());
            assertEquals("wrong outbound value", value, valueXNode.getStringValue());
            found = true;
        }
    }
    assertTrue("attribute " + attributeName + " mapping not found", found);
}
Also used : PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 27 with ItemPathType

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

the class TestIteration method test200JackAssignAccountDummyPinkConflicting.

@Test
public void test200JackAssignAccountDummyPinkConflicting() throws Exception {
    final String TEST_NAME = "test200JackAssignAccountDummyPinkConflicting";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    // Make sure there is a conflicting account and also a shadow for it
    DummyAccount account = new DummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    account.setEnabled(true);
    account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Jack Pinky");
    account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Red Sea");
    dummyResourcePink.addAccount(account);
    repoAddObject(createShadow(resourceDummyPink, ACCOUNT_JACK_DUMMY_USERNAME), result);
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    // assignment with weapon := 'pistol' (test for
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    AssignmentType assignmentType = createConstructionAssignment(RESOURCE_DUMMY_PINK_OID, ShadowKindType.ACCOUNT, null);
    ConstructionType constructionType = assignmentType.getConstruction();
    ResourceAttributeDefinitionType attributeDefinitionType = new ResourceAttributeDefinitionType();
    attributeDefinitionType.setRef(new ItemPathType(new ItemPath(dummyResourceCtlPink.getAttributeWeaponQName())));
    MappingType mappingType = new MappingType();
    mappingType.setStrength(MappingStrengthType.STRONG);
    ExpressionType expressionType = new ExpressionType();
    expressionType.getExpressionEvaluator().add(new ObjectFactory().createValue(RawType.create("pistol", prismContext)));
    mappingType.setExpression(expressionType);
    attributeDefinitionType.setOutbound(mappingType);
    constructionType.getAttribute().add(attributeDefinitionType);
    modifications.add(createAssignmentModification(assignmentType, true));
    ObjectDelta<UserType> accountAssignmentUserDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
    deltas.add(accountAssignmentUserDelta);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    display("User after change execution", userJack);
    assertUserJack(userJack);
    assertLinks(userJack, 2);
    assertAccount(userJack, RESOURCE_DUMMY_OID);
    assertAccount(userJack, RESOURCE_DUMMY_PINK_OID);
    String accountPinkOid = getLinkRefOid(userJack, RESOURCE_DUMMY_PINK_OID);
    // Check shadow
    PrismObject<ShadowType> accountPinkShadow = repositoryService.getObject(ShadowType.class, accountPinkOid, null, result);
    assertAccountShadowRepo(accountPinkShadow, accountPinkOid, "jack1", resourceDummyPinkType);
    // Check account
    PrismObject<ShadowType> accountPinkModel = modelService.getObject(ShadowType.class, accountPinkOid, null, task, result);
    assertAccountShadowModel(accountPinkModel, accountPinkOid, "jack1", resourceDummyPinkType);
    display("accountPinkModel", accountPinkModel);
    PrismAsserts.assertPropertyValue(accountPinkModel, dummyResourceCtlPink.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME), "pistol");
    // Check account in dummy resource
    assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
    // The original conflicting account should still remain
    assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Pinky", true);
    // The new account
    assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "jack1", "Jack Sparrow", true);
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(3);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
    dummyAuditService.assertExecutionSuccess();
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) Task(com.evolveum.midpoint.task.api.Task) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 28 with ItemPathType

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

the class Main method createUserQuery2.

private static QueryType createUserQuery2(String username) throws JAXBException {
    QueryType query = new QueryType();
    SearchFilterType filter = new SearchFilterType();
    PropertyComplexValueFilterClauseType fc = new PropertyComplexValueFilterClauseType();
    ItemPathType path = new ItemPathType();
    path.setValue("declare namespace c=\"http://midpoint.evolveum.com/xml/ns/public/common/common-3\"; c:name");
    fc.setPath(path);
    fc.getValue().add(username);
    ObjectFactory factory = new ObjectFactory();
    JAXBElement<PropertyComplexValueFilterClauseType> equal = factory.createEqual(fc);
    JAXBContext jaxbContext = JAXBContext.newInstance("com.evolveum.midpoint.xml.ns._public.common.api_types_3:" + "com.evolveum.midpoint.xml.ns._public.common.common_3:" + "com.evolveum.prism.xml.ns._public.annotation_3:" + "com.evolveum.prism.xml.ns._public.query_3:" + "com.evolveum.prism.xml.ns._public.types_3:");
    Marshaller marshaller = jaxbContext.createMarshaller();
    DOMResult result = new DOMResult();
    marshaller.marshal(equal, result);
    filter.setFilterClause(((Document) result.getNode()).getDocumentElement());
    query.setFilter(filter);
    return query;
}
Also used : Marshaller(javax.xml.bind.Marshaller) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) DOMResult(javax.xml.transform.dom.DOMResult) ObjectFactory(com.evolveum.prism.xml.ns._public.query_3.ObjectFactory) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) PropertyComplexValueFilterClauseType(com.evolveum.prism.xml.ns._public.query_3.PropertyComplexValueFilterClauseType) JAXBContext(javax.xml.bind.JAXBContext) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 29 with ItemPathType

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

the class AbstractTestForExchangeConnector method createNonDefaultItemPathType.

public static ItemPathType createNonDefaultItemPathType(String stringPath) {
    ItemPathType itemPathType = new ItemPathType();
    itemPathType.setValue(stringPath);
    return itemPathType;
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType)

Example 30 with ItemPathType

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

the class SecurityEnforcerImpl method isApplicableItem.

private <O extends ObjectType> boolean isApplicableItem(Authorization autz, PrismObject<O> object, ObjectDelta<O> delta) throws SchemaException {
    List<ItemPathType> itemPaths = autz.getItem();
    if (itemPaths == null || itemPaths.isEmpty()) {
        // No item constraints. Applicable for all items.
        LOGGER.trace("  items empty");
        return true;
    }
    for (ItemPathType itemPathType : itemPaths) {
        ItemPath itemPath = itemPathType.getItemPath();
        if (delta == null) {
            if (object != null) {
                if (object.containsItem(itemPath, false)) {
                    LOGGER.trace("  applicable object item " + itemPath);
                    return true;
                }
            }
        } else {
            ItemDelta<?, ?> itemDelta = delta.findItemDelta(itemPath);
            if (itemDelta != null && !itemDelta.isEmpty()) {
                LOGGER.trace("  applicable delta item " + itemPath);
                return true;
            }
        }
    }
    LOGGER.trace("  no applicable item");
    return false;
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)55 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)36 QName (javax.xml.namespace.QName)20 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)11 ArrayList (java.util.ArrayList)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)10 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)9 Test (org.testng.annotations.Test)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)7 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)7 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)6 List (java.util.List)5 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)4 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)4 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)4 MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)4 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)3