Search in sources :

Example 56 with PrismContext

use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.

the class TestRefinedSchema method testProtectedAccount.

@Test
public void testProtectedAccount() throws JAXBException, SchemaException, SAXException, IOException {
    System.out.println("\n===[ testProtectedAccount ]===\n");
    // GIVEN
    PrismContext prismContext = createInitializedPrismContext();
    PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE);
    ResourceType resourceType = resource.asObjectable();
    RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext);
    assertNotNull("Refined schema is null", rSchema);
    assertFalse("No account definitions", rSchema.getRefinedDefinitions(ShadowKindType.ACCOUNT).isEmpty());
    RefinedObjectClassDefinition rAccount = rSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String) null);
    // WHEN
    Collection<ResourceObjectPattern> protectedAccounts = rAccount.getProtectedObjectPatterns();
    // THEN
    assertNotNull("Null protectedAccounts", protectedAccounts);
    assertFalse("Empty protectedAccounts", protectedAccounts.isEmpty());
    assertEquals("Unexpected number of protectedAccounts", 2, protectedAccounts.size());
    Iterator<ResourceObjectPattern> iterator = protectedAccounts.iterator();
    assertDeprecatedProtectedAccount("first protected account", iterator.next(), "uid=idm,ou=Administrators,dc=example,dc=com", rAccount);
    assertDeprecatedProtectedAccount("second protected account", iterator.next(), "uid=root,ou=Administrators,dc=example,dc=com", rAccount);
}
Also used : ResourceObjectPattern(com.evolveum.midpoint.common.ResourceObjectPattern) PrismContext(com.evolveum.midpoint.prism.PrismContext) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Test(org.testng.annotations.Test)

Example 57 with PrismContext

use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.

the class TestRefinedSchema method testParseAccount.

@Test
public void testParseAccount() throws JAXBException, SchemaException, SAXException, IOException {
    System.out.println("\n===[ testParseAccount ]===\n");
    // GIVEN
    PrismContext prismContext = createInitializedPrismContext();
    PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE);
    ResourceType resourceType = resource.asObjectable();
    RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext);
    RefinedObjectClassDefinition defaultAccountDefinition = rSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
    assertNotNull("No refined default account definition in " + rSchema, defaultAccountDefinition);
    PrismObject<ShadowType> accObject = prismContext.parseObject(new File(TEST_DIR_NAME, "account-jack.xml"));
    // WHEN
    PrismObjectDefinition<ShadowType> objectDefinition = defaultAccountDefinition.getObjectDefinition();
    System.out.println("Refined account definition:");
    System.out.println(objectDefinition.debugDump());
    accObject.applyDefinition(objectDefinition);
    // THEN
    System.out.println("Parsed account:");
    System.out.println(accObject.debugDump());
    assertAccountShadow(accObject, resource, prismContext);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) File(java.io.File) Test(org.testng.annotations.Test)

Example 58 with PrismContext

use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.

the class TestRefinedSchema method testParseFromResourceComplex.

@Test
public void testParseFromResourceComplex() throws Exception {
    final String TEST_NAME = "testParseFromResourceComplex";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    PrismContext prismContext = createInitializedPrismContext();
    PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE);
    ResourceType resourceType = resource.asObjectable();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertNotNull("Refined schema is null", rSchema);
    System.out.println("Refined schema");
    System.out.println(rSchema.debugDump());
    assertRefinedSchema(resourceType, rSchema, null, LayerType.MODEL, true);
    assertLayerRefinedSchema(resourceType, rSchema, LayerType.SCHEMA, LayerType.SCHEMA, true);
    assertLayerRefinedSchema(resourceType, rSchema, LayerType.MODEL, LayerType.MODEL, true);
    assertLayerRefinedSchema(resourceType, rSchema, LayerType.PRESENTATION, LayerType.PRESENTATION, true);
    RefinedObjectClassDefinition rAccount = rSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String) null);
    RefinedAttributeDefinition userPasswordAttribute = rAccount.findAttributeDefinition("userPassword");
    assertNotNull("No userPassword attribute", userPasswordAttribute);
    assertTrue("userPassword not ignored", userPasswordAttribute.isIgnored());
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Test(org.testng.annotations.Test)

Example 59 with PrismContext

use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.

the class RawTypeUtil method getParsedItem.

public static <IV extends PrismValue, ID extends ItemDefinition> Item<IV, ID> getParsedItem(ID itemDefinition, List<RawType> values, QName elementQName, PrismContainerDefinition containerDef) throws SchemaException {
    Item<IV, ID> subItem = null;
    List<IV> parsedValues = new ArrayList<IV>();
    for (RawType rawValue : values) {
        if (itemDefinition == null && containerDef != null) {
            itemDefinition = (ID) ((PrismContextImpl) containerDef.getPrismContext()).getPrismUnmarshaller().locateItemDefinition(containerDef, elementQName, rawValue.getXnode());
        }
        IV parsed = rawValue.getParsedValue(itemDefinition, elementQName);
        if (parsed != null) {
            parsedValues.add(parsed);
        }
    }
    PrismContext prismContext = null;
    if (containerDef != null) {
        prismContext = containerDef.getPrismContext();
    }
    if (prismContext == null && itemDefinition != null) {
        prismContext = itemDefinition.getPrismContext();
    }
    if (itemDefinition == null) {
        PrismProperty property = new PrismProperty(elementQName, prismContext);
        property.addAll(PrismValue.cloneCollection(parsedValues));
        return property;
    }
    if (itemDefinition instanceof PrismPropertyDefinition<?>) {
        // property
        PrismProperty<?> property = ((PrismPropertyDefinition<?>) itemDefinition).instantiate();
        for (IV val : parsedValues) {
            property.add((PrismPropertyValue) val.clone());
        }
        subItem = (Item<IV, ID>) property;
    } else if (itemDefinition instanceof PrismContainerDefinition<?>) {
        PrismContainer<?> container = ((PrismContainerDefinition<?>) itemDefinition).instantiate();
        for (IV val : parsedValues) {
            container.add((PrismContainerValue) val.clone());
        }
        subItem = (Item<IV, ID>) container;
    } else if (itemDefinition instanceof PrismReferenceDefinition) {
        // TODO
        PrismReference reference = ((PrismReferenceDefinition) itemDefinition).instantiate();
        for (IV val : parsedValues) {
            PrismReferenceValue ref;
            if (val instanceof PrismReferenceValue) {
                ref = (PrismReferenceValue) val.clone();
            } else if (val instanceof PrismContainerValue) {
                // this is embedded (full) object
                Containerable c = ((PrismContainerValue) val).asContainerable();
                if (!(c instanceof Objectable)) {
                    throw new IllegalStateException("Content of " + itemDefinition + " is a Containerable but not Objectable: " + c);
                }
                Objectable o = (Objectable) c;
                ref = new PrismReferenceValue();
                ref.setObject(o.asPrismObject());
            } else {
                throw new IllegalStateException("Content of " + itemDefinition + " is neither PrismReferenceValue nor PrismContainerValue: " + val);
            }
            reference.merge(ref);
        }
        subItem = (Item<IV, ID>) reference;
    } else {
        throw new IllegalArgumentException("Unsupported definition type " + itemDefinition.getClass());
    }
    return subItem;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PrismContext(com.evolveum.midpoint.prism.PrismContext) ArrayList(java.util.ArrayList) PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition) Item(com.evolveum.midpoint.prism.Item) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) PrismReference(com.evolveum.midpoint.prism.PrismReference) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 60 with PrismContext

use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.

the class TestParseFilter method testParseFilterFile.

@Test
public void testParseFilterFile() throws Exception {
    System.out.println("===[ testParseFilterFile ]===");
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    // WHEN
    SearchFilterType filter = prismContext.parserFor(FILTER_FILE).parseRealValue(SearchFilterType.class);
    // THEN
    System.out.println("Parsed filter:");
    System.out.println(filter.debugDump());
    String serialized = PrismTestUtil.serializeJaxbElementToString(new JAXBElement<SearchFilterType>(new QName(SchemaConstants.NS_QUERY, "filter"), SearchFilterType.class, filter));
    System.out.println("JAXB serialization result:\n" + serialized);
    // WHEN2
    SearchFilterType filter2 = prismContext.parserFor(serialized).parseRealValue(SearchFilterType.class);
    System.out.println("Reparsed filter:");
    System.out.println(filter2.debugDump());
    // THEN2
    assertEquals("Parsed and serialized+parsed filters do not match", filter, filter2);
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) Test(org.testng.annotations.Test)

Aggregations

PrismContext (com.evolveum.midpoint.prism.PrismContext)104 Test (org.testng.annotations.Test)59 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)15 QName (javax.xml.namespace.QName)15 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)13 Task (com.evolveum.midpoint.task.api.Task)11 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)10 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 SystemException (com.evolveum.midpoint.util.exception.SystemException)9 File (java.io.File)8 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)7 ArrayList (java.util.ArrayList)7 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)6 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)6 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 Protector (com.evolveum.midpoint.prism.crypto.Protector)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)5