Accessing Java Privileged Actions from within Rhino script
<p>How can I execute a local file from JavaScript running within Rhino in Java? I will consider any method that works from within the Rhino environment. My current exploration of the issue is below.</p>

<p>I am attempting this through java.lang.Runtime.exec, with help from the Mozilla "Scripting Java" tutorial i can access it. However this is a restricted action so calling it directly gives an access control exception.</p>

<p>To solve this I need to use the AccesController.doPrivileged method. An example of using this in Java is below;</p>

<pre><code>AccessController.doPrivileged(new PrivilegedAction() {
          public Object run() {
             // Code goes here. Any permission checks within this
             // run method will require that the intersection of the
             // callers protection domain and the snapshot's
             // context have the desired permission.
          }
</code></pre>

<p>The road block is replicating the construction of a PrivilegedAction in javascript. </p>

<pre><code>var ourRuntime = Packages.java.lang.Runtime.getRuntime();
//ourRuntime.exec("notepad.exe") //will raise Access Control Exception
var controller = Packages.java.security.AccessController.doPrivileged
var action = new Packages.java.security.PrivilegedAction(ourRuntime.exec("notepad.exe"))         // somehow make this wwrk
controller.doPrivileged(action)
</code></pre>

<p><a href="http://www.mozilla.org/rhino/ScriptingJava.html" rel="nofollow">Mozilla Scripting Java</a></p>

<p><a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/security/AccessController.html" rel="nofollow">java.securit.AccessController</a></p>
