Search in sources :

Example 1 with SupportedScriptingLanguage

use of org.forgerock.openam.scripting.SupportedScriptingLanguage in project OpenAM by OpenRock.

the class ScriptResource method actionCollection.

@Override
public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request) {
    if ("validate".equals(request.getAction())) {
        try {
            JsonValue json = request.getContent();
            SupportedScriptingLanguage language = getLanguageFromString(json.get(SCRIPT_LANGUAGE).asString());
            String script = json.get(SCRIPT_TEXT).asString();
            if (script == null) {
                throw new ScriptException(MISSING_SCRIPT);
            }
            List<ScriptError> scriptErrorList = scriptValidator.validateScript(new ScriptObject(EMPTY, decodeScript(script), language, null));
            if (scriptErrorList.isEmpty()) {
                return newResultPromise(newActionResponse(json(object(field("success", true)))));
            }
            Set<Object> errors = new HashSet<>();
            for (ScriptError error : scriptErrorList) {
                errors.add(object(field("line", error.getLineNumber()), field("column", error.getColumnNumber()), field("message", error.getMessage())));
            }
            return newResultPromise(newActionResponse(json(object(field("success", false), field("errors", errors)))));
        } catch (ScriptException se) {
            return exceptionMappingHandler.handleError(context, request, se).asPromise();
        }
    } else {
        return new NotSupportedException().asPromise();
    }
}
Also used : ScriptException(org.forgerock.openam.scripting.ScriptException) ScriptObject(org.forgerock.openam.scripting.ScriptObject) ScriptError(org.forgerock.openam.scripting.ScriptError) JsonValue(org.forgerock.json.JsonValue) ScriptObject(org.forgerock.openam.scripting.ScriptObject) SupportedScriptingLanguage(org.forgerock.openam.scripting.SupportedScriptingLanguage) NotSupportedException(org.forgerock.json.resource.NotSupportedException) HashSet(java.util.HashSet)

Example 2 with SupportedScriptingLanguage

use of org.forgerock.openam.scripting.SupportedScriptingLanguage in project OpenAM by OpenRock.

the class OidcClaimsExtensionTest method setupScript.

@BeforeClass
public void setupScript() throws Exception {
    String rawScript = IOUtils.readStream(this.getClass().getClassLoader().getResourceAsStream("oidc-claims-extension.groovy"));
    SupportedScriptingLanguage scriptType = SupportedScriptingLanguage.GROOVY;
    this.script = new ScriptObject("oidc-claims-script", rawScript, scriptType, null);
    StandardScriptEngineManager scriptEngineManager = new StandardScriptEngineManager();
    scriptEngineManager.registerEngineName(SupportedScriptingLanguage.GROOVY_ENGINE_NAME, new GroovyScriptEngineFactory());
    scriptEvaluator = new StandardScriptEvaluator(scriptEngineManager);
}
Also used : StandardScriptEngineManager(org.forgerock.openam.scripting.StandardScriptEngineManager) StandardScriptEvaluator(org.forgerock.openam.scripting.StandardScriptEvaluator) ScriptObject(org.forgerock.openam.scripting.ScriptObject) GroovyScriptEngineFactory(org.codehaus.groovy.jsr223.GroovyScriptEngineFactory) SupportedScriptingLanguage(org.forgerock.openam.scripting.SupportedScriptingLanguage) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

ScriptObject (org.forgerock.openam.scripting.ScriptObject)2 SupportedScriptingLanguage (org.forgerock.openam.scripting.SupportedScriptingLanguage)2 HashSet (java.util.HashSet)1 GroovyScriptEngineFactory (org.codehaus.groovy.jsr223.GroovyScriptEngineFactory)1 JsonValue (org.forgerock.json.JsonValue)1 NotSupportedException (org.forgerock.json.resource.NotSupportedException)1 ScriptError (org.forgerock.openam.scripting.ScriptError)1 ScriptException (org.forgerock.openam.scripting.ScriptException)1 StandardScriptEngineManager (org.forgerock.openam.scripting.StandardScriptEngineManager)1 StandardScriptEvaluator (org.forgerock.openam.scripting.StandardScriptEvaluator)1 BeforeClass (org.testng.annotations.BeforeClass)1