use of javax.script.Bindings in project tomee by apache.
the class ScriptLoginModule method login.
@Override
public boolean login() throws LoginException {
File script = getScriptFile((String) this.options.get("scriptURI"));
if (script == null) {
script = getScriptFile(JavaSecurityManagers.getSystemProperty("openejb.ScriptLoginModule.scriptURI"));
if (script == null) {
script = getScriptFile(null);
}
}
if (script == null) {
throw new LoginException("No login script defined");
}
final String scriptText;
try {
scriptText = new Scanner(script).useDelimiter("\\Z").next();
} catch (final FileNotFoundException e) {
throw new LoginException("Invalid login script URI.");
}
this.userData = getUserData();
final ScriptEngineManager manager = new ScriptEngineManager();
final ScriptEngine engine = manager.getEngineByName((String) this.options.get("engineName"));
// new context for the execution of this script
final ScriptContext newContext = new SimpleScriptContext();
// creating the bidings object for the current execution
final Bindings bindings = newContext.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("user", this.userData.user);
bindings.put("password", this.userData.pass);
final List<String> myGroups;
try {
myGroups = (List) engine.eval(scriptText, newContext);
} catch (final ScriptException e) {
throw new LoginException("Cannot execute login script. Msg: " + e.getMessage());
}
this.userData.groups.addAll(myGroups);
return true;
}
use of javax.script.Bindings in project tomee by apache.
the class OpenEJBScripter method bindLocal.
private static void bindLocal(final ScriptContext context) {
final Bindings bindings = context.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("bm", new BeanManagerHelper());
}
use of javax.script.Bindings in project hazelcast by hazelcast.
the class HazelcastOSGiScriptEngineManagerTest method putAndGetOverBindingsSuccessfully.
@Test
public void putAndGetOverBindingsSuccessfully() {
ScriptEngineManager scriptEngineManager = ScriptEngineManagerContext.getScriptEngineManager();
Bindings bindings = scriptEngineManager.getBindings();
assertNull(bindings.get("my-key"));
bindings.put("my-key", "my-value");
assertEquals("my-value", bindings.get("my-key"));
}
use of javax.script.Bindings in project hazelcast by hazelcast.
the class HazelcastOSGiScriptEngineTest method verifyThatBindingsPutAndGetOverBindingsSuccessfully.
private void verifyThatBindingsPutAndGetOverBindingsSuccessfully(ScriptEngine scriptEngine) {
Bindings bindings = scriptEngine.createBindings();
assertNull(bindings.get("my-key"));
bindings.put("my-key", "my-value");
assertEquals("my-value", bindings.get("my-key"));
}
use of javax.script.Bindings in project hazelcast by hazelcast.
the class HazelcastOSGiScriptEngineTest method verifyScriptEngineEvaluation.
private void verifyScriptEngineEvaluation(ScriptEngine scriptEngine) throws ScriptException {
assertNotNull(scriptEngine.getFactory());
final String SCRIPT_SOURCE_WITH_VARIABLE = "\"I am \" + name";
final String SCRIPT_SOURCE_WITHOUT_VARIABLE = "\"I am human\"";
Bindings bindings = scriptEngine.createBindings();
bindings.put("name", "Serkan");
ScriptContext scriptContext = scriptEngine.getContext();
scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
assertEquals("I am Serkan", scriptEngine.eval(SCRIPT_SOURCE_WITH_VARIABLE, bindings));
assertEquals("I am Serkan", scriptEngine.eval(SCRIPT_SOURCE_WITH_VARIABLE, scriptContext));
assertEquals("I am human", scriptEngine.eval(SCRIPT_SOURCE_WITHOUT_VARIABLE));
assertEquals("I am Serkan", scriptEngine.eval(new StringReader(SCRIPT_SOURCE_WITH_VARIABLE), bindings));
assertEquals("I am Serkan", scriptEngine.eval(new StringReader(SCRIPT_SOURCE_WITH_VARIABLE), scriptContext));
assertEquals("I am human", scriptEngine.eval(new StringReader(SCRIPT_SOURCE_WITHOUT_VARIABLE)));
}
Aggregations