This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

custom classloader in applet

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a signed applet, which uses a custom class loader. Here is a brief explanation of what I am doing:

Applet loads data files from the server, and decompresses them using my custom class loader.

Applet launches main class.

This allows me to use a better compression algorithm than Zip. It works great until one of the loaded classes calls getClass()getResource("blah"); I have implemented findResource(String) for my class loader, which uses a custom URLStreamHandler to provide the InputStream for the URL. It returns a ByteArrayInputStream containing a copy of the data read from the data file.

At first this did not work, as the URL constructor would throw a security exception because it did not want to allow any custom URLStreamHandlers. I got around this by using AccessController.doPrivileged(...); I'm not sure why this is needed, since my applet is signed.

Now, this works and I get a working URL... but it throws a security exception down in Swing. :-(

Here is a trace:

java.security.AccessControlException: access denied (java.security.AllPermission <all permissions> <all actions>
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
at sun.awt.SunToolkit.getImage(Unknown Source)
at javax.swing.ImageIcon.<init>(Unknown Source)
at javax.swing.ImageIcon.<init>(Unknown Source)
at <snip>.NavigationToolbar$CompassRose.<init>(Unknown Source)
at <snip>.NavigationToolbar.<init>(Unknown Source)
at <snip>.MapFrame.intialize(Unknown Source)
at <snip>.MapViewer.initWindowMode(Unknown Source)
at <snip>.MapViewer.init(Unknown Source)
at launcher.AppletLauncher.start(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

I really don't want to muck around with all of the getResource(String) calls. Isn't it odd that I have already loaded classes from an external source, but I can't display an image which is already in memory??

I am signing my applet with an RSA style certificate, so I should have all privileges.

 
Mark Deneen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i fixed my problem by doing the following:

Policy.setPolicy(new Policy()
{
public PermissionCollection getPermissions(CodeSource source)
{
Permissions result = new Permissions();
result.add(new AllPermission());

return result;
}

public void refresh()
{
}
});

Works like a charm. By using the LZMA algorithm & proguard, I have been able to make my applet jar (now dat) files 1/3 the size. The only downside is that your applet must be signed.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic