Search in sources :

Example 1 with ProhibitedValuesType

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

the class ValuePolicyProcessor method testProhibitedValues.

private StringLimitationResult testProhibitedValues(String newPassword, ProhibitedValuesType prohibitedValuesType, ObjectBasedValuePolicyOriginResolver<?> originResolver, String shortDesc, Task task, OperationResult result, List<LocalizableMessage> messages) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    if (prohibitedValuesType == null || originResolver == null) {
        return null;
    }
    StringLimitationResult limitation = new StringLimitationResult();
    PolyStringType name = new PolyStringType("prohibited value");
    PolyStringTranslationType translation = new PolyStringTranslationType();
    translation.setKey("ValuePolicy.prohibitedValueName");
    name.setTranslation(translation);
    limitation.setName(name);
    PolyStringType help = new PolyStringType("");
    PolyStringTranslationType helpTranslation = new PolyStringTranslationType();
    helpTranslation.setKey("ValuePolicy.prohibitedValue");
    help.setTranslation(helpTranslation);
    limitation.setHelp(help);
    limitation.setSuccess(true);
    Consumer<ProhibitedValueItemType> failAction = (prohibitedItemType) -> {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.prohibitedValue").build();
        result.addSubresult(new OperationResult("Prohibited value", OperationResultStatus.FATAL_ERROR, msg));
        messages.add(msg);
        limitation.setSuccess(false);
    };
    checkProhibitedValues(newPassword, prohibitedValuesType, originResolver, failAction, shortDesc, task, result);
    return limitation;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) StringUtils(org.apache.commons.lang.StringUtils) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionConstants(com.evolveum.midpoint.schema.constants.ExpressionConstants) StringLimitType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringLimitType) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) LimitationsType(com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) LocalizableMessageList(com.evolveum.midpoint.util.LocalizableMessageList) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) LocalizationUtil(com.evolveum.midpoint.schema.util.LocalizationUtil) StringPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType) Task(com.evolveum.midpoint.task.api.Task) MutablePrismPropertyDefinition(com.evolveum.midpoint.prism.MutablePrismPropertyDefinition) CheckExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CheckExpressionType) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ExpressionUtil(com.evolveum.midpoint.repo.common.expression.ExpressionUtil) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) BooleanUtils.isTrue(org.apache.commons.lang3.BooleanUtils.isTrue) NotNull(org.jetbrains.annotations.NotNull) Validate(org.apache.commons.lang.Validate) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) StrBuilder(org.apache.commons.lang.text.StrBuilder) java.util(java.util) CharacterClassType(com.evolveum.midpoint.xml.ns._public.common.common_3.CharacterClassType) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) CollectionUtils(org.apache.commons.collections4.CollectionUtils) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ProhibitedValueItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProhibitedValueItemType) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) PrismContext(com.evolveum.midpoint.prism.PrismContext) PrimitiveType(com.evolveum.midpoint.prism.PrimitiveType) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) PrismObject(com.evolveum.midpoint.prism.PrismObject) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Consumer(java.util.function.Consumer) LocalizableMessageListBuilder(com.evolveum.midpoint.util.LocalizableMessageListBuilder) Component(org.springframework.stereotype.Component) ItemName(com.evolveum.midpoint.prism.path.ItemName) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) Protector(com.evolveum.midpoint.prism.crypto.Protector) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) ProhibitedValuesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProhibitedValuesType) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ProhibitedValueItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProhibitedValueItemType) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)

Example 2 with ProhibitedValuesType

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

the class ValuePolicyProcessor method checkProhibitedValues.

private <O extends ObjectType, R extends ObjectType> boolean checkProhibitedValues(String newPassword, ProhibitedValuesType prohibitedValuesType, ObjectBasedValuePolicyOriginResolver<O> originResolver, Consumer<ProhibitedValueItemType> failAction, String shortDesc, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    if (prohibitedValuesType == null || originResolver == null) {
        return true;
    }
    MutableBoolean isAcceptable = new MutableBoolean(true);
    for (ProhibitedValueItemType prohibitedItemType : prohibitedValuesType.getItem()) {
        ItemPathType itemPathType = prohibitedItemType.getPath();
        if (itemPathType == null) {
            throw new SchemaException("No item path defined in prohibited item in " + shortDesc);
        }
        ItemPath itemPath = itemPathType.getItemPath();
        ResultHandler<R> handler = (object, objectResult) -> {
            PrismProperty<Object> objectProperty = object.findProperty(itemPath);
            if (objectProperty == null) {
                return true;
            }
            if (isMatching(newPassword, objectProperty)) {
                if (failAction != null) {
                    failAction.accept(prohibitedItemType);
                }
                isAcceptable.setValue(false);
                return false;
            }
            return true;
        };
        originResolver.resolve(prohibitedItemType, handler, shortDesc, task, result);
    }
    return isAcceptable.booleanValue();
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionConstants(com.evolveum.midpoint.schema.constants.ExpressionConstants) StringLimitType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringLimitType) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) LimitationsType(com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) LocalizableMessageList(com.evolveum.midpoint.util.LocalizableMessageList) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) LocalizationUtil(com.evolveum.midpoint.schema.util.LocalizationUtil) StringPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType) Task(com.evolveum.midpoint.task.api.Task) MutablePrismPropertyDefinition(com.evolveum.midpoint.prism.MutablePrismPropertyDefinition) CheckExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CheckExpressionType) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ExpressionUtil(com.evolveum.midpoint.repo.common.expression.ExpressionUtil) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) BooleanUtils.isTrue(org.apache.commons.lang3.BooleanUtils.isTrue) NotNull(org.jetbrains.annotations.NotNull) Validate(org.apache.commons.lang.Validate) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) StrBuilder(org.apache.commons.lang.text.StrBuilder) java.util(java.util) CharacterClassType(com.evolveum.midpoint.xml.ns._public.common.common_3.CharacterClassType) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) CollectionUtils(org.apache.commons.collections4.CollectionUtils) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ProhibitedValueItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProhibitedValueItemType) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) PrismContext(com.evolveum.midpoint.prism.PrismContext) PrimitiveType(com.evolveum.midpoint.prism.PrimitiveType) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) PrismObject(com.evolveum.midpoint.prism.PrismObject) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Consumer(java.util.function.Consumer) LocalizableMessageListBuilder(com.evolveum.midpoint.util.LocalizableMessageListBuilder) Component(org.springframework.stereotype.Component) ItemName(com.evolveum.midpoint.prism.path.ItemName) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) Protector(com.evolveum.midpoint.prism.crypto.Protector) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) ProhibitedValuesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProhibitedValuesType) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) ProhibitedValueItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProhibitedValueItemType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

StringLimitationResult (com.evolveum.midpoint.model.api.validator.StringLimitationResult)2 MutablePrismPropertyDefinition (com.evolveum.midpoint.prism.MutablePrismPropertyDefinition)2 PrimitiveType (com.evolveum.midpoint.prism.PrimitiveType)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 PrismObjectDefinition (com.evolveum.midpoint.prism.PrismObjectDefinition)2 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)2 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)2 Protector (com.evolveum.midpoint.prism.crypto.Protector)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)2 ExpressionUtil (com.evolveum.midpoint.repo.common.expression.ExpressionUtil)2 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)2 ExpressionConstants (com.evolveum.midpoint.schema.constants.ExpressionConstants)2 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)2 ExpressionProfile (com.evolveum.midpoint.schema.expression.ExpressionProfile)2 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 OperationResultStatus (com.evolveum.midpoint.schema.result.OperationResultStatus)2