wood burning stoves 2.0*
The moose likes Applets and the fly likes Java AccessControlException : Access Denied (Java.io.fileSystem) error while running Applet from JS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Java AccessControlException : Access Denied (Java.io.fileSystem) error while running Applet from JS" Watch "Java AccessControlException : Access Denied (Java.io.fileSystem) error while running Applet from JS" New topic
Author

Java AccessControlException : Access Denied (Java.io.fileSystem) error while running Applet from JS

Bob Mathews
Ranch Hand

Joined: Feb 26, 2006
Posts: 43
Hi all Ranchers,

I am trying to run an Applet from Javascript/HTML.
Applet has to run one bat file on the filesystem.

And while running Runtime.exec(), Applet is giving

java.security.AccessControlException: access denied (java.io.FilePermission C:\Project\main\win32\bin\init.bat 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 ReExecutionApplet.reExecute(ReExecutionApplet.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.invoke.JSInvoke.invoke(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
at sun.plugin.com.MethodDispatcher.invoke(Unknown Source)
at sun.plugin.com.DispatchImpl.invokeImpl(Unknown Source)
at sun.plugin.com.DispatchImpl$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.com.DispatchImpl.invoke(Unknown Source)
java.lang.Exception: java.security.AccessControlException: access denied (java.io.FilePermission C:\Project\main\win32\bin\init.bat execute)
at sun.plugin.com.DispatchImpl.invokeImpl(Unknown Source)
at sun.plugin.com.DispatchImpl$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.com.DispatchImpl.invoke(Unknown Source)


Now as this html containg applet has to be run by multiple users I cannot expect each of them to change the java.policy file.

Here is the HTML applet tag and Js

<applet archive="SSignedReExecution.jar" code="ReExecutionApplet.class" name="reExecuteApplet" id="reExecuteApplet" width="0" height="0" mayscript="true">
</applet>

and JavaScript is

document.reExecuteApplet.reExecute(arguments,configLabel.innerHTML);

And the Aapllet code is :

String cmdArgs = "C:\\Project\\main\\win32\\bin\\init.cmd --configId "+configId+" ";

try
{
Runtime.getRuntime().exec(cmdArgs);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}



Applet is a Signed Jar files.

And here is the process to sign.

keytool -genkey
keytool -selfcert
keytool -export
jarsigner

Once the jar is signed I have copied the signed jar and the .crt file to the deployment folder


I have been banging my head for this error for 2-3 days now but still no luck.


Please let me know if any one of you can help me resolve this.


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41085
    
  43
When you run the applet, are you getting the little popup window that asks you to accept the certificate? If not, then the applet isn't signed correctly. Also, you don't by any chance have loose class files in the deployment directory in addition to the jar file?

The .crt file is not needed for the deployment.

I assume the discrepancy between init.cmd and init.bat is just a typo.


Ping & DNS - my free Android networking tools app
Bob Mathews
Ranch Hand

Joined: Feb 26, 2006
Posts: 43
Thanks for reply Ulf

I get the pop up message as you have mentioned so the jar file is signed properly.

There are no open class files in the deployment dir

But still the problem persists.


Any other thoughts will be highly appreciated.



Thanks,
Bob







Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41085
    
  43
You can try putting the code in a privileged section, as discussed in http://faq.javaranch.com/java/HowCanAnAppletReadFilesOnTheLocalFileSystem
 
wood burning stoves
 
subject: Java AccessControlException : Access Denied (Java.io.fileSystem) error while running Applet from JS
 
Similar Threads
Signed Applet retuns Java.security.AccessControlException
InvalidAlgorithmParameter Exception
print Screen from a jsp
JSP having problem accessing signed .jar
AccessControlException is thrown when a signed applet is trying to read a file from local system