2

I used some code from another question to access the private field "classes" in the Java ClassLoader. This works fine, however when I move it to an applet it gets messed up with this exception: access denied (java.lang.RuntimePermission accessDeclaredMembers). I've done some searching and tried using PrivlegedExceptionAction to skip that, but it isn't working. So my question is this: is is possible to bypass this, and if not what is another way to get a list of classes?

Reflection Code:

final ClassLoader cLoader = getClass().getClassLoader();
            final Field f = ClassLoader.class.getDeclaredField("classes");
            AccessController.doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws Exception {
                        f.setAccessible(true);
                        return null;}});
            Vector<Class> classes = (Vector<Class>)f.get(cLoader);
            cList.addAll(classes);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Octavia Togami
  • 4,186
  • 4
  • 31
  • 49

1 Answers1

2

Digitally sign the applet code (then get the user to accept it when prompted) to gain full privileges.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Sorry I forgot to mention this but I am using greenfoot to do this (it has to be done in this program) and I cannot make a digital signature unless I could do it programmatically. – Octavia Togami Sep 06 '12 at 23:17
  • (shrugs) Whether it is 'greenfoot' or paper, glue & sparkles used to make the applet does not matter. The answer to your question remains the same. – Andrew Thompson Sep 06 '12 at 23:36
  • I can't make a digital signature because I am not in control of the upload. – Octavia Togami Sep 07 '12 at 00:19
  • I'm having the exact same problem with an app that *is* digitally signed, what do you recommend in that case? – Brian Knoblauch Jan 20 '14 at 20:04
  • @BrianKnoblauch I recommend you ask your own question, link to this one, and explain the differences. Name the exact JRE version this occurs in. Security has been tightened in recent times/JREs. – Andrew Thompson Jan 20 '14 at 22:17