• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JApplet Browser security issues

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I've written a game JApplet which uses 3rd party image gifs and jpgs embedded in JLabels / JButtons. Trouble is when I try to browse my Japplet, I get security exceptions left, right & centre becuse it won't allow the JApplet to read external files, even on my local machine!
The only solutions I can think of are twofold:
1. use public / private key encryption (messy), or
2. use custom graphics routines
Are these the only viable solutions, or is there a more elegant answer out there somewhere in Javaspace?!
Thanks.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

You seem to load the image files from your local hard disk. Why don't you keep them in your web directory alongside the applet? That way the applet is allowed access to them with no special setup.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Response from Mark:

Allow me to elaborate on the problem i'm having:
i've written a game JApplet which uses 3rd party gif's & jpg's. When testing it using appletviewer there were no problems, but when i tried testing it with a browser (IE6), the following occurs: in the status bar i get this message: "Applet MasterMind not inited" and a big red X in the top left-hand corner of the browser window.

Then, looking in the Java Console, i see this error:

java.security.AccessControlException: access denied (java.io.FilePermission mastermindchair.jpg read)

All the image files needed by the applet are located in the same directory as the compiled class files. The html to trigger the applet is in the same directory:
<html>
<applet code="MasterMind.class" width=800 height=750 alt="JVM deactivated."></applet>
</html>
Tonight, i tried lowering the security level of my browser to nil, and it still refuses to start it, always reporting the errors mentioned above. I can't understand why i can't get my machine's browser to fire up the applet , especially when i have set the security to virtually zero. BTW, i also tried using Netscape, with the same results. Any suggestions gratefully received...



The browser security settings have no bearing on this - it's the applet security settings that prohibit it. Applets can't open files (or use anything in the java.io package, and a number of other things). The appletviewer is special in this regard, as it generally doesn't enforce these restrictions; but browsers do.

There are three ways around this. Either relax the security policy for applets on your machine, or digitally sign the applet, or load the images in a way the applet is allowed to do. The first two methods are described in this FAQ page. The third one has a short blurb and link pointing to further information on the Applet FAQ page.
[ February 07, 2006: Message edited by: Ulf Dittmer ]
 
mark weatherill
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf

I got it all working now; for a totally sublime Java Swing Mastermind gaming experiance, browse over to http://geocities.com/m_weatherill/HomePage.html and follow the link to the Mastermind game.
Basically, I did the following:
1) Changed the ImageIcon constructors' argument from a string to a URL object ref.
2) Created keys & certificate using the JDK's keytool.
3) Exported the self-certified X.509 certificate and then imported it into the cacerts keystore on my local file system, also using keytool.
4) Signed the jar file using jarsigner.
5) Uploaded the signed jar file and all the image files to the server.
And it now works.
Thanks for your advice!
Mark.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic