java.lang.SecurityException when calling Image.IO.Read inside applet

Started by richardadams, January 28, 2010, 19:02:08

Previous topic - Next topic

kappa

sound like a jre bug or that the calls from javascript are not allowed access outside the sandbox. not really sure what could be causing this, maybe its a browser restriction (tried in other browsers?)

richardadams

OK I've done some more testing.  It's not just ImageIO that has a problem.  I just tested an applet that when initialising calls a functiom write a text file to disk.  That works with no problems.

Call this same function via javascript (using the getApplet() function in AppletLoader) and and you get..

java.security.AccessControlException: access denied

Why would the access rights of the applet be different depending on how the function is called.  I'm a bit stuck on this one.

Cheers,

Richard

Matzon

might be because the "action" occurs from another thread/classloader than the signed one.
Try and wrap your stuff in
AccessController.doPrivileged(new PrivilegedExceptionAction() {
				public Object run() throws Exception {
				}
			});

richardadams

Ahh thank you,

It's because scripted calls in to signed applets operate without the permissions granted with the certificate.  I've used the following now and it works..

AccessController.doPrivileged(new PrivilegedAction<Void>() {
         public Void run() {
                                // Your code here
            return null;
         }
      });

I'm fairly new to Java else I guess I would have known that.  Thanks for all you help.