Search in sources :

Example 1 with ScriptException

use of javax.script.ScriptException in project zipkin by openzipkin.

the class ZipkinMySQLContainer method containerIsStarted.

@Override
protected void containerIsStarted(InspectContainerResponse containerInfo) {
    String[] scripts = { // Drop all previously created tables in zipkin.*
    "drop_zipkin_tables.sql", // Populate the schema
    "mysql.sql" };
    try (Connection connection = dataSource.getConnection()) {
        for (String script : scripts) {
            URL scriptURL = Resources.getResource(script);
            String statements = Resources.toString(scriptURL, Charset.defaultCharset());
            ScriptUtils.executeSqlScript(connection, script, statements);
        }
    } catch (SQLException | IOException | ScriptException e) {
        throw new RuntimeException(e);
    }
}
Also used : ScriptException(javax.script.ScriptException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) IOException(java.io.IOException) URL(java.net.URL)

Example 2 with ScriptException

use of javax.script.ScriptException in project OpenAM by OpenRock.

the class RhinoScriptEngine method eval.

/**
     * {@inheritDoc}
     */
@Override
public Object eval(final Reader reader, final ScriptContext scriptContext) throws ScriptException {
    Reject.ifNull(reader, scriptContext);
    Object result = null;
    final Context context = factory.getContext();
    try {
        final Scriptable scope = getScope(context, scriptContext);
        final String filename = getFilename(scriptContext);
        result = context.evaluateReader(scope, reader, filename, 1, null);
    } catch (RhinoException ex) {
        throw convertException(ex);
    } catch (IOException ex) {
        throw new ScriptException(ex);
    } finally {
        factory.releaseContext(context);
    }
    return result;
}
Also used : Context(org.mozilla.javascript.Context) ScriptContext(javax.script.ScriptContext) ScriptException(javax.script.ScriptException) ScriptableObject(org.mozilla.javascript.ScriptableObject) RhinoException(org.mozilla.javascript.RhinoException) IOException(java.io.IOException) Scriptable(org.mozilla.javascript.Scriptable)

Example 3 with ScriptException

use of javax.script.ScriptException in project OpenAM by OpenRock.

the class RhinoCompiledScriptTest method shouldPropagateExceptions.

@Test(expectedExceptions = ScriptException.class)
public void shouldPropagateExceptions() throws ScriptException {
    // Given
    ScriptContext context = mock(ScriptContext.class);
    given(mockEngine.evalCompiled(mockScript, context)).willThrow(new ScriptException("test exception"));
    // When
    testScript.eval(context);
// Then - exception
}
Also used : ScriptException(javax.script.ScriptException) ScriptContext(javax.script.ScriptContext) Test(org.testng.annotations.Test)

Example 4 with ScriptException

use of javax.script.ScriptException in project OpenAM by OpenRock.

the class OpenAMScopeValidator method getUserInfo.

/**
     * {@inheritDoc}
     */
public UserInfoClaims getUserInfo(AccessToken token, OAuth2Request request) throws UnauthorizedClientException, NotFoundException {
    Map<String, Object> response = new HashMap<>();
    Bindings scriptVariables = new SimpleBindings();
    SSOToken ssoToken = getUsersSession(request);
    String realm;
    Set<String> scopes;
    AMIdentity id;
    OAuth2ProviderSettings providerSettings = providerSettingsFactory.get(request);
    Map<String, Set<String>> requestedClaimsValues = gatherRequestedClaims(providerSettings, request, token);
    try {
        if (token != null) {
            OpenIdConnectClientRegistration clientRegistration;
            try {
                clientRegistration = clientRegistrationStore.get(token.getClientId(), request);
            } catch (InvalidClientException e) {
                logger.message("Unable to retrieve client from store.");
                throw new NotFoundException("No valid client registration found.");
            }
            final String subId = clientRegistration.getSubValue(token.getResourceOwnerId(), providerSettings);
            //data comes from token when we have one
            realm = token.getRealm();
            scopes = token.getScope();
            id = identityManager.getResourceOwnerIdentity(token.getResourceOwnerId(), realm);
            response.put(OAuth2Constants.JWTTokenParams.SUB, subId);
            response.put(OAuth2Constants.JWTTokenParams.UPDATED_AT, getUpdatedAt(token.getResourceOwnerId(), token.getRealm(), request));
        } else {
            //otherwise we're simply reading claims into the id_token, so grab it from the request/ssoToken
            realm = DNMapper.orgNameToRealmName(ssoToken.getProperty(ISAuthConstants.ORGANIZATION));
            id = identityManager.getResourceOwnerIdentity(ssoToken.getProperty(ISAuthConstants.USER_ID), realm);
            String scopeStr = request.getParameter(OAuth2Constants.Params.SCOPE);
            scopes = splitScope(scopeStr);
        }
        scriptVariables.put(OAuth2Constants.ScriptParams.SCOPES, getScriptFriendlyScopes(scopes));
        scriptVariables.put(OAuth2Constants.ScriptParams.IDENTITY, id);
        scriptVariables.put(OAuth2Constants.ScriptParams.LOGGER, logger);
        scriptVariables.put(OAuth2Constants.ScriptParams.CLAIMS, response);
        scriptVariables.put(OAuth2Constants.ScriptParams.SESSION, ssoToken);
        scriptVariables.put(OAuth2Constants.ScriptParams.REQUESTED_CLAIMS, requestedClaimsValues);
        ScriptObject script = getOIDCClaimsExtensionScript(realm);
        try {
            return scriptEvaluator.evaluateScript(script, scriptVariables);
        } catch (ScriptException e) {
            logger.message("Error running OIDC claims script", e);
            throw new ServerException("Error running OIDC claims script: " + e.getMessage());
        }
    } catch (ServerException e) {
        //API does not allow ServerExceptions to be thrown!
        throw new NotFoundException(e.getMessage());
    } catch (SSOException e) {
        throw new NotFoundException(e.getMessage());
    }
}
Also used : ScriptObject(org.forgerock.openam.scripting.ScriptObject) OpenIdConnectClientRegistration(org.forgerock.openidconnect.OpenIdConnectClientRegistration) SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) HashSet(java.util.HashSet) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) SSOException(com.iplanet.sso.SSOException) SimpleBindings(javax.script.SimpleBindings) Bindings(javax.script.Bindings) ScriptException(javax.script.ScriptException) SimpleBindings(javax.script.SimpleBindings) AMIdentity(com.sun.identity.idm.AMIdentity) InvalidClientException(org.forgerock.oauth2.core.exceptions.InvalidClientException) JSONObject(org.json.JSONObject) ScriptObject(org.forgerock.openam.scripting.ScriptObject) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings)

Example 5 with ScriptException

use of javax.script.ScriptException in project OpenAM by OpenRock.

the class Scripted method process.

/**
     * {@inheritDoc}
     */
@Override
public int process(Callback[] callbacks, int state) throws LoginException {
    switch(state) {
        case ISAuthConstants.LOGIN_START:
            substituteUIStrings();
            return STATE_RUN_SCRIPT;
        case STATE_RUN_SCRIPT:
            Bindings scriptVariables = new SimpleBindings();
            scriptVariables.put(REQUEST_DATA_VARIABLE_NAME, getScriptHttpRequestWrapper());
            String clientScriptOutputData = getClientScriptOutputData(callbacks);
            scriptVariables.put(CLIENT_SCRIPT_OUTPUT_DATA_VARIABLE_NAME, clientScriptOutputData);
            scriptVariables.put(LOGGER_VARIABLE_NAME, DEBUG);
            scriptVariables.put(STATE_VARIABLE_NAME, state);
            scriptVariables.put(SHARED_STATE, sharedState);
            scriptVariables.put(USERNAME_VARIABLE_NAME, userName);
            scriptVariables.put(SUCCESS_ATTR_NAME, SUCCESS_VALUE);
            scriptVariables.put(FAILED_ATTR_NAME, FAILURE_VALUE);
            scriptVariables.put(HTTP_CLIENT_VARIABLE_NAME, httpClient);
            scriptVariables.put(IDENTITY_REPOSITORY, identityRepository);
            try {
                scriptEvaluator.evaluateScript(getServerSideScript(), scriptVariables);
            } catch (ScriptException e) {
                DEBUG.message("Error running server side scripts", e);
                throw new AuthLoginException("Error running script", e);
            }
            state = ((Number) scriptVariables.get(STATE_VARIABLE_NAME)).intValue();
            userName = (String) scriptVariables.get(USERNAME_VARIABLE_NAME);
            sharedState.put(CLIENT_SCRIPT_OUTPUT_DATA_VARIABLE_NAME, clientScriptOutputData);
            if (state != SUCCESS_VALUE) {
                throw new AuthLoginException("Authentication failed");
            }
            return state;
        default:
            throw new AuthLoginException("Invalid state");
    }
}
Also used : ScriptException(javax.script.ScriptException) SimpleBindings(javax.script.SimpleBindings) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) Bindings(javax.script.Bindings) SimpleBindings(javax.script.SimpleBindings)

Aggregations

ScriptException (javax.script.ScriptException)300 ScriptEngine (javax.script.ScriptEngine)115 IOException (java.io.IOException)84 ScriptEngineManager (javax.script.ScriptEngineManager)59 Bindings (javax.script.Bindings)57 Invocable (javax.script.Invocable)40 File (java.io.File)32 CompiledScript (javax.script.CompiledScript)31 InputStreamReader (java.io.InputStreamReader)26 Reader (java.io.Reader)23 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)23 Map (java.util.Map)21 ScriptContext (javax.script.ScriptContext)19 SimpleBindings (javax.script.SimpleBindings)18 FileReader (java.io.FileReader)15 PrintWriter (java.io.PrintWriter)15 Compilable (javax.script.Compilable)14 StringWriter (java.io.StringWriter)12 URL (java.net.URL)10