Security Policy

Shelton Wilson (shelton@ee.uwa.edu.au)
Fri, 13 Mar 1998 04:11:28 +0800

Date: Fri, 13 Mar 1998 04:11:28 +0800
From: Shelton Wilson <shelton@ee.uwa.edu.au>
To: java-security@web1.javasoft.com
Subject: Security Policy

Under the java security sand box model applications were not restricted
but applets were restricted and could not for example write to the local
file system they were downloaded to. Under the new the JDK1.2 security
model you can specify access writes so that applet can have access to
local system resources via a policy file. My question is, how do I
restrict local applications from say writing to a local file using a
security policy.
I'm trying to set the access to the file in the following code to read
only, so an attempt to
write to this file should throw an AccessController exception.

public class MyClass
{

public static void main(String argv[])
{
try
{
Permission myPerm = new FilePermission("hello.dat","read);
MyClass myClass = new MyClass();
AccessController.checkPermission(myPerm);
DataOutputStream dos = new DataOutputStream( new
FileOutputStream("hello.dat"));
dos.writeInt(10);
dos.writeInt(20);
dos.close();
} catch (IOException e) {System.out.println(e);}
}
}

I have added the following line to the security policy file to give only
read access to all files.

permission java.io.FilePermission "-", "read";

However and the above code does not throw an exception and allows the
write to the file. How do I get to throw an exception when an attempt
is made to write to a file by an application.

Thanks
Shelton Wilson
Research Officer
Univeristy of Western Australia
shelton@ee.uwa.edu.au