Search in sources :

Example 21 with PrismContext

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

the class TestFilterSimplifier method test160OrLevel1WithoutAll.

@Test
public void test160OrLevel1WithoutAll() throws Exception {
    System.out.println("===[ test160OrLevel1WithoutAll ]===");
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    // WHEN
    ObjectFilter filter = QueryBuilder.queryFor(UserType.class, prismContext).none().or().undefined().buildFilter();
    System.out.println("Original filter:\n" + filter.debugDump());
    // THEN
    ObjectFilter simplified = ObjectQueryUtil.simplify(filter);
    System.out.println("Simplified filter:\n" + DebugUtil.debugDump(simplified));
    assertTrue("Wrong simplified filter: " + simplified, simplified instanceof NoneFilter);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) Test(org.testng.annotations.Test)

Example 22 with PrismContext

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

the class TestFilterExpression method evaluateExpressionAssertFilter.

private ObjectFilter evaluateExpressionAssertFilter(String filename, String input, Class<? extends ObjectFilter> expectedType, Task task, OperationResult result) throws SchemaException, IOException, ObjectNotFoundException, ExpressionEvaluationException {
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    SearchFilterType filterType = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, filename), SearchFilterType.COMPLEX_TYPE);
    ObjectFilter filter = QueryJaxbConvertor.createObjectFilter(UserType.class, filterType, prismContext);
    Map<QName, Object> params = new HashMap<>();
    PrismPropertyValue<String> pval = null;
    if (input != null) {
        pval = new PrismPropertyValue<String>(input);
    }
    params.put(ExpressionConstants.VAR_INPUT, pval);
    ExpressionVariables variables = new ExpressionVariables();
    variables.addVariableDefinitions(params);
    // WHEN
    ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(filter, variables, expressionFactory, prismContext, "evaluating filter with null value not allowed", task, result);
    // THEN
    display("Evaluated filter", evaluatedFilter);
    AssertJUnit.assertTrue("Expression should be evaluated to " + expectedType + ", but was " + evaluatedFilter, expectedType.isAssignableFrom(evaluatedFilter.getClass()));
    return evaluatedFilter;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) HashMap(java.util.HashMap) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) File(java.io.File)

Example 23 with PrismContext

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

the class TestProtectedString method testParseProtectedStringEncrypted.

@Test
public void testParseProtectedStringEncrypted() throws Exception {
    final String TEST_NAME = "testParseProtectedStringEncrypted";
    displayTestTitle(TEST_NAME);
    // GIVEN
    Protector protector = PrismInternalTestUtil.createProtector(XMLCipher.AES_128);
    ProtectedStringType protectedStringType = protector.encryptString("salalala");
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    // WHEN
    MapXNode protectedStringTypeXNode = ((PrismContextImpl) prismContext).getBeanMarshaller().marshalProtectedDataType(protectedStringType, null);
    System.out.println("Protected string type XNode: " + protectedStringTypeXNode.debugDump());
    // THEN
    ProtectedStringType unmarshalled = new ProtectedStringType();
    XNodeProcessorUtil.parseProtectedType(unmarshalled, protectedStringTypeXNode, prismContext, ParsingContext.createDefault());
    System.out.println("Unmarshalled value: " + unmarshalled);
    assertEquals("Unmarshalled value differs from the original", protectedStringType, unmarshalled);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) TestProtector(com.evolveum.midpoint.prism.crypto.TestProtector) Protector(com.evolveum.midpoint.prism.crypto.Protector) Test(org.testng.annotations.Test)

Example 24 with PrismContext

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

the class TestProtectedString method testParseProtectedStringHashed.

@Test
public void testParseProtectedStringHashed() throws Exception {
    final String TEST_NAME = "testParseProtectedStringHashed";
    displayTestTitle(TEST_NAME);
    // GIVEN
    ProtectedStringType protectedStringType = new ProtectedStringType();
    protectedStringType.setClearValue("blabla");
    Protector protector = PrismInternalTestUtil.createProtector(XMLCipher.AES_128);
    protector.hash(protectedStringType);
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    // WHEN
    MapXNode protectedStringTypeXNode = ((PrismContextImpl) prismContext).getBeanMarshaller().marshalProtectedDataType(protectedStringType, null);
    System.out.println("Protected string type XNode: " + protectedStringTypeXNode.debugDump());
    // THEN
    ProtectedStringType unmarshalled = new ProtectedStringType();
    XNodeProcessorUtil.parseProtectedType(unmarshalled, protectedStringTypeXNode, prismContext, ParsingContext.createDefault());
    System.out.println("Unmarshalled value: " + unmarshalled);
    assertEquals("Unmarshalled value differs from the original", protectedStringType, unmarshalled);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) TestProtector(com.evolveum.midpoint.prism.crypto.TestProtector) Protector(com.evolveum.midpoint.prism.crypto.Protector) Test(org.testng.annotations.Test)

Example 25 with PrismContext

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

the class AssignmentEditorDto method prepareAssignmentAttributes.

private List<ACAttributeDto> prepareAssignmentAttributes(AssignmentType assignment, PageBase pageBase) {
    List<ACAttributeDto> acAtrList = new ArrayList<>();
    if (assignment == null || assignment.getConstruction() == null || assignment.getConstruction().getAttribute() == null || assignment.getConstruction() == null) {
        return acAtrList;
    }
    OperationResult result = new OperationResult(OPERATION_LOAD_ATTRIBUTES);
    ConstructionType construction = assignment.getConstruction();
    PrismObject<ResourceType> resource = construction.getResource() != null ? construction.getResource().asPrismObject() : null;
    if (resource == null) {
        resource = getReference(construction.getResourceRef(), result, pageBase);
    }
    try {
        PrismContext prismContext = pageBase.getPrismContext();
        RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.PRESENTATION, prismContext);
        RefinedObjectClassDefinition objectClassDefinition = refinedSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, construction.getIntent());
        if (objectClassDefinition == null) {
            return attributes;
        }
        PrismContainerDefinition definition = objectClassDefinition.toResourceAttributeContainerDefinition();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Refined definition for {}\n{}", construction, definition.debugDump());
        }
        Collection<ItemDefinition> definitions = definition.getDefinitions();
        for (ResourceAttributeDefinitionType attribute : assignment.getConstruction().getAttribute()) {
            for (ItemDefinition attrDef : definitions) {
                if (attrDef instanceof PrismPropertyDefinition) {
                    PrismPropertyDefinition propertyDef = (PrismPropertyDefinition) attrDef;
                    if (propertyDef.isOperational() || propertyDef.isIgnored()) {
                        continue;
                    }
                    if (ItemPathUtil.getOnlySegmentQName(attribute.getRef()).equals(propertyDef.getName())) {
                        acAtrList.add(ACAttributeDto.createACAttributeDto(propertyDef, attribute, prismContext));
                        break;
                    }
                }
            }
        }
        result.recordSuccess();
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Exception occurred during assignment attribute loading", ex);
        result.recordFatalError("Exception occurred during assignment attribute loading.", ex);
    } finally {
        result.recomputeStatus();
    }
    return acAtrList;
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PrismContext(com.evolveum.midpoint.prism.PrismContext) ArrayList(java.util.ArrayList) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema)

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