views:

262

answers:

3

hi

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

+2  A: 

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.

ZZ Coder
+2  A: 

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.

Omry
+1 for signing the applet
Pascal Thivent
+2  A: 

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.

Knife-Action-Jesus