Search in sources :

Example 11 with StringPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType in project midpoint by Evolveum.

the class TestPasswordPolicy method stringPolicyUtilsComplexTest.

@Test
public void stringPolicyUtilsComplexTest() {
    final String TEST_NAME = "stringPolicyUtilsComplexTest";
    TestUtil.displayTestTile(TEST_NAME);
    File file = new File(TEST_DIR, "password-policy-complex.xml");
    ValuePolicyType pp = null;
    try {
        pp = (ValuePolicyType) PrismTestUtil.parseObject(file).asObjectable();
    } catch (Exception e) {
        e.printStackTrace();
    }
    StringPolicyType sp = pp.getStringPolicy();
    StringPolicyUtils.normalize(sp);
}
Also used : StringPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) File(java.io.File) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 12 with StringPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType in project midpoint by Evolveum.

the class TestMappingDynamicSimple method testGenerateDefault.

@Test
public void testGenerateDefault() throws Exception {
    final String TEST_NAME = "testGenerateDefault";
    TestUtil.displayTestTile(TEST_NAME);
    final StringPolicyType stringPolicy = evaluator.getStringPolicy();
    // GIVEN
    Mapping<PrismPropertyValue<String>, PrismPropertyDefinition<String>> mapping = evaluator.createMapping("mapping-generate.xml", TEST_NAME, stringPolicy, "employeeNumber", null);
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN (1)
    mapping.evaluate(null, opResult);
    // THEN (1)
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = mapping.getOutputTriple();
    String value1 = MappingTestEvaluator.getSingleValue("plus set", outputTriple.getZeroSet());
    PrismAsserts.assertTripleNoPlus(outputTriple);
    PrismAsserts.assertTripleNoMinus(outputTriple);
    System.out.println("Generated value (1): " + value1);
    assertGeneratedValue(value1, stringPolicy, null, false, false);
    mapping = evaluator.createMapping("mapping-generate.xml", TEST_NAME, stringPolicy, "employeeNumber", null);
    // WHEN (2)
    mapping.evaluate(null, opResult);
    // THEN (2)
    outputTriple = mapping.getOutputTriple();
    outputTriple.checkConsistence();
    String value2 = MappingTestEvaluator.getSingleValue("plus set", outputTriple.getZeroSet());
    System.out.println("Generated value (2): " + value2);
    assertGeneratedValue(value2, stringPolicy, null, false, false);
    PrismAsserts.assertTripleNoPlus(outputTriple);
    PrismAsserts.assertTripleNoMinus(outputTriple);
    assertFalse("Generated the same value", value1.equals(value2));
}
Also used : StringPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Example 13 with StringPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType in project midpoint by Evolveum.

the class MappingTestEvaluator method createInboudMapping.

public <T> Mapping<PrismPropertyValue<T>, PrismPropertyDefinition<T>> createInboudMapping(String filename, String testName, ItemDelta delta, UserType user, ShadowType account, ResourceType resource, final StringPolicyType policy) throws SchemaException, IOException, JAXBException {
    MappingType mappingType = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, filename), MappingType.COMPLEX_TYPE);
    Mapping.Builder<PrismPropertyValue<T>, PrismPropertyDefinition<T>> builder = mappingFactory.createMappingBuilder(mappingType, testName);
    Source<PrismPropertyValue<T>, PrismPropertyDefinition<T>> defaultSource = new Source<>(null, delta, null, ExpressionConstants.VAR_INPUT);
    defaultSource.recompute();
    builder.setDefaultSource(defaultSource);
    builder.setTargetContext(getUserDefinition());
    builder.addVariableDefinition(ExpressionConstants.VAR_USER, user);
    builder.addVariableDefinition(ExpressionConstants.VAR_FOCUS, user);
    builder.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, account.asPrismObject());
    builder.addVariableDefinition(ExpressionConstants.VAR_SHADOW, account.asPrismObject());
    StringPolicyResolver stringPolicyResolver = new StringPolicyResolver() {

        ItemPath outputPath;

        ItemDefinition outputDefinition;

        @Override
        public void setOutputPath(ItemPath outputPath) {
            this.outputPath = outputPath;
        }

        @Override
        public void setOutputDefinition(ItemDefinition outputDefinition) {
            this.outputDefinition = outputDefinition;
        }

        @Override
        public StringPolicyType resolve() {
            return policy;
        }
    };
    builder.setStringPolicyResolver(stringPolicyResolver);
    builder.setOriginType(OriginType.INBOUND);
    builder.setOriginObject(resource);
    return builder.build();
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) StringPolicyResolver(com.evolveum.midpoint.repo.common.expression.StringPolicyResolver) File(java.io.File) Source(com.evolveum.midpoint.repo.common.expression.Source) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 14 with StringPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType in project midpoint by Evolveum.

the class MappingEvaluator method createFocusMapping.

public <V extends PrismValue, D extends ItemDefinition, F extends FocusType, T extends FocusType> Mapping<V, D> createFocusMapping(final MappingFactory mappingFactory, final LensContext<F> context, final MappingType mappingType, ObjectType originObject, ObjectDeltaObject<F> focusOdo, PrismObject<T> defaultTargetObject, AssignmentPathVariables assignmentPathVariables, Integer iteration, String iterationToken, PrismObject<SystemConfigurationType> configuration, XMLGregorianCalendar now, String contextDesc, final Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    if (!Mapping.isApplicableToChannel(mappingType, context.getChannel())) {
        LOGGER.trace("Mapping {} not applicable to channel {}, skipping.", mappingType, context.getChannel());
        return null;
    }
    StringPolicyResolver stringPolicyResolver = new StringPolicyResolver() {

        private ItemPath outputPath;

        private ItemDefinition outputDefinition;

        @Override
        public void setOutputPath(ItemPath outputPath) {
            this.outputPath = outputPath;
        }

        @Override
        public void setOutputDefinition(ItemDefinition outputDefinition) {
            this.outputDefinition = outputDefinition;
        }

        @Override
        public StringPolicyType resolve() {
            // TODO need to switch to ObjectValuePolicyEvaluator
            if (outputDefinition.getName().equals(PasswordType.F_VALUE)) {
                ValuePolicyType passwordPolicy = credentialsProcessor.determinePasswordPolicy(context.getFocusContext(), task, result);
                if (passwordPolicy == null) {
                    return null;
                }
                return passwordPolicy.getStringPolicy();
            }
            if (mappingType.getExpression() != null) {
                List<JAXBElement<?>> evaluators = mappingType.getExpression().getExpressionEvaluator();
                if (evaluators != null) {
                    for (JAXBElement jaxbEvaluator : evaluators) {
                        Object object = jaxbEvaluator.getValue();
                        if (object instanceof GenerateExpressionEvaluatorType && ((GenerateExpressionEvaluatorType) object).getValuePolicyRef() != null) {
                            ObjectReferenceType ref = ((GenerateExpressionEvaluatorType) object).getValuePolicyRef();
                            try {
                                ValuePolicyType valuePolicyType = mappingFactory.getObjectResolver().resolve(ref, ValuePolicyType.class, null, "resolving value policy for generate attribute " + outputDefinition.getName() + " value", task, new OperationResult("Resolving value policy"));
                                if (valuePolicyType != null) {
                                    return valuePolicyType.getStringPolicy();
                                }
                            } catch (CommonException ex) {
                                throw new SystemException(ex.getMessage(), ex);
                            }
                        }
                    }
                }
            }
            return null;
        }
    };
    ExpressionVariables variables = new ExpressionVariables();
    FOCUS_VARIABLE_NAMES.forEach(name -> variables.addVariableDefinition(name, focusOdo));
    variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION, iteration);
    variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION_TOKEN, iterationToken);
    variables.addVariableDefinition(ExpressionConstants.VAR_CONFIGURATION, configuration);
    Collection<V> targetValues = computeTargetValues(mappingType.getTarget(), defaultTargetObject, variables, mappingFactory.getObjectResolver(), contextDesc, task, result);
    Mapping.Builder<V, D> mappingBuilder = mappingFactory.<V, D>createMappingBuilder(mappingType, contextDesc).sourceContext(focusOdo).targetContext(defaultTargetObject.getDefinition()).variables(variables).originalTargetValues(targetValues).originType(OriginType.USER_POLICY).originObject(originObject).stringPolicyResolver(stringPolicyResolver).rootNode(focusOdo).now(now);
    mappingBuilder = LensUtil.addAssignmentPathVariables(mappingBuilder, assignmentPathVariables);
    Mapping<V, D> mapping = mappingBuilder.build();
    ItemPath itemPath = mapping.getOutputPath();
    if (itemPath == null) {
        // no output element, i.e. this is a "validation mapping"
        return mapping;
    }
    if (defaultTargetObject != null) {
        Item<V, D> existingTargetItem = (Item<V, D>) defaultTargetObject.findItem(itemPath);
        if (existingTargetItem != null && !existingTargetItem.isEmpty() && mapping.getStrength() == MappingStrengthType.WEAK) {
            LOGGER.trace("Mapping {} is weak and target already has a value {}, skipping.", mapping, existingTargetItem);
            return null;
        }
    }
    return mapping;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) StringPolicyResolver(com.evolveum.midpoint.repo.common.expression.StringPolicyResolver) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) JAXBElement(javax.xml.bind.JAXBElement) Item(com.evolveum.midpoint.prism.Item) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) GenerateExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenerateExpressionEvaluatorType) CommonException(com.evolveum.midpoint.util.exception.CommonException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 15 with StringPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType in project midpoint by Evolveum.

the class ValuePolicyProcessor method normalize.

/**
	 * add defined default values
	 */
private void normalize(ValuePolicyType pp) {
    if (null == pp) {
        throw new IllegalArgumentException("Password policy cannot be null");
    }
    if (null == pp.getStringPolicy()) {
        StringPolicyType sp = new StringPolicyType();
        pp.setStringPolicy(StringPolicyUtils.normalize(sp));
    } else {
        pp.setStringPolicy(StringPolicyUtils.normalize(pp.getStringPolicy()));
    }
    if (null == pp.getLifetime()) {
        PasswordLifeTimeType lt = new PasswordLifeTimeType();
        lt.setExpiration(-1);
        lt.setWarnBeforeExpiration(0);
        lt.setLockAfterExpiration(0);
        lt.setMinPasswordAge(0);
        lt.setPasswordHistoryLength(0);
    }
    return;
}
Also used : StringPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType) PasswordLifeTimeType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordLifeTimeType)

Aggregations

StringPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType)8 ValuePolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType)8 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)7 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)6 StringPolicyResolver (com.evolveum.midpoint.repo.common.expression.StringPolicyResolver)6 File (java.io.File)6 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)3 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)3 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)3 Test (org.testng.annotations.Test)3 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)2 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2