Policy files enabling Applet access to user files

Introduction

This page shows two policy files that I have set up for personal use at home. These examples represent my extent of knowledge on the subject but they may be of help. For a detailed description, see the Sun Java Website. I have also set up a mechanism via a file .java.lfp.txt to enable logical directory/folder names to be set up to point, for example, to directories/folders containing image files. This is used in the example applets which allow the user to display their own locally stored images.

Example file for Windows XP

The file must be named .java.policy and is placed in the user's home directory as pointed to by user.home. This example enables read access of files in the folder C:\Documents...\image_applet\data.

grant codeBase "http://www.ccp4.ac.uk/jwc/image_applet/*" {
  permission java.io.FilePermission "C:\\Documents and Settings\\JOHN\\My Documents\\temp\\image_applet\\data\\*", "read";
};
grant codeBase "http://www.ccp4.ac.uk/jwc/image_applet/*" {
  permission java.util.PropertyPermission "user.home", "read";
};
grant codeBase "http://www.ccp4.ac.uk/jwc/image_applet/*" {
  permission java.io.FilePermission "C:\\Documents and Settings\\JOHN\\.java.lfp.txt", "read";
};
};

Example file for Linux

The file must be named .java.policy and is placed in the user's home directory. This example enables access of files in all subdirectories of /home/jwc as indicated by the '-'.

grant codeBase "http://www.ccp4.ac.uk/jwc/image_applet/*" {
  permission java.io.FilePermission "/home/jwc/-", "read";
  permission java.io.FilePermission "/home/jwc/-", "write, delete";
};
grant codeBase "file:/home/jwc/Current/jdlswing/image_applet/*" {
  permission java.util.PropertyPermission "user.home", "read";
};
grant codeBase "http://www.ccp4.ac.uk/jwc/image_applet/*" {
  permission java.io.FilePermission "/home/jwc/.java.lfp.txt", "read";
};

  Back to Java Image Display home page

Example of a Logical File Paths file

Below is an example of the file .java.lfp.txt for Windows. This sets up just a single logical name IMG pointing to the folder containing some image files.

IMG C:\Documents and Settings\JOHN\My Documents\temp\image_applet\data\

In this case the file name for an image file "C:\Documents and Settings\JOHN\My Documents\temp\image_applet\data\lys.image" would be input to the program as IMG/lys.image.