Sunday, July 18, 2010

Java Applet Permissions Mac OS X

I was working on Applets for the first time in a long time the other day. I found that I was getting SecurityException messages, and the applets would not work. This was related to the applet security policies not being set. I thought this should be easy to find and fix. It was not. It appears that this is somewhat arcane knowledge. There are plenty of documents, even release notes from Sun/Oracle on Windows, Linux, and Solaris, but Mac OS X...nothing.

Anyway here is the arcane part you are interested in.

The applet security policy is stored in the user's home directory in a file called .java.policy. Here is a wide open policy which probably should not be used except when absolutely necessary. You can comment the policy out using the /* */ syntax when it is not necessary.

grant {
permission java.security.AllPermission;
};

A more conservative approach would be to use something like this for testing from your localhost development system. The trailing "-" indicates any sub-directory from the top level.

grant codeBase "http://localhost/-" {
permission java.security.AllPermission;
}; 
 
This allows you to do wide open development and testing, but keeps the permissions limited from code outside of the current machine.

I have attached a NetBeans 6.9 project which includes code from Oracle which demonstrates the Java Security Manager. WriteFileApplet.zip

0 comments :

Popular Posts