Results 1 to 1 of 1
Thread: ClassLoader Access denied
- 04-24-2011, 01:58 PM #1
ClassLoader Access denied
Hello everyone,
I have a problem with java's ClassLoader.
I have written an java applet with inside the, by my written simple, ClassLoader. (Sources below)
The java applet jar file is signed.
Now when the ClassLoader starts he loads and calls "theClass". (Sources below)
When I run the applet in my browser and click "run" at the security warning the program starts, calls "theClass" and print in the console: "From theClass: Hello World!", that part works finely.
Then the second output has to be: "From theClass: " + System.getProperty("java.io.tmpdir")
But because that is an permission-needed call I get an error. (Error code below)
I don't know how so grant permission to the ClassLoader or classes in the ClassLoader.
I've read something about the java class "RuntimePermission", but there is no way to grant the RuntimePermission to the ClassLoader.
I hope someone could tell me how to grant permissions to a ClassLoader or if there is another way to make this possible.
Thanks,
Dennis
Sources/Error code:
loader.java
My ClassLoader: c.java:Java Code:import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class loader extends java.applet.Applet { public void init() { c cl = new c(ClassLoader.getSystemClassLoader()); cl.getClass("theClass", getFileContent(new File("/media/Data/workspace/ClassLoaderTest/test1Classes/bin/theClass.class"))); try{ Class<?> c = cl.loadClass("theClass"); c.newInstance(); }catch(ClassNotFoundException ex){ ex.printStackTrace(); }catch(InstantiationException ex){ ex.printStackTrace(); }catch(IllegalAccessException ex){ ex.printStackTrace(); } } private byte[] getFileContent(File f) { if(f.exists()){ try { FileInputStream fis = new FileInputStream(f); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int r=0; while(r<f.length()) { byte[] b = new byte[(int) (f.length()-r)]; try { int n = fis.read(b, 0, ((int)f.length())-r); baos.write(B); r+=n; } catch (IOException e) { e.printStackTrace(); } } return baos.toByteArray(); } catch (FileNotFoundException e) { e.printStackTrace(); } } return null; } }
The by ClassLoader loaded class: theClass.java (in an extern file, not in scope)Java Code:public class c extends ClassLoader { public c() { super(); } public c(ClassLoader cl) { super(cl); } public void getClass(String s, byte[] B) { if(b!=null) defineClass(s, b, 0, b.length); // protected function } }
Error/output code:Java Code:public class theClass { public theClass() { System.out.println("From theClass: Hello World!"); System.out.println("From theClass: " + System.getProperty("java.io.tmpdir")); } }
Java Code:From theClass: Hello World! java.security.AccessControlException: access denied (java.util.PropertyPermission java.io.tmpdir read) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:393) at java.security.AccessController.checkPermission(AccessController.java:553) at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1302) at java.lang.System.getProperty(System.java:669) at theClass.<init>(theClass.java:7) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:532) at java.lang.Class.newInstance0(Class.java:372) at java.lang.Class.newInstance(Class.java:325) at loader.init(loader.java:21) at sun.applet.AppletPanel.run(AppletPanel.java:436) at java.lang.Thread.run(Thread.java:636)
Similar Threads
-
Jni registry 'access denied' error.
By durino13 in forum Advanced JavaReplies: 4Last Post: 09-17-2011, 07:06 AM -
newbie here, access denied error?!?
By kingpabs in forum JCreatorReplies: 3Last Post: 04-01-2011, 02:16 AM -
Access is denied when trying to create a file.
By adwodon in forum New To JavaReplies: 5Last Post: 03-18-2011, 02:58 PM -
Access is denied
By tholland in forum New To JavaReplies: 2Last Post: 12-20-2010, 08:57 PM -
access denied
By Dennis in forum Advanced JavaReplies: 8Last Post: 06-05-2010, 08:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks