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 enhydrator by AdamBien.
the class ScriptableSink method init.
@Override
public void init() {
requireNonNull(this.scriptFile, "Cannot initialize ScriptableSink without script.");
try {
this.scriptContent = load(this.scriptFile);
} catch (IOException ex) {
throw new IllegalStateException("Cannot load script from: " + this.scriptFile, ex);
}
ScriptEngineManager sem = new ScriptEngineManager();
this.engine = sem.getEngineByName("javascript");
try {
this.engine.eval(this.scriptContent);
} catch (ScriptException ex) {
throw new IllegalStateException("Parsing script failed. Problem in line: " + ex.getLineNumber() + " and column: " + ex.getColumnNumber(), ex);
}
this.invocable = (Invocable) engine;
this.sink = this.invocable.getInterface(Sink.class);
requireNonNull(this.sink, "Sink instantiation failed - script: " + this.scriptContent + " is incompatible");
this.sink.init();
}
use of javax.script.ScriptException in project enhydrator by AdamBien.
the class FilterExpression method execute.
public Boolean execute(Row columns, String expression) {
Bindings bindings = ScriptingEnvironmentProvider.create(this.manager, this.scriptEngineBindings, columns);
try {
this.expressionListener.accept("Executing: " + expression);
Object result = this.engine.eval(expression, bindings);
this.expressionListener.accept("Got result: " + result);
if (!(result instanceof Boolean)) {
return Boolean.FALSE;
} else {
return (Boolean) result;
}
} catch (ScriptException ex) {
throw new IllegalStateException(ex.getMessage(), ex);
}
}
Aggregations