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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations