Search in sources :

Example 1 with ScriptExpressionProfile

use of com.evolveum.midpoint.schema.expression.ScriptExpressionProfile in project midpoint by Evolveum.

the class ExpressionProfileCompiler method compileScriptProfile.

private ScriptExpressionProfile compileScriptProfile(ScriptExpressionProfileType scriptType, List<ExpressionPermissionProfile> permissionProfiles) throws SchemaException {
    ScriptExpressionProfile profile = new ScriptExpressionProfile(scriptType.getLanguage());
    profile.setDecision(AccessDecision.translate(scriptType.getDecision()));
    profile.setTypeChecking(scriptType.isTypeChecking());
    profile.setPermissionProfile(findPermissionProfile(permissionProfiles, scriptType.getPermissionProfile()));
    return profile;
}
Also used : ScriptExpressionProfile(com.evolveum.midpoint.schema.expression.ScriptExpressionProfile)

Example 2 with ScriptExpressionProfile

use of com.evolveum.midpoint.schema.expression.ScriptExpressionProfile in project midpoint by Evolveum.

the class AbstractScriptTest method getExpressionProfile.

protected ExpressionProfile getExpressionProfile(ScriptExpressionProfile scriptExpressionProfile) {
    if (scriptExpressionProfile == null) {
        return null;
    }
    ExpressionProfile expressionProfile = new ExpressionProfile(this.getClass().getSimpleName());
    expressionProfile.setDecision(AccessDecision.DENY);
    ExpressionEvaluatorProfile evaluatorProfile = new ExpressionEvaluatorProfile(ScriptExpressionEvaluatorFactory.ELEMENT_NAME);
    expressionProfile.add(evaluatorProfile);
    evaluatorProfile.setDecision(AccessDecision.DENY);
    evaluatorProfile.add(scriptExpressionProfile);
    return expressionProfile;
}
Also used : ExpressionEvaluatorProfile(com.evolveum.midpoint.schema.expression.ExpressionEvaluatorProfile) ScriptExpressionProfile(com.evolveum.midpoint.schema.expression.ScriptExpressionProfile) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile)

Example 3 with ScriptExpressionProfile

use of com.evolveum.midpoint.schema.expression.ScriptExpressionProfile in project midpoint by Evolveum.

the class AbstractScriptTest method createScriptExpression.

private ScriptExpression createScriptExpression(ScriptExpressionEvaluatorType expressionType, ItemDefinition<?> outputDefinition) {
    String language = expressionType.getLanguage();
    ScriptExpression expression = new ScriptExpression(scriptExpressionfactory.getEvaluators().get(language), expressionType);
    expression.setOutputDefinition(outputDefinition);
    expression.setObjectResolver(scriptExpressionfactory.getObjectResolver());
    expression.setFunctions(new ArrayList<>(scriptExpressionfactory.getFunctions()));
    ScriptExpressionProfile scriptExpressionProfile = getScriptExpressionProfile(language);
    expression.setScriptExpressionProfile(scriptExpressionProfile);
    expression.setExpressionProfile(getExpressionProfile(scriptExpressionProfile));
    return expression;
}
Also used : ScriptExpressionProfile(com.evolveum.midpoint.schema.expression.ScriptExpressionProfile)

Example 4 with ScriptExpressionProfile

use of com.evolveum.midpoint.schema.expression.ScriptExpressionProfile in project midpoint by Evolveum.

the class TestGroovyExpressionsSandbox method getScriptExpressionProfile.

@Override
protected ScriptExpressionProfile getScriptExpressionProfile(String language) {
    ScriptExpressionProfile profile = new ScriptExpressionProfile(language);
    profile.setTypeChecking(true);
    ExpressionPermissionProfile permissionProfile = new ExpressionPermissionProfile(this.getClass().getSimpleName());
    profile.setPermissionProfile(permissionProfile);
    permissionProfile.addClassAccessRule(Poison.class, AccessDecision.ALLOW);
    permissionProfile.addClassAccessRule(Poison.class, "smell", AccessDecision.DENY);
    permissionProfile.addClassAccessRule(Poison.class, "drink", AccessDecision.DENY);
    permissionProfile.addClassAccessRule(String.class, AccessDecision.ALLOW);
    permissionProfile.addClassAccessRule(String.class, "execute", AccessDecision.DENY);
    permissionProfile.addClassAccessRule(List.class, AccessDecision.ALLOW);
    permissionProfile.addClassAccessRule(List.class, "execute", AccessDecision.DENY);
    permissionProfile.setDecision(AccessDecision.ALLOW);
    return profile;
}
Also used : ExpressionPermissionProfile(com.evolveum.midpoint.schema.expression.ExpressionPermissionProfile) ScriptExpressionProfile(com.evolveum.midpoint.schema.expression.ScriptExpressionProfile)

Example 5 with ScriptExpressionProfile

use of com.evolveum.midpoint.schema.expression.ScriptExpressionProfile in project midpoint by Evolveum.

the class ScriptExpressionFactory method processScriptExpressionProfile.

private ScriptExpressionProfile processScriptExpressionProfile(ExpressionProfile expressionProfile, String language, String shortDesc) throws SecurityViolationException {
    if (expressionProfile == null) {
        return null;
    }
    ExpressionEvaluatorProfile evaluatorProfile = expressionProfile.getEvaluatorProfile(ScriptExpressionEvaluatorFactory.ELEMENT_NAME);
    if (evaluatorProfile == null) {
        if (expressionProfile.getDecision() == AccessDecision.ALLOW) {
            return null;
        } else {
            throw new SecurityViolationException("Access to script expression evaluator " + " not allowed (expression profile: " + expressionProfile.getIdentifier() + ") in " + shortDesc);
        }
    }
    ScriptExpressionProfile scriptProfile = evaluatorProfile.getScriptExpressionProfile(language);
    if (scriptProfile == null) {
        if (evaluatorProfile.getDecision() == AccessDecision.ALLOW) {
            return null;
        } else {
            throw new SecurityViolationException("Access to script language " + language + " not allowed (expression profile: " + expressionProfile.getIdentifier() + ") in " + shortDesc);
        }
    }
    return scriptProfile;
}
Also used : SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ExpressionEvaluatorProfile(com.evolveum.midpoint.schema.expression.ExpressionEvaluatorProfile) ScriptExpressionProfile(com.evolveum.midpoint.schema.expression.ScriptExpressionProfile)

Aggregations

ScriptExpressionProfile (com.evolveum.midpoint.schema.expression.ScriptExpressionProfile)7 ExpressionEvaluatorProfile (com.evolveum.midpoint.schema.expression.ExpressionEvaluatorProfile)2 AccessDecision (com.evolveum.midpoint.schema.AccessDecision)1 ExpressionPermissionProfile (com.evolveum.midpoint.schema.expression.ExpressionPermissionProfile)1 ExpressionProfile (com.evolveum.midpoint.schema.expression.ExpressionProfile)1 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)1 GroovyClassLoader (groovy.lang.GroovyClassLoader)1