aspose file tools
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 Head First Android this week in the Android 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
Rancher

Joined: Mar 22, 2005
Posts: 42956
    
  73
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.
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
Rancher

Joined: Mar 22, 2005
Posts: 42956
    
  73
You can try putting the code in a privileged section, as discussed in http://faq.javaranch.com/java/HowCanAnAppletReadFilesOnTheLocalFileSystem
 
Don't get me started about those stupid light bulbs.
 
subject: Java AccessControlException : Access Denied (Java.io.fileSystem) error while running Applet from JS
 
It's not a secret anymore!