0

So when I try to load my applet from my website I get

AccessControlException
access denied ("java.io.FilePermission" "cursor.gif" "read")

This corresponds to the code inside my applet.

//Modify the cursor when inside the Applet
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image cursorIcon = toolkit.getImage("cursor.gif");
Point center = new Point(16, 16);
Cursor cursor = toolkit.createCustomCursor(cursorIcon, center, "Cursor");
setCursor(cursor);

I HAVE googled and tried things such as

  • Sign the .jar
  • Create a policy thing, but I didn't completely understand how to make it and what to do with it (Could someone explain to me how to do the policy thing in detail?)

My applet works perfectly fine when I run it in my eclipse Additionally, if I comment out the code above, my applet works, so just that portion is giving me an error.

Rizier123
  • 58,877
  • 16
  • 101
  • 156
kikiotsuka
  • 79
  • 8
  • `"cursor.gif"` This seems like an application resource - provided by you along with the applet, as opposed to loaded from ..some place on the file system of the end user. If it is supplied by 'the web site', the applet needs to access the image via URL. That URL is typically formed relative to the codebase or document base, or via `getResource()` if the cursor image is in a jar mentioned in the archive attribute of the applet element. – Andrew Thompson Dec 27 '12 at 06:21
  • *"My applet works perfectly fine when I run it in my (insert IDE here)"* (sigh) Wish I had a dollar for every time I've heard that. ;) – Andrew Thompson Dec 27 '12 at 06:24
  • Rather than edit your original question, take the information you learned and [answer your own question](http://meta.stackexchange.com/questions/17463/can-i-answer-my-own-questions-even-those-where-i-knew-the-answer-before-asking). – Jim Dagg Dec 27 '12 at 19:09

1 Answers1

0

You have to wrap your code inside privileged code like:

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;
    }
});

This code is copied from: where policy file location for my applet that needs clients permission to access resource?

Also useful links:

http://docs.oracle.com/javase/6/docs/technotes/guides/security/PolicyFiles.html about java policy implementation.

http://docs.oracle.com/javase/1.3/docs/tooldocs/win32/policytool.html#Usage using GUI policy file editor

Community
  • 1
  • 1
Kerb
  • 1,138
  • 2
  • 20
  • 39