Search in sources :

Example 11 with LocalizableMessageBuilder

use of com.evolveum.midpoint.util.LocalizableMessageBuilder 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 12 with LocalizableMessageBuilder

use of com.evolveum.midpoint.util.LocalizableMessageBuilder in project midpoint by Evolveum.

the class ValuePolicyProcessor method testMustBeFirst.

private StringLimitationResult testMustBeFirst(StringLimitType stringLimitation, OperationResult result, List<LocalizableMessage> messages, String value, Set<String> validFirstChars, StringLimitationResult limitation) {
    if (stringLimitation.isMustBeFirst() == null) {
        return limitation;
    }
    if (limitation == null) {
        limitation = new StringLimitationResult();
        limitation.setMustBeFirst(stringLimitation.isMustBeFirst());
        limitation.setSuccess(StringUtils.isNotEmpty(value));
    } else {
        limitation.setMustBeFirst(stringLimitation.isMustBeFirst());
    }
    if (StringUtils.isNotEmpty(value) && isTrue(stringLimitation.isMustBeFirst()) && !validFirstChars.contains(value.substring(0, 1))) {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.firstCharacterNotAllowed").arg(validFirstChars.toString()).build();
        result.addSubresult(new OperationResult("Check valid first char", OperationResultStatus.FATAL_ERROR, msg));
        messages.add(msg);
        limitation.setSuccess(false);
    }
    return limitation;
}
Also used : StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder)

Example 13 with LocalizableMessageBuilder

use of com.evolveum.midpoint.util.LocalizableMessageBuilder in project midpoint by Evolveum.

the class ValuePolicyProcessor method testInvalidCharacters.

private StringLimitationResult testInvalidCharacters(List<String> valueCharacters, HashSet<String> validChars, OperationResult result, List<LocalizableMessage> message) {
    StringBuilder invalidCharacters = new StringBuilder();
    for (String character : valueCharacters) {
        if (!validChars.contains(character)) {
            invalidCharacters.append(character);
        }
    }
    StringLimitationResult limitation = new StringLimitationResult();
    PolyStringType name = new PolyStringType("invalid characters");
    PolyStringTranslationType translation = new PolyStringTranslationType();
    translation.setKey("ValuePolicy.invalidCharacters");
    name.setTranslation(translation);
    limitation.setName(name);
    PolyStringType help = new PolyStringType(getCharsetAsString(validChars));
    limitation.setHelp(help);
    limitation.setSuccess(true);
    if (invalidCharacters.length() > 0) {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.charactersNotAllowed").arg(invalidCharacters).build();
        result.addSubresult(new OperationResult("Check if value does not contain invalid characters", OperationResultStatus.FATAL_ERROR, msg));
        message.add(msg);
        limitation.setSuccess(false);
    }
    return limitation;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)

Example 14 with LocalizableMessageBuilder

use of com.evolveum.midpoint.util.LocalizableMessageBuilder in project midpoint by Evolveum.

the class CollectionProcessor method evaluatePolicyRule.

/**
 * Very simple implementation, needs to be extended later.
 */
@NotNull
private EvaluatedPolicyRule evaluatePolicyRule(PrismObject<ObjectCollectionType> collection, CompiledObjectCollectionView collectionView, @NotNull AssignmentType assignmentType, @NotNull PolicyRuleType policyRuleType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, ConfigurationException, CommunicationException, ExpressionEvaluationException {
    AssignmentPathImpl assignmentPath = new AssignmentPathImpl();
    AssignmentPathSegmentImpl assignmentPathSegment = new AssignmentPathSegmentImpl.Builder().source(collection.asObjectable()).sourceDescription("object collection " + collection).assignment(assignmentType).isAssignment(true).evaluationOrder(EvaluationOrderImpl.zero(relationRegistry)).evaluationOrderForTarget(EvaluationOrderImpl.zero(relationRegistry)).direct(// to be reconsidered - but assignment path is empty, so we consider this to be directly assigned
    true).pathToSourceValid(true).pathToSourceConditionState(ConditionState.allTrue()).build();
    assignmentPath.add(assignmentPathSegment);
    // Generated proforma - actually not much needed for now.
    String ruleId = PolicyRuleTypeUtil.createId(collection.getOid(), assignmentType.getId());
    EvaluatedPolicyRuleImpl evaluatedPolicyRule = new EvaluatedPolicyRuleImpl(policyRuleType.clone(), ruleId, assignmentPath, null);
    PolicyConstraintsType policyConstraints = policyRuleType.getPolicyConstraints();
    if (policyConstraints == null) {
        return evaluatedPolicyRule;
    }
    PolicyThresholdType policyThreshold = policyRuleType.getPolicyThreshold();
    for (CollectionStatsPolicyConstraintType collectionStatsPolicy : policyConstraints.getCollectionStats()) {
        CollectionStats stats = determineCollectionStats(collectionView, task, result);
        if (isThresholdTriggered(stats, collection, policyThreshold)) {
            EvaluatedPolicyRuleTrigger<?> trigger = new EvaluatedCollectionStatsTrigger(PolicyConstraintKindType.COLLECTION_STATS, collectionStatsPolicy, new LocalizableMessageBuilder().key(SchemaConstants.DEFAULT_POLICY_CONSTRAINT_KEY_PREFIX + CONSTRAINT_KEY).arg(ObjectTypeUtil.createDisplayInformation(collection, false)).args().build(), new LocalizableMessageBuilder().key(SchemaConstants.DEFAULT_POLICY_CONSTRAINT_SHORT_MESSAGE_KEY_PREFIX + CONSTRAINT_KEY).arg(ObjectTypeUtil.createDisplayInformation(collection, false)).args().build());
            evaluatedPolicyRule.addTrigger(trigger);
        }
    }
    return evaluatedPolicyRule;
}
Also used : LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) AssignmentPathSegmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.AssignmentPathSegmentImpl) EvaluatedPolicyRuleImpl(com.evolveum.midpoint.model.impl.lens.EvaluatedPolicyRuleImpl) EvaluatedCollectionStatsTrigger(com.evolveum.midpoint.model.api.context.EvaluatedCollectionStatsTrigger) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) AssignmentPathImpl(com.evolveum.midpoint.model.impl.lens.assignments.AssignmentPathImpl) CollectionStats(com.evolveum.midpoint.model.api.CollectionStats) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with LocalizableMessageBuilder

use of com.evolveum.midpoint.util.LocalizableMessageBuilder in project midpoint by Evolveum.

the class ValuePolicyProcessor method testLength.

private StringLimitationResult testLength(String value, LimitationsType limitations, OperationResult result, List<LocalizableMessage> messages) {
    if (limitations.getMinLength() == null && limitations.getMaxLength() == null) {
        return null;
    }
    StringLimitationResult limitation = new StringLimitationResult();
    limitation.setMinOccurs(limitations.getMinLength());
    limitation.setMaxOccurs(limitations.getMaxLength());
    PolyStringType name = new PolyStringType("characters");
    PolyStringTranslationType translation = new PolyStringTranslationType();
    translation.setKey("ValuePolicy.characters");
    name.setTranslation(translation);
    limitation.setName(name);
    limitation.setSuccess(true);
    if (limitations.getMinLength() != null && value.length() < limitations.getMinLength()) {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.minimalSizeNotMet").arg(limitations.getMinLength()).arg(value.length()).build();
        result.addSubresult(new OperationResult("Check global minimal length", OperationResultStatus.FATAL_ERROR, msg));
        messages.add(msg);
        limitation.setSuccess(false);
    }
    if (limitations.getMaxLength() != null && value.length() > limitations.getMaxLength()) {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.maximalSizeExceeded").arg(limitations.getMaxLength()).arg(value.length()).build();
        result.addSubresult(new OperationResult("Check global maximal length", OperationResultStatus.FATAL_ERROR, msg));
        messages.add(msg);
        limitation.setSuccess(false);
    }
    return limitation;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)

Aggregations

LocalizableMessageBuilder (com.evolveum.midpoint.util.LocalizableMessageBuilder)24 LocalizableMessage (com.evolveum.midpoint.util.LocalizableMessage)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)11 StringLimitationResult (com.evolveum.midpoint.model.api.validator.StringLimitationResult)7 NotNull (org.jetbrains.annotations.NotNull)7 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 PolyStringTranslationType (com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)4 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)3 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)3 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)3 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 EvaluatedPolicyRule (com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule)2 EvaluatedSituationTrigger (com.evolveum.midpoint.model.api.context.EvaluatedSituationTrigger)2 EvaluatedAssignmentImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl)2 AssignmentPolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext)2 PolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleEvaluationContext)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2