3

我正在使用 Javascript 与 Java 小程序交互的 HTML 页面。小程序的 HTML 页面、javascript 文件和 .jar 文件将在本地部署到用户文件系统上的文件夹中。

(将其实现为独立的 Java 应用程序在这里不是一个选项;由于各种原因,我不会在这里解释)。

小程序需要做本地文件 i/o。因此,我试图调整用户 .java.policy 文件中的设置以允许这样做。

我发现以下设置是唯一有效的设置:

grant 
{
  permission java.io.FilePermission "<<ALL FILES>>", "read";
  permission java.io.FilePermission "<<ALL FILES>>", "write";
};

这并不理想,因为它授予所有小程序读写所有文件的权限。自然,我更愿意隔离到特定的代码库。但是我找不到有效的“grant codeBase”语法。

我努力了:

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";
};

这是使用此配置运行的:

  • 火狐 3.6.10
  • Java 1.6 更新 25
  • 视窗 7 64 位

在设置这个 .java.policy 文件时我哪里出错了?

我对 Java 世界非常生疏,尤其是在使用小程序时——因此感谢您的专业知识!

4

2 回答 2

4

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.

于 2012-10-06T15:45:07.860 回答
0

不要在语法上浪费时间,请改用策略工具:

点击这里:政策工具

于 2011-06-24T14:20:31.583 回答