use of com.evolveum.midpoint.schema.expression.ExpressionProfile in project midpoint by Evolveum.
the class ValuePolicyProcessor method validateValue.
public List<StringLimitationResult> validateValue(String newValue, ValuePolicyType pp, ObjectBasedValuePolicyOriginResolver<?> originResolver, List<LocalizableMessage> messages, String shortDesc, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
// TODO: do we want to throw exception when no value policy defined??
Validate.notNull(pp, "Value policy must not be null.");
OperationResult result = parentResult.createSubresult(OPERATION_STRING_POLICY_VALIDATION);
result.addArbitraryObjectAsParam("policyName", pp.getName());
List<StringLimitationResult> limitations = new ArrayList<>();
try {
normalize(pp);
if (newValue == null) {
newValue = "";
}
LimitationsType lims = pp.getStringPolicy().getLimitations();
CollectionUtils.addIgnoreNull(limitations, testLength(newValue, lims, result, messages));
CollectionUtils.addIgnoreNull(limitations, testMinimalUniqueCharacters(newValue, lims, result, messages));
CollectionUtils.addIgnoreNull(limitations, testProhibitedValues(newValue, pp.getProhibitedValues(), originResolver, shortDesc, task, result, messages));
// TODO: this needs to be determined from ValuePolicyType archetype
ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
limitations.addAll(testCheckExpression(newValue, lims, expressionProfile, originResolver, shortDesc, task, result, messages));
if (!lims.getLimit().isEmpty()) {
// check limitation
HashSet<String> validChars;
HashSet<String> allValidChars = new HashSet<>();
List<String> characters = StringPolicyUtils.stringTokenizer(newValue);
for (StringLimitType stringLimitationType : lims.getLimit()) {
OperationResult limitResult = new OperationResult("Tested limitation: " + stringLimitationType.getDescription());
validChars = getValidCharacters(stringLimitationType.getCharacterClass(), pp);
int count = countValidCharacters(validChars, characters);
allValidChars.addAll(validChars);
StringLimitationResult limitation = null;
limitation = testMinimalOccurrence(stringLimitationType, count, limitResult, messages, limitation);
limitation = testMaximalOccurrence(stringLimitationType, count, limitResult, messages, limitation);
limitation = testMustBeFirst(stringLimitationType, limitResult, messages, newValue, validChars, limitation);
if (limitation != null) {
PolyStringType name = stringLimitationType.getName();
if (name == null) {
name = new PolyStringType(stringLimitationType.getDescription());
PolyStringTranslationType translation = new PolyStringTranslationType();
translation.setKey(stringLimitationType.getDescription());
name.setTranslation(translation);
}
PolyStringType help = new PolyStringType(getCharsetAsString(validChars));
limitation.setHelp(help);
limitation.setName(name);
limitations.add(limitation);
}
limitResult.computeStatus();
result.addSubresult(limitResult);
}
CollectionUtils.addIgnoreNull(limitations, testInvalidCharacters(characters, allValidChars, result, messages));
}
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
if (!result.isSuccess() && !messages.isEmpty()) {
result.setUserFriendlyMessage(new LocalizableMessageListBuilder().messages(messages).separator(LocalizableMessageList.SPACE).buildOptimized());
}
return limitations;
}
use of com.evolveum.midpoint.schema.expression.ExpressionProfile in project midpoint by Evolveum.
the class TestExpression method compileExpressionProfile.
protected ExpressionProfile compileExpressionProfile(String profileName) throws SchemaException, IOException {
if (profileName == null) {
return null;
}
PrismObject<SystemConfigurationType> systemConfig = PrismTestUtil.parseObject(getSystemConfigurationFile());
SystemConfigurationExpressionsType expressions = systemConfig.asObjectable().getExpressions();
if (expressions == null) {
throw new SchemaException("No expressions in system config");
}
ExpressionProfileCompiler compiler = new ExpressionProfileCompiler();
ExpressionProfiles profiles = compiler.compile(expressions);
ExpressionProfile profile = profiles.getProfile(profileName);
if (profile == null) {
throw new SchemaException("Profile '" + profileName + "' not found in system config");
}
return profile;
}
use of com.evolveum.midpoint.schema.expression.ExpressionProfile in project midpoint by Evolveum.
the class ExpressionProfileCompiler method compileExpressionProfile.
private ExpressionProfile compileExpressionProfile(ExpressionProfileType expressionProfileType, List<ExpressionPermissionProfile> permissionProfiles) throws SchemaException {
ExpressionProfile profile = new ExpressionProfile(expressionProfileType.getIdentifier());
profile.setDecision(AccessDecision.translate(expressionProfileType.getDecision()));
for (ExpressionEvaluatorProfileType evaluatorType : expressionProfileType.getEvaluator()) {
profile.add(compileEvaluatorProfile(evaluatorType, permissionProfiles));
}
return profile;
}
use of com.evolveum.midpoint.schema.expression.ExpressionProfile in project midpoint by Evolveum.
the class SynchronizationExpressionsEvaluator method findFocusesByCorrelationRule.
@NotNull
public <F extends FocusType> List<PrismObject<F>> findFocusesByCorrelationRule(Class<F> focusType, ShadowType currentShadow, List<ConditionalSearchFilterType> conditionalFilters, ResourceType resourceType, SystemConfigurationType configurationType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
if (conditionalFilters == null || conditionalFilters.isEmpty()) {
LOGGER.warn("Correlation rule for resource '{}' doesn't contain query, " + "returning empty list of users.", resourceType);
return emptyList();
}
// TODO: determine from the resource
ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
List<PrismObject<F>> allUsers = new ArrayList<>();
for (ConditionalSearchFilterType conditionalFilter : conditionalFilters) {
// TODO: better description
if (satisfyCondition(currentShadow, conditionalFilter, expressionProfile, resourceType, configurationType, "Condition expression", task, result)) {
LOGGER.trace("Condition {} in correlation expression evaluated to true", conditionalFilter.getCondition());
List<PrismObject<F>> usersFound = findFocusesByCorrelationRule(focusType, currentShadow, conditionalFilter, expressionProfile, resourceType, configurationType, task, result);
for (PrismObject<F> userFound : usersFound) {
if (!contains(allUsers, userFound)) {
allUsers.add(userFound);
}
}
}
}
LOGGER.debug("SYNCHRONIZATION: CORRELATION: expression for {} returned {} users: {}", currentShadow, allUsers.size(), PrettyPrinter.prettyPrint(allUsers, 3));
return allUsers;
}
use of com.evolveum.midpoint.schema.expression.ExpressionProfile in project midpoint by Evolveum.
the class ScriptingExpressionEvaluator method evaluateExpression.
private ExecutionContext evaluateExpression(@NotNull ExecuteScriptType executeScript, VariablesMap initialVariables, boolean privileged, boolean recordProgressAndIterationStatistics, Task task, OperationResult result) throws ScriptExecutionException {
Validate.notNull(executeScript.getScriptingExpression(), "Scripting expression must be present");
ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
try {
VariablesMap frozenVariables = VariablesUtil.initialPreparation(initialVariables, executeScript.getVariables(), expressionFactory, modelObjectResolver, prismContext, expressionProfile, task, result);
PipelineData pipelineData = PipelineData.parseFrom(executeScript.getInput(), frozenVariables, prismContext);
ExecutionContext context = new ExecutionContext(executeScript.getOptions(), task, this, privileged, recordProgressAndIterationStatistics, frozenVariables);
PipelineData output = evaluateExpression(executeScript.getScriptingExpression().getValue(), pipelineData, context, result);
context.setFinalOutput(output);
result.computeStatusIfUnknown();
context.computeResults();
return context;
} catch (ExpressionEvaluationException | SchemaException | ObjectNotFoundException | RuntimeException | CommunicationException | ConfigurationException | SecurityViolationException e) {
result.recordFatalError("Couldn't execute script", e);
throw new ScriptExecutionException("Couldn't execute script: " + e.getMessage(), e);
} catch (Throwable t) {
result.recordFatalError("Couldn't execute script", t);
throw t;
}
}
Aggregations