Search in sources :

Example 1 with ScriptCompilationException

use of org.keycloak.scripting.ScriptCompilationException in project keycloak by keycloak.

the class ScriptBasedOIDCProtocolMapper method validateConfig.

@Override
public void validateConfig(KeycloakSession session, RealmModel realm, ProtocolMapperContainerModel client, ProtocolMapperModel mapperModel) throws ProtocolMapperConfigException {
    String scriptCode = getScriptCode(mapperModel);
    if (scriptCode == null) {
        return;
    }
    ScriptingProvider scripting = session.getProvider(ScriptingProvider.class);
    ScriptModel scriptModel = scripting.createScript(realm.getId(), ScriptModel.TEXT_JAVASCRIPT, mapperModel.getName() + "-script", scriptCode, "");
    try {
        scripting.prepareEvaluatableScript(scriptModel);
    } catch (ScriptCompilationException ex) {
        throw new ProtocolMapperConfigException("error", "{0}", ex.getMessage());
    }
}
Also used : ScriptModel(org.keycloak.models.ScriptModel) ProtocolMapperConfigException(org.keycloak.protocol.ProtocolMapperConfigException) ScriptingProvider(org.keycloak.scripting.ScriptingProvider) ScriptCompilationException(org.keycloak.scripting.ScriptCompilationException)

Example 2 with ScriptCompilationException

use of org.keycloak.scripting.ScriptCompilationException in project keycloak by keycloak.

the class ScriptBasedMapper method validateConfig.

@Override
public void validateConfig(KeycloakSession session, RealmModel realm, ProtocolMapperContainerModel client, ProtocolMapperModel mapperModel) throws ProtocolMapperConfigException {
    String scriptCode = mapperModel.getConfig().get(ProviderConfigProperty.SCRIPT_TYPE);
    if (scriptCode == null) {
        return;
    }
    ScriptingProvider scripting = session.getProvider(ScriptingProvider.class);
    ScriptModel scriptModel = scripting.createScript(realm.getId(), ScriptModel.TEXT_JAVASCRIPT, mapperModel.getName() + "-script", scriptCode, "");
    try {
        scripting.prepareEvaluatableScript(scriptModel);
    } catch (ScriptCompilationException ex) {
        throw new ProtocolMapperConfigException("error", "{0}", ex.getMessage());
    }
}
Also used : ProtocolMapperConfigException(org.keycloak.protocol.ProtocolMapperConfigException) ScriptingProvider(org.keycloak.scripting.ScriptingProvider) ScriptCompilationException(org.keycloak.scripting.ScriptCompilationException)

Aggregations

ProtocolMapperConfigException (org.keycloak.protocol.ProtocolMapperConfigException)2 ScriptCompilationException (org.keycloak.scripting.ScriptCompilationException)2 ScriptingProvider (org.keycloak.scripting.ScriptingProvider)2 ScriptModel (org.keycloak.models.ScriptModel)1