Skip to content Skip to sidebar Skip to footer

Java AccessControlException Only With LiveConnect

I'm geting Access Errors, only when I call the functions with Javascript (LiveConnect). The applet calls a function postData and displays the response (this works great). Now if I

Solution 1:

I've recently run into the same problem, in particular with Firefox on the Mac. I was using SwingUtilities.invokeLater() in my block though.

The way I worked around it was to wrap the invokeLater call in an AccessController.doPrivileged() block. For example, if I have a method on my applet called someAction() that's callable from JavaScript, I would do:

void someAction() {
  AccessController.doPrivileged( new PrivilegedAction() {
     public Object run() {
        SwingUtilities.invokeLater( new Runnable() {
           public void run() {
              // some privileged action here
           }
        });
     }
  });
}

This approach seemed to fix the issue for me in Firefox. It does not get around Same Origin problems in Safari, though, for example if you want to serve the Javascript from a different domain than the applet.

Update I should mention that the invokeLater part isn't required for this to work; it's just what I happened to be using.


Post a Comment for "Java AccessControlException Only With LiveConnect"