Search in sources :

Example 1 with CheckExpressionType

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

the class ValuePolicyProcessor method testCheckExpression.

private <O extends ObjectType> void testCheckExpression(String newPassword, LimitationsType lims, PrismObject<O> object, String shortDesc, Task task, OperationResult result, StringBuilder message) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    List<CheckExpressionType> checkExpressions = lims.getCheckExpression();
    if (checkExpressions.isEmpty()) {
        return;
    }
    for (CheckExpressionType checkExpression : checkExpressions) {
        ExpressionType expressionType = checkExpression.getExpression();
        if (expressionType == null) {
            return;
        }
        if (!checkExpression(newPassword, expressionType, object, shortDesc, task, result)) {
            String msg = checkExpression.getFailureMessage();
            if (msg == null) {
                msg = "Check expression failed";
            }
            result.addSubresult(new OperationResult("Check expression", OperationResultStatus.FATAL_ERROR, msg));
            message.append(msg);
            message.append("\n");
        }
    }
}
Also used : CheckExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CheckExpressionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CheckExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CheckExpressionType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)

Example 2 with CheckExpressionType

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

the class ValuePolicyProcessor method checkAttempt.

private <O extends ObjectType> boolean checkAttempt(String generatedValue, StringPolicyType policy, PrismObject<O> object, String shortDesc, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    LimitationsType limitationsType = policy.getLimitations();
    if (limitationsType == null) {
        return true;
    }
    List<CheckExpressionType> checkExpressionTypes = limitationsType.getCheckExpression();
    if (!checkExpressions(generatedValue, checkExpressionTypes, object, shortDesc, task, result)) {
        LOGGER.trace("Check expression returned false for generated value in {}", shortDesc);
        return false;
    }
    // TODO Check pattern
    return true;
}
Also used : CheckExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CheckExpressionType) LimitationsType(com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType)

Example 3 with CheckExpressionType

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

the class ValuePolicyProcessor method testCheckExpression.

private List<StringLimitationResult> testCheckExpression(String newPassword, LimitationsType lims, ExpressionProfile expressionProfile, ObjectBasedValuePolicyOriginResolver<?> originResolver, String shortDesc, Task task, OperationResult result, List<LocalizableMessage> messages) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    List<StringLimitationResult> limitations = new ArrayList<>();
    for (CheckExpressionType checkExpression : lims.getCheckExpression()) {
        ExpressionType expressionType = checkExpression.getExpression();
        if (expressionType == null) {
            continue;
        }
        StringLimitationResult limitation = new StringLimitationResult();
        PolyStringType name = null;
        if (checkExpression.getDisplay() != null) {
            name = checkExpression.getDisplay().getLabel();
            limitation.setHelp(checkExpression.getDisplay().getHelp());
        }
        if (name == null) {
            name = new PolyStringType("Check expression");
            PolyStringTranslationType translation = new PolyStringTranslationType();
            translation.setKey("ValuePolicy.checkExpression");
            name.setTranslation(translation);
        }
        limitation.setName(name);
        limitation.setSuccess(true);
        if (!checkExpression(newPassword, expressionType, expressionProfile, originResolver, shortDesc, task, result)) {
            LocalizableMessage msg;
            if (checkExpression.getLocalizableFailureMessage() != null) {
                msg = LocalizationUtil.toLocalizableMessage(checkExpression.getLocalizableFailureMessage());
            } else if (checkExpression.getFailureMessage() != null) {
                msg = LocalizableMessageBuilder.buildFallbackMessage(checkExpression.getFailureMessage());
            } else {
                msg = LocalizableMessageBuilder.buildKey("ValuePolicy.checkExpressionFailed");
            }
            result.addSubresult(new OperationResult("Check expression", OperationResultStatus.FATAL_ERROR, msg));
            messages.add(msg);
            limitation.setSuccess(false);
        }
        limitations.add(limitation);
    }
    return limitations;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) CheckExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CheckExpressionType) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CheckExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CheckExpressionType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)

Aggregations

CheckExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.CheckExpressionType)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)2 StringLimitationResult (com.evolveum.midpoint.model.api.validator.StringLimitationResult)1 LocalizableMessage (com.evolveum.midpoint.util.LocalizableMessage)1 LimitationsType (com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType)1 PolyStringTranslationType (com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)1 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)1