LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: richardadams on January 28, 2010, 19:02:08

Title: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: richardadams on January 28, 2010, 19:02:08
Hi Everyone,

I have an applet loaded via the AppletLoader which loads and runs as expected.  During the initialisation of this applet I call

java.awt.Image image = ImageIO.read(stream);

No problems the jpg gets loaded as expected.  However when I call a public function of the applet (via getApplet()) the very same code generates the following exception

java.lang.SecurityException: Unable to create temporary file

The applet is signed, i've checked and double checked.  Can anyone explain why this might be happening?

Thanks in advance.
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: kappa on January 28, 2010, 19:32:10
care to paste the whole exception from the java console? bit difficult to tell from just that snippet you've provided.
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: kappa on January 28, 2010, 19:57:54
hmm, hard to say.

which OS, Java version and browser are you using?

is it possible you could provide a link to the applet, so i can see if i can reproduce the error here?
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: richardadams on January 28, 2010, 20:01:39
Certainly,

Window XP SP3 & Java 1.6.18.

Can I email you the link?  The site's under development and I can't have it indexed just yet :)
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: kappa on January 28, 2010, 20:04:21
send me the link as a pm :)
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: kappa on January 28, 2010, 20:17:27
thx, just tried but i'm on linux, it seems to be missing the linux_natives.jar
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: richardadams on January 28, 2010, 20:27:40
That should fix it.
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: kappa on January 28, 2010, 20:29:10
now i get an unable to validate certificate chain error. remember the certificates in the natives jars, should be the same as that of the lwjgl_util_applet.jar
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: richardadams on January 28, 2010, 20:32:07
Hmm everything's signed with my own certificate cold it be a caching issue?
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: richardadams on January 28, 2010, 20:48:03
Hi,

Let me know if it's still not working for you.  I'll create a new page with a simple applet that demonstrates the problem and send you the source.

Thanks.
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: kappa on January 28, 2010, 20:52:45
i've just checked, the linux_natives.jar is not signed.
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: richardadams on January 28, 2010, 20:55:01
Lord, really sorry I copied the wrong one up.  It is now.

Applolgies for that.
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: kappa on January 28, 2010, 20:58:59
works great for me now. see a model in the middle of the page and you can rotate around it.

not sure why it's still not working for you, make sure you haven't corrupted your cache somehow with an older version of lwjgl, if you suspect that try change the al_title value and clear the java cache from the java control panel.
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: kappa on January 28, 2010, 21:01:26
further check all your jars are signed, (just open them with a zip program and see if the META-INF folder has the certificates in there)
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: richardadams on January 28, 2010, 21:03:52
OK the problem occurs when you hit one of the image logos below the main window.  That's when the public function gets called via javascript and the error occurs.

This is the code from the public the function

   InputStream stream = null;   
   URL file = null;
      
   try {
      file = new URL(modelUrl + ".jpg");
   } catch (MalformedURLException e) {
      e.printStackTrace();
   }
      
   try {
      stream = file.openStream();
   } catch (IOException e) {
      e.printStackTrace();
   }
      
   try {
      java.awt.Image image = ImageIO.read(stream);
   } catch (IOException e) {
      e.printStackTrace();
}

The exception occurs when we get to the following line, but only when the function is called from Javascript not during initialisation.

java.awt.Image image = ImageIO.read(stream);

Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: kappa on January 28, 2010, 21:32:02
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?)
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: richardadams on January 28, 2010, 21:41:53
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
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: Matzon on January 28, 2010, 22:11:52
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 {
}
});
Title: Re: java.lang.SecurityException when calling Image.IO.Read inside applet
Post by: richardadams on January 29, 2010, 00:40:00
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.