* cmdline options for lifting sandbox restrictions in scripting shell

This commit is contained in:
Reinhard Pointner 2011-11-05 01:16:05 +00:00
parent f3912a9eee
commit 6b964043fb
3 changed files with 12 additions and 2 deletions

View File

@ -61,6 +61,9 @@ public class ArgumentBean {
@Option(name = "-script", usage = "Run Groovy script")
public String script = null;
@Option(name = "-trust-script", usage = "Lift scripting restrictions")
public boolean trustScript = false;
@Option(name = "--log", usage = "Log level", metaVar = "[all, config, info, warning]")
public String log = "all";

View File

@ -89,7 +89,7 @@ public class ArgumentProcessor {
bindings.put("args", args.getFiles(false));
Analytics.trackEvent("CLI", "ExecuteScript", args.getScriptLocation().getProtocol());
ScriptShell shell = new ScriptShell(cli, args, AccessController.getContext());
ScriptShell shell = new ScriptShell(cli, args, args.trustScript, AccessController.getContext());
shell.evaluate(script, bindings);
}

View File

@ -34,9 +34,12 @@ import net.sourceforge.filebot.web.MovieIdentificationService;
class ScriptShell {
private final ScriptEngine engine = new GroovyScriptEngineFactory().getScriptEngine();
private final boolean trustScript;
public ScriptShell(CmdlineInterface cli, ArgumentBean args, AccessControlContext acc) throws ScriptException {
public ScriptShell(CmdlineInterface cli, ArgumentBean args, boolean trustScript, AccessControlContext acc) throws ScriptException {
this.trustScript = trustScript;
// setup script context
ScriptContext context = new SimpleScriptContext();
context.setBindings(initializeBindings(cli, args, acc), ScriptContext.GLOBAL_SCOPE);
@ -67,6 +70,10 @@ class ScriptShell {
public Object evaluate(final String script, final Bindings bindings) throws Exception {
if (trustScript) {
return engine.eval(script, bindings);
}
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {