Note that there are some explanatory texts on larger screens.

plurals
  1. POSigned Java Applet gives AccessControlException when calling from JavaScript
    text
    copied!<p>First of all I'm aware that my question is same as <a href="https://stackoverflow.com/questions/1068271/signed-applet-gives-accesscontrolexception-access-denied-when-calling-from-jav">in here</a>. But that question did not helped me.</p> <p>I have self signed applet.</p> <pre><code>jarsigner -verify sJSApplet.jar jar verified. Warning: This jar contains entries whose signer certificate will expire within six months. </code></pre> <p>Applet's purpose is to open MS Word document from LAN machine. So far I've tried opening using <code>Desktop.open()</code> and <code>Runtime.exec()</code>. With <code>AccessController.doPrivileged</code> and without. I always get <code>java.security.AccessControlException: access denied</code>. </p> <p>I'm out of options. What else I could do?</p> <p>I cannot use java.policy file.</p> <p><strong>HTML</strong></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script&gt; function openFile( command ) { var applet = "&lt;object type='application/x-java-applet' height='100' width='100' name='jsApplet'&gt;&lt;param name='code' value='com.avacoda.swing.JSApplet'/&gt;&lt;param name='archive' value='sJSApplet.jar' /&gt;&lt;param name='mayscript' value='true'/&gt;&lt;param name='filePath' value='C:\\note.txt'/&gt;Applet failed to run. No Java plug-in was found.&lt;/object&gt;"; var body = document.getElementsByTagName("body")[0]; var div = document.createElement("div"); div.innerHTML = applet; body.appendChild(div); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;a href="#" onclick="openFile('C:/note.txt');"&gt;Open file&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>Java code:</strong></p> <pre><code>public class WordApplet extends JApplet { @Override public void init() { openFile(getParameter("filePath")); }; public void openFile(final String path) { AccessController.doPrivileged(new PrivilegedAction&lt;Object&gt;() { @Override public Object run() { try { Runtime.getRuntime().exec("winword " + path); //Desktop.getDesktop().open(new File(path)); } catch (Exception e) { e.printStackTrace(); } return null; } }); } } </code></pre> <p><strong>Full stack trace</strong></p> <pre><code>java.security.AccessControlException: access denied (java.io.FilePermission &lt;&lt;ALL FILES&gt;&gt; execute) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkExec(Unknown Source) at java.lang.ProcessBuilder.start(Unknown Source) at java.lang.Runtime.exec(Unknown Source) at java.lang.Runtime.exec(Unknown Source) at java.lang.Runtime.exec(Unknown Source) at com.test.applet.JSApplet$1.run(JSApplet.java:34) at java.security.AccessController.doPrivileged(Native Method) at com.avacoda.swing.JSApplet.openFile(JSApplet.java:29) at com.avacoda.swing.JSApplet.init(JSApplet.java:25) at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Unknown Source) basic: Applet initialized </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload