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

╄→гoц情女王★ 提交于 2019-12-09 18:23:51

问题


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.

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?

please help me


回答1:


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,

  ${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.




回答2:


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.

you can try a test certificate you can generate for free. This may help.




回答3:


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

On a windows machine.

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

Java 6 update 13 policy is stored here

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.



来源:https://stackoverflow.com/questions/1417271/where-policy-file-location-for-my-applet-that-needs-clients-permission-to-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!