Java 需要客户端访问资源权限的小程序的策略文件位置在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1417271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 11:52:01  来源:igfitidea点击:

where policy file location for my applet that needs clients permission to access resource?

javasecuritypermissionsapplet

提问by sirvan

i find out that i must write a policy file to grant permission for my applet...

我发现我必须编写一个策略文件来为我的小程序授予权限...

but i really confused with it... :(

但我真的很困惑...... :(

i want to write a applet that is a map viewer, i need to save image tiles on client that run my applet to locally access tiles for gain speed and time safely viewing map which is benefit to user...

我想编写一个地图查看器小程序,我需要在客户端上保存图像图块,这些图块运行我的小程序以本地访问图块,以获得安全查看地图的速度和时间,这对用户有好处...

so, the applet needs grant permission to read/write and make directory on client tempdir.

因此,小程序需要授予在客户端 tempdir 上读/写和创建目录的权限。

now, i want to write a policy file to gain permission to my applet,i don't want to involve the users to this,instead of, i want to write policy file by myself to grant permission for applet...

现在,我想编写一个策略文件来获得对我的小程序的权限,我不想让用户参与其中,而不是,我想自己编写策略文件来授予对小程序的权限...

now where is the policy file location? in applet jar file? how the applet use policy file?

现在策略文件位置在哪里?在小程序 jar 文件中?小程序如何使用策略文件?

please help me

请帮我

回答by ZZ Coder

Simple answer is no, you can't change the policy remotely. Where is the security if you can just override the policy on user's machine?

简单的答案是否定的,您不能远程更改策略。如果您可以覆盖用户机器上的策略,那么安全性在哪里?

In an enterprise environment, this is possible through desktop management/provisioning systems. If you want test that, you can update the policy file manually. It's located here on Windows,

在企业环境中,这可以通过桌面管理/供应系统实现。如果您想对此进行测试,您可以手动更新策略文件。它位于 Windows 上,

  ${user.home}\java.policy
  ${java.home}\lib\security\java.policy

The first one changes policy for a single user and the second one affects the whole system.

第一个更改单个用户的策略,第二个影响整个系统。

回答by Omry Yadan

using the policy file is not a good idea because it's too complicated for users to edit. instead, you should obtain a certificate (costs $200 - $400/year) and sign your applet. will allow you to access files.

使用策略文件不是一个好主意,因为它太复杂了,用户无法编辑。相反,您应该获得证书(每年花费 200 到 400 美元)并签署您的小程序。将允许您访问文件。

you can try a test certificate you can generate for free. Thismay help.

您可以尝试免费生成的测试证书。 可能会有所帮助。

回答by Keibosh

You need to sign your applet then wrap the file operations in a privileged block of code like this.

您需要对您的小程序进行签名,然后将文件操作包装在像这样的特权代码块中。

            final String location = locationVal;

    File f = (File) AccessController.doPrivileged(new PrivilegedAction()
    {
        public Object run()
        {
            System.out.println("Getting File : " + location);
            File outputFile1 = new File(location);
            return outputFile1;
        }
    });

For reference the default location for a JRE policy file is as follows

作为参考,JRE 策略文件的默认位置如下

On a windows machine.

在 Windows 机器上。

C:\Program Files\Java\JRE Version\lib\security\java.policy

C:\Program Files\Java\JRE 版本\lib\security\java.policy

Java 6 update 13 policy is stored here

Java 6 更新 13 策略存储在这里

C:\Program Files\Java\jre1.6.0_13\lib\security\java.policy

C:\Program Files\Java\jre1.6.0_13\lib\security\java.policy

As stated above you cannot edit this file without having access to the machine.

如上所述,您无法在无法访问机器的情况下编辑此文件。