Search in sources :

Example 26 with ValuePolicyType

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

the class SystemConfigPanel method initLayout.

protected void initLayout() {
    ChooseTypePanel<ValuePolicyType> passPolicyChoosePanel = new ChooseTypePanel<ValuePolicyType>(ID_GLOBAL_PASSWORD_POLICY_CHOOSER, new PropertyModel<ObjectViewDto<ValuePolicyType>>(getModel(), SystemConfigurationDto.F_PASSWORD_POLICY));
    ChooseTypePanel<SecurityPolicyType> securityPolicyChoosePanel = new ChooseTypePanel<SecurityPolicyType>(ID_GLOBAL_SECURITY_POLICY_CHOOSER, new PropertyModel<ObjectViewDto<SecurityPolicyType>>(getModel(), SystemConfigurationDto.F_SECURITY_POLICY));
    add(passPolicyChoosePanel);
    add(securityPolicyChoosePanel);
    ObjectPolicyConfigurationEditor objectPolicyEditor = new ObjectPolicyConfigurationEditor(ID_OBJECT_POLICY_EDITOR, new PropertyModel<List<ObjectPolicyConfigurationTypeDto>>(getModel(), SystemConfigurationDto.F_OBJECT_POLICY_LIST));
    add(objectPolicyEditor);
    DropDownChoice<AEPlevel> aepLevel = new DropDownChoice<>(ID_GLOBAL_AEP, new PropertyModel<AEPlevel>(getModel(), SystemConfigurationDto.F_AEP_LEVEL), WebComponentUtil.createReadonlyModelFromEnum(AEPlevel.class), new EnumChoiceRenderer<AEPlevel>(SystemConfigPanel.this));
    aepLevel.setOutputMarkupId(true);
    if (aepLevel.getModel().getObject() == null) {
        aepLevel.getModel().setObject(null);
    }
    aepLevel.add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    add(aepLevel);
    TextField<String> auditRecordsField = WebComponentUtil.createAjaxTextField(ID_CLEANUP_AUDIT_RECORDS, new PropertyModel<String>(getModel(), SystemConfigurationDto.F_AUDIT_CLEANUP));
    TextField<String> closedTasksField = WebComponentUtil.createAjaxTextField(ID_CLEANUP_CLOSED_TASKS, new PropertyModel<String>(getModel(), SystemConfigurationDto.F_TASK_CLEANUP));
    add(auditRecordsField);
    add(closedTasksField);
    createTooltip(ID_CLEANUP_AUDIT_RECORDS_TOOLTIP);
    createTooltip(ID_CLEANUP_CLOSED_TASKS_TOOLTIP);
    CheckBox experimentalCodeCheck = WebComponentUtil.createAjaxCheckBox(ID_EXPERIMENTAL_CODE_CHECKBOX, new PropertyModel<Boolean>(getModel(), SystemConfigurationDto.F_ENABLE_EXPERIMENTAL_CODE));
    add(experimentalCodeCheck);
}
Also used : ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) AEPlevel(com.evolveum.midpoint.web.page.admin.configuration.dto.AEPlevel) SecurityPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) CheckBox(org.apache.wicket.markup.html.form.CheckBox) List(java.util.List) ObjectViewDto(com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto) ObjectPolicyConfigurationEditor(com.evolveum.midpoint.web.component.ObjectPolicyConfigurationEditor)

Example 27 with ValuePolicyType

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

the class SystemConfigurationDto method loadPasswordPolicy.

private ObjectViewDto<ValuePolicyType> loadPasswordPolicy(SystemConfigurationType config) {
    ValuePolicyType passPolicy = config.getGlobalPasswordPolicy();
    if (passPolicy != null) {
        passPolicyDto = new ObjectViewDto<>(passPolicy.getOid(), passPolicy.getName().getOrig());
    } else {
        passPolicyDto = new ObjectViewDto<>();
    }
    passPolicyDto.setType(ValuePolicyType.class);
    return passPolicyDto;
}
Also used : ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType)

Example 28 with ValuePolicyType

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

the class TestParsePasswordPolicy method testParsePasswordPolicyFile.

@Test
public void testParsePasswordPolicyFile() throws Exception {
    System.out.println("===[ testParsePasswordPolicyFile ]===");
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    // WHEN
    PrismObject<ValuePolicyType> policy = prismContext.parserFor(FILE).xml().parse();
    // THEN
    System.out.println("Parsed policy:");
    System.out.println(policy.debugDump());
    assertPolicy(policy);
}
Also used : ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) PrismContext(com.evolveum.midpoint.prism.PrismContext) Test(org.testng.annotations.Test)

Example 29 with ValuePolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType 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 30 with ValuePolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType 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

ValuePolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType)35 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)19 Test (org.testng.annotations.Test)14 Task (com.evolveum.midpoint.task.api.Task)12 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)8 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 File (java.io.File)7 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 StringPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)5 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 StringPolicyResolver (com.evolveum.midpoint.repo.common.expression.StringPolicyResolver)4 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)4 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)3