Access exception loading icon
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Richard_Hall
Posted On:   Thursday, April 11, 2002 10:06 AM

I have a system that dynamically loads components (as JAR files) and instantiates them. I have started to add permission checks to this system to make it more secure. By default, my framework has all permissions granted to it and it uses doPrivileged() where necessary to perform sensitive tasks on the behalf of downloaded code without the necessary permissions. Before adding permissions to my framework, my downloaded components normally loaded icons like this: m_offIcon = new ImageIcon(getClass().getResource("off.gif")); But this approach now throws an exception like this (read below for a work-around): java.security.AccessControlException: access denied (java.se   More>>


I have a system that dynamically loads components (as JAR files) and instantiates them. I have started to add permission checks to this system to make it more secure. By default, my framework has all permissions granted to it and it uses doPrivileged() where necessary to perform sensitive tasks on the behalf of downloaded code without the necessary permissions.


Before adding permissions to my framework, my downloaded components normally loaded icons like this:

			
m_offIcon = new ImageIcon(getClass().getResource("off.gif"));


But this approach now throws an exception like this (read below for a work-around):

			
java.security.AccessControlException: access denied
(java.security.AllPermission )
at
java.security.AccessControlContext.checkPermission(AccessControlContext.java:272)
at java.security.AccessController.checkPermission(AccessController.java:399)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at sun.awt.SunToolkit.getImageFromHash(SunToolkit.java:231)
at sun.awt.SunToolkit.getImage(SunToolkit.java:284)
at javax.swing.ImageIcon. (ImageIcon.java:115)
at javax.swing.ImageIcon. (ImageIcon.java:134)
at
org.ungoverned.oscar.bundle.serviceregister.ServiceRegisterFrame. (ServiceRegisterFrame.java:56)
at
org.ungoverned.oscar.bundle.serviceregister.ServiceRegisterModel.start(ServiceRegisterModel.java:42)
at org.ungoverned.oscar.BundleImpl$1.run(BundleImpl.java:502)
at java.security.AccessController.doPrivileged(Native Method)
at org.ungoverned.oscar.BundleImpl.start(BundleImpl.java:499)


I have spent hours trying to figure out exactly which permission is required by sun.awt.SunToolkit.getImageFromHash(), but I have finally given up. I did find an alternative method that does work fine for loading the icon using this code:
			
java.io.InputStream is = getClass().getResourceAsStream("off.gif");
int count = is.available();
byte[] buf = new byte[count];
is.read(buf);
is.close();
m_offIcon = new ImageIcon(buf);

This loads the icon fine. But the former approach is the more "standard" way of loading a resource and it is really bothering me, since clearly if I can load the icon with the latter approach, then why not with the former? Since the source code for SunToolkit does not come with the JDK, I am unable to look for myself to see what permission is being checked and the exception message is not revealing enough detail.


At any rate, I would greatly appreciate it if anyone had any insight for me.


Thanks.


-> richard

   <<Less
About | Sitemap | Contact