.java.policy 文件和本地小程序

发布于 2024-11-08 20:23:10 字数 1323 浏览 5 评论 0原文

我正在开发一个 HTML 页面,该页面使用 Javascript 与 Java 小程序交互。小程序的 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";
};

这是使用以下配置运行的:

  • Firefox 3.6.10
  • Java 1.6 update 25
  • Windows 7 64 位

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

我对 Java 世界相当生疏,尤其是使用小程序 - 所以非常感谢您的专业知识!

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
  • Windows 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞄了个咪的 2024-11-15 20:23:10

要连接具有访问权限的 Applet,这里是策略工具设置:

转到策略工具,您将在以下路径中找到它:

java->jdk1.3->bin->policyTool Application

出现策略工具窗口。
在策略工具窗口中选择“添加策略条目”按钮。
这将带您进入策略输入窗口,

在其中输入代码库“file:/java bin 的路径”。例如

CodeBase   file:/c:/java/jdk1.3/bin/

,现在按“策略输入”窗口中的“添加权限”按钮。
这将带您进入“权限”窗口

,从权限下拉列表框中选择“所有权限”。
然后单击“确定”。

现在再次按策略条目窗口中的“添加权限”按钮。

现在选择“从权限下拉列表框中选择“RunTimepermission”。
现在在 Target Name 下拉列表框中选择“accessClassInpackage”,在文本框中输入 accessClassInpackage.sun.jdbc.odbc

现在单击“ok”。

现在单击“策略输入”窗口中的“完成”。

现在在策略输入窗口文件->保存
将其保存在 Java 安装的“bin”中。
记住名字...
例如说..
小程序权限
'save'

现在您已经创建了可供访问的策略文件

现在可以在命令提示符处编译 java 文件

javac programname.java

要运行您的程序,请在 cmd 提示符处键入以下内容:

appletviewer -J-Djava.security.policy=appletpermission programname.java

现在一切都已完成。

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.

晨敛清荷 2024-11-15 20:23:10

不要在语法上浪费时间,而是使用策略工具:

点击此处:政策工具

don't waste your time with syntax, use the policy tool instead :

click here : Policy Tool

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文