Search in sources :

Example 6 with LimitationsType

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

the class SchemaTransformer method applyObjectTemplateItem.

private <IV extends PrismValue, ID extends ItemDefinition> void applyObjectTemplateItem(ID itemDef, ObjectTemplateItemDefinitionType templateItemDefType, String desc) throws SchemaException {
    if (itemDef == null) {
        throw new SchemaException("No definition for " + desc);
    }
    String displayName = templateItemDefType.getDisplayName();
    if (displayName != null) {
        ((ItemDefinitionImpl) itemDef).setDisplayName(displayName);
    }
    Integer displayOrder = templateItemDefType.getDisplayOrder();
    if (displayOrder != null) {
        ((ItemDefinitionImpl) itemDef).setDisplayOrder(displayOrder);
    }
    Boolean emphasized = templateItemDefType.isEmphasized();
    if (emphasized != null) {
        ((ItemDefinitionImpl) itemDef).setEmphasized(emphasized);
    }
    List<PropertyLimitationsType> limitations = templateItemDefType.getLimitations();
    if (limitations != null) {
        PropertyLimitationsType limitationsType = MiscSchemaUtil.getLimitationsType(limitations, LayerType.PRESENTATION);
        if (limitationsType != null) {
            if (limitationsType.getMinOccurs() != null) {
                ((ItemDefinitionImpl) itemDef).setMinOccurs(XsdTypeMapper.multiplicityToInteger(limitationsType.getMinOccurs()));
            }
            if (limitationsType.getMaxOccurs() != null) {
                ((ItemDefinitionImpl) itemDef).setMaxOccurs(XsdTypeMapper.multiplicityToInteger(limitationsType.getMaxOccurs()));
            }
            if (limitationsType.isIgnore() != null) {
                ((ItemDefinitionImpl) itemDef).setIgnored(limitationsType.isIgnore());
            }
            PropertyAccessType accessType = limitationsType.getAccess();
            if (accessType != null) {
                if (accessType.isAdd() != null) {
                    ((ItemDefinitionImpl) itemDef).setCanAdd(accessType.isAdd());
                }
                if (accessType.isModify() != null) {
                    ((ItemDefinitionImpl) itemDef).setCanModify(accessType.isModify());
                }
                if (accessType.isRead() != null) {
                    ((ItemDefinitionImpl) itemDef).setCanRead(accessType.isRead());
                }
            }
        }
    }
    ObjectReferenceType valueEnumerationRef = templateItemDefType.getValueEnumerationRef();
    if (valueEnumerationRef != null) {
        PrismReferenceValue valueEnumerationRVal = MiscSchemaUtil.objectReferenceTypeToReferenceValue(valueEnumerationRef);
        ((ItemDefinitionImpl) itemDef).setValueEnumerationRef(valueEnumerationRVal);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PropertyAccessType(com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyAccessType) PropertyLimitationsType(com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyLimitationsType)

Example 7 with LimitationsType

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

the class RefinedAttributeDefinitionImpl method isIgnored.

static boolean isIgnored(ResourceAttributeDefinitionType attrDefType) throws SchemaException {
    List<PropertyLimitationsType> limitations = attrDefType.getLimitations();
    if (limitations == null) {
        return false;
    }
    PropertyLimitationsType limitationsType = MiscSchemaUtil.getLimitationsType(limitations, DEFAULT_LAYER);
    if (limitationsType == null) {
        return false;
    }
    if (limitationsType.isIgnore() == null) {
        return false;
    }
    return limitationsType.isIgnore();
}
Also used : PropertyLimitationsType(com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyLimitationsType)

Example 8 with LimitationsType

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

Example 9 with LimitationsType

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

the class ValuePolicyProcessor method generate.

public String generate(ItemPath path, ValuePolicyType policy, int defaultLength, boolean generateMinimalSize, ObjectBasedValuePolicyOriginResolver<?> originResolver, String shortDesc, Task task, OperationResult parentResult) throws ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    Context ctx = new Context(path != null ? path : SchemaConstants.PATH_PASSWORD_VALUE);
    OperationResult result = parentResult.createSubresult(OP_GENERATE);
    if (policy == null) {
        // lets create some default policy
        policy = new ValuePolicyType().stringPolicy(new StringPolicyType().limitations(new LimitationsType().maxLength(defaultLength).minLength(defaultLength)));
    }
    StringPolicyType stringPolicy = policy.getStringPolicy();
    int maxAttempts = DEFAULT_MAX_ATTEMPTS;
    if (stringPolicy.getLimitations() != null && stringPolicy.getLimitations().getMaxAttempts() != null) {
        maxAttempts = stringPolicy.getLimitations().getMaxAttempts();
    }
    if (maxAttempts < 1) {
        ExpressionEvaluationException e = new ExpressionEvaluationException("Illegal number of maximum value generation attempts: " + maxAttempts);
        result.recordFatalError(e);
        throw e;
    }
    String generatedValue;
    int attempt = 1;
    for (; ; ) {
        generatedValue = generateAttempt(policy, defaultLength, generateMinimalSize, ctx, result);
        if (result.isError()) {
            throw new ExpressionEvaluationException(result.getMessage());
        }
        // TODO: this needs to be determined from ValuePolicyType archetype
        ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
        if (checkAttempt(generatedValue, policy, expressionProfile, originResolver, shortDesc, task, result)) {
            break;
        }
        LOGGER.trace("Generator attempt {}: check failed", attempt);
        if (attempt == maxAttempts) {
            ExpressionEvaluationException e = new ExpressionEvaluationException("Unable to generate value, maximum number of attempts (" + maxAttempts + ") exceeded");
            result.recordFatalError(e);
            throw e;
        }
        attempt++;
    }
    return generatedValue;
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) StringPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LimitationsType(com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 LimitationsType (com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType)5 CheckExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.CheckExpressionType)3 StringLimitationResult (com.evolveum.midpoint.model.api.validator.StringLimitationResult)2 ExpressionProfile (com.evolveum.midpoint.schema.expression.ExpressionProfile)2 ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)2 PropertyLimitationsType (com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyLimitationsType)2 StringLimitType (com.evolveum.midpoint.xml.ns._public.common.common_3.StringLimitType)2 PolyStringTranslationType (com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)2 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 LocalizableMessage (com.evolveum.midpoint.util.LocalizableMessage)1 LocalizableMessageListBuilder (com.evolveum.midpoint.util.LocalizableMessageListBuilder)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 CharacterClassType (com.evolveum.midpoint.xml.ns._public.common.common_3.CharacterClassType)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 PropertyAccessType (com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyAccessType)1 StringPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType)1 ValuePolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType)1