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);
}
}
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;
}
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
}
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());
}
}
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");
}
}
Aggregations