File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes java.policy grant codeBase Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "java.policy grant codeBase" Watch "java.policy grant codeBase" New topic

java.policy grant codeBase

Ruben Sal

Joined: Feb 17, 2009
Posts: 2

I've a signed applet that deletes some temp files on a local machine.
The applet works fine when I add grant permissions on the .java.policy file.

The problems begin when I specify a grant codeBase.
If I put:

This grant, I think, allows io.permissions for the applets placed on
"" and subdirectories but it doesn't work.
Always I have an access denied error like this
" access denied ( C:\xxxx delete)"

This applet is called from a Firefox browser.

Anyone know what is the problem?
Why it doesn't work when I set a grant codeBase?

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Welcome to JavaRanch.

The "=" character is not part of the policy file syntax, so it probably leads to this permission being ignored. Replace it with a space character.
Ruben Sal

Joined: Feb 17, 2009
Posts: 2
Hi Ulf

Sorry, the codeBase is set without character "=", I paste it wrong before.
It doesn't work

I generate the java.policy with policytool.exe and I supose the sintax is correct, but I don't know.

I don't know if the problem can be in the file.
Yilmaz Ay

Joined: Nov 03, 2009
Posts: 1
Have you found a solution for this problem? I am having exactly the same problem.
I have checked my javapolicy file syntax several times to make sure that it is not my mistake.
I am pretty sure, everything is according to the spects as described on Sun's website.

However, adding a codebase after "grant" command makes all permissions disabled for some reasons.

without codebase grant { permission ....... } works fine.

so, i think, there is something wrong with the codebase

here is my code snippet :

grant codeBase "" {
permission "C:\\Documents and Settings\\UserName\\SomeDirectory\\-", "read,write";

UserName\\SomeDirectory\\ is actually a real path, just did not want to display it here.

If anyone has any solution or any idea that might help me solve this problem, i appreciate your help.
Rafal Sasadeusz

Joined: Feb 16, 2012
Posts: 1
It's probably too late to help you but maybe someone will find my answer useful. I've had similar problem few days ago. It was caused by JavaScript code calling my applet. When you are calling "restricted" applet functions from JavaScript you will get "security exception" even if the applet is signed.

You need to use AccessControler to elevate privileges for JavaScript:

Granting permission as showed below will solve your problem as well because JavaScript codebase is null.

grant {
permission "<<ALL FILES>>", "delete";

Darryl Burke

Joined: May 03, 2008
Posts: 5115

Since that link is for the API of an old, obsoleted Java version, here are the links for the later versions.
Java SE 6:
Java SE 7:

There's probably no difference in the API of this particular class, but there are several differences in the overall Java API.

Welcome to the Ranch, Rafal!

luck, db
There are no new questions, but there may be new answers.
I agree. Here's the link:
subject: java.policy grant codeBase
It's not a secret anymore!