Search in sources :

Example 1 with ProhibitedValueItemType

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

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

Example 3 with ProhibitedValueItemType

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

the class AbstractValuePolicyOriginResolver method handleProjections.

private <P extends ObjectType> void handleProjections(ResultHandler<P> handler, ProhibitedValueItemType prohibitedValueItemType, String contextDescription, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    // Not very efficient. We will usually read the shadows again, as they are already in model context.
    // It will also work only for the items that are stored in shadow (usually not attributes, unless caching is enabled).
    // But this is good enough for now.
    FocusType focus;
    if (object.canRepresent(FocusType.class)) {
        focus = (FocusType) object.asObjectable();
    } else if (object.canRepresent(ShadowType.class)) {
        if (object.getOid() == null) {
            // process only provided shadow or do not handle projection?
            return;
        }
        ObjectQuery query = object.getPrismContext().queryFor(FocusType.class).item(FocusType.F_LINK_REF).ref(object.getOid()).maxSize(1).build();
        try {
            List<PrismObject<FocusType>> objects = objectResolver.searchObjects(FocusType.class, query, createReadOnlyCollection(), task, result);
            if (objects.isEmpty()) {
                return;
            }
            focus = MiscUtil.extractSingleton(objects).asObjectable();
        } catch (CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
            throw new SystemException(e.getMessage(), e);
        }
    } else {
        return;
    }
    // We want to provide default intent to allow configurators to be a little lazy and skip intent specification.
    // Consider changing this if necessary.
    ResourceShadowDiscriminator shadowDiscriminator = ResourceShadowDiscriminator.fromResourceShadowDiscriminatorType(prohibitedValueItemType.getProjectionDiscriminator(), true);
    for (ObjectReferenceType linkRef : focus.getLinkRef()) {
        GetOperationOptions options = GetOperationOptions.createReadOnly();
        options.setNoFetch(true);
        ShadowType resolvedShadow = objectResolver.resolve(linkRef, ShadowType.class, SelectorOptions.createCollection(options), "resolving projection shadow in " + contextDescription, task, result);
        if (shadowDiscriminator != null) {
            if (!ShadowUtil.matches(resolvedShadow.asPrismObject(), shadowDiscriminator)) {
                LOGGER.trace("Skipping evaluation of projection {} in {} because it does not match discriminator", resolvedShadow, contextDescription);
                continue;
            }
        }
        // noinspection unchecked
        handler.handle((PrismObject<P>) resolvedShadow.asPrismObject(), result);
    }
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) List(java.util.List) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Aggregations

SystemException (com.evolveum.midpoint.util.exception.SystemException)3 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