.java.policy file and local applet
I am working on an HTML page that is using Javascript to interact with a Java applet. The HTML page, javascript files, and .jar file for the applet will be deployed locally to a folder on the user's filesystem.
(Implmenting this as a standalone Java application is not an option here; for various reasons I will not explain here).
The applet needs to do local file i/o. As such, I'm attempting to tweek the settings in the user's .java.policy file to permit this.
I have found the following setup is the only one that works:
grant
{
permission java.io.FilePermission "<<ALL FILES>>", "read";
permission java.io.FilePermission "<<ALL FILES>>", "write";
};
This is not ideal, as that it grants all applets permissions to read write all files. Naturally I would prefer to isolate to the particular code base. However I could not find a "grant codeBase" syntax that works.
I have tried:
grant codeBase "file:/C:/Files/FileIOApplet/-" {
permission java.io.FilePermission "<<ALL FILES>>", "read";
permission java.io.FilePermission "<<ALL FILES>>", "write";
};
grant codeBase "file:///-" {
permission java.io.FilePermission "<<ALL FILES>>", "read";
permission java.io.FilePermission "<<ALL FILES>>", "write";
};
grant codeBase "file:${user.home}/-"
{
permission java.io.FilePermission "<<ALL FILES>>", "read";
permission java.io.FilePermission "<<ALL FILES>>", "write";
};
This is running using this configuration:
- Firefox 3.6.10
- Java 1.6 update 25
- Wi开发者_Python百科ndows 7 64 bit
Where I am I going wrong in setting up this .java.policy file?
I am pretty rusty to the Java world, especially working with applets - so your expertise is appreciated!
To connect an Applet with access here are the policy tool settings:
Go to policyTool, you will find it in following path:
java->jdk1.3->bin->policyTool Application
There appears Policy Tool window.
In the Policy Tool window select the "Add Policy Entry" button.
This will take you to Policy Entry window
There enter the CodeBase as "file:/path of your java bin". For example
CodeBase file:/c:/java/jdk1.3/bin/
Now press "Add Permission" button in the Policy Entry window.
This will take you to the "Permissions" window
There Select "All permission" from permission drop down list box.
And click "ok".
Now again press the "Add Permission" button in the Policy Entry window.
Now Select "Select "RunTimepermission" from permission drop down list box.
Now in the Target Name drop down list box select "accessClassInpackage", in the text box enter accessClassInpackage.sun.jdbc.odbc
Now click "ok".
Now click "done" in "Policy Entry" window.
Now in the Policy Entry window file->save Save it in "bin" of your Java installation. Remember the name... for example say.. appletpermission 'save'
Now you have a created policy file for access
Now to compile your java file at the command prompt
javac programname.java
To run your program type the following at the cmd prompt:
appletviewer -J-Djava.security.policy=appletpermission programname.java
Now everything is done.
don't waste your time with syntax, use the policy tool instead :
click here : Policy Tool
精彩评论