• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try putting the code in a privileged section, as discussed in http://faq.javaranch.com/java/HowCanAnAppletReadFilesOnTheLocalFileSystem
 
My, my, aren't you a big fella. Here, have a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic