1 2 Previous Next 15 Replies Latest reply: Oct 27, 2009 2:25 PM by 843811 RSS

    Signed Applet: java.security.AccessControlException:access denied

    843811
      Guys,

      Please help me ..i am challenged...I am trying to read a .MIDI file,from an Applet(a signed one)
      ..I dont know where it is going wrong...

      May be I might not be creating the policy file correctly or failing to access the URL...or point to policy file correctly...
      Is there any way to skip creating policy files by using [color=blue]AccessController.doPrivileged() [color]


      here 's the stack trace..

      java.security.AccessControlException: access denied (java.io.FilePermission C:\Documents and Settings\milind\GF1_P123 read)
           at java.security.AccessControlContext.checkPermission(Unknown Source)
           at java.security.AccessController.checkPermission(Unknown Source)
           at java.lang.SecurityManager.checkPermission(Unknown Source)
           at java.lang.SecurityManager.checkRead(Unknown Source)
           at java.io.FileInputStream.<init>(Unknown Source)
           at com.sun.media.sound.RmfFileReader.getMidiFileFormat(Unknown Source)
           at javax.sound.midi.MidiSystem.getMidiFileFormat(Unknown Source)
           at org.jfugue.Player.loadMidi(Player.java:402)
           at AccessDLLApplet.processMidi(AccessDLLApplet.java:143)
           at AccessDLLApplet$2.run(AccessDLLApplet.java:78)
           at AccessDLLApplet$2.run(AccessDLLApplet.java:1)
           at java.security.AccessController.doPrivileged(Native Method)
           at AccessDLLApplet.loadMidiString(AccessDLLApplet.java:74)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at sun.plugin.javascript.invoke.JSInvoke.invoke(Unknown Source)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
           at sun.plugin.com.MethodDispatcher.invoke(Unknown Source)
           at sun.plugin.com.DispatchImpl.invokeImpl(Unknown Source)
           at sun.plugin.com.DispatchImpl$1.run(Unknown Source)
           at java.security.AccessController.doPrivileged(Native Method)
           at sun.plugin.com.DispatchImpl.invoke(Unknown Source)
        • 1. Re: Signed Applet: java.security.AccessControlException:access denied
          EJP
          Are the org.jfugue classes in the signed JAR? or another unsigned JAR?
          • 2. Re: Signed Applet: java.security.AccessControlException:access denied
            843811
            Hi

            Thanks for responding !

            I am using an AccessDLLApplet.class(Applet File) and few more classes + Jfugue.jar . i am creating a new Jar out of it, then signing it using " jarsigner <Jar name>.jar <keyname>" . Still geting the same AccessControlException .

            This is how i am calling my method to read a .midi file:

            AccessControlContext acc = AccessController.getContext();
                      try{
                           this.arg1=arg;
                           
                      AccessController.doPrivileged(new PrivilegedExceptionAction <String>()
                      {
                      public String run() throws Exception
                      {
                           player.play(arg1);
                      return null;
                      }
                      }, acc);
                      }catch(Exception e){
                           e.printStackTrace();
                      }


            public String processMidi(String file){
                      String midiString =      "";     
            try{
                      Player player = new Player();
                      Pattern loadMidi = player.loadMidi(new File("C:\\Documents and Settings\\milind\\" + file + ".mid"));
                      midiString = loadMidi.toString();
                      catch(Exception e){
                           e.printStackTrace();
                      }
                      return midiString;
                      
                 }
            • 3. Re: Signed Applet: java.security.AccessControlException:access denied
              843811
              I would like to correct my previous post the code is slightly incorrect


              AccessControlContext acc = AccessController.getContext();
              try{
              this.fileName = fileName1;

              AccessController.doPrivileged(new PrivilegedExceptionAction <String>()
              {
              public String run() throws Exception
              {
              String midi = processMidi(fileName);
              return midi;
              }
              }, acc);
              }catch(Exception e){
              e.printStackTrace();
              }


              public String processMidi(String file){
              String midiString = "";     
              try{
              Player player = new Player();
              Pattern loadMidi = player.loadMidi(new File("C:\\Documents and Settings\\milind\\" file + ".mid"));
              midiString = loadMidi.toString();
              catch(Exception e){
              e.printStackTrace();
              }
              return midiString;

              }
              • 6. Re: Signed Applet: java.security.AccessControlException:access denied
                843811
                Yes org.jfugue classes are there in the Jar that i am creating ?

                Infact i tried reading a normal .txt file still same AccessControlException.

                What is the proper way of signing a jar ?
                • 7. Re: Signed Applet: java.security.AccessControlException:access denied
                  EJP
                  With the jarsigner tool.
                  • 8. Re: Signed Applet: java.security.AccessControlException:access denied
                    843811
                    Yes , I am using jarsigner to sign my .jar
                    • 9. Re: Signed Applet: java.security.AccessControlException:access denied
                      EJP
                      Is there any way to skip creating policy files by using AccessController.doPrivileged()
                      No. All that does is execute the code concerned with the privileges of the calling code rather than those of whoever called you (if not a system class). It's only of use to people writing frameworks where third-party code with even lower access rights may be calling you. That's not happening in this case. I would take it out - it's only confusing the situation.
                      • 10. Re: Signed Applet: java.security.AccessControlException:access denied
                        843811
                        Ok , that means I should follow signed applet approach . Currently I am using following link to sign an applet , still getting same AccessControlException.

                        http://forums.sun.com/thread.jspa?threadID=174214

                        Is there any other way for signing ?
                        • 11. Re: Signed Applet: java.security.AccessControlException:access denied
                          843811
                          Have you checked that you signed jar has the proper folder structure ? In mine case the folder structure was not correct and I was getting the error.I was accesing the Applet from the browser.

                          The path to the .class was something like this http://localhost:8080/classes/appls/access/privilegedwrite.class

                          http://localhost:8080/classes this was the codebase for my applet.
                          http://forums.sun.com/thread.jspa?threadID=174214 has the correct way to sign the jar.
                          • 12. Re: Signed Applet: java.security.AccessControlException:access denied
                            843811
                            Hi Guys


                            Finally I got the solution ..!

                            I tried accessing my local resources through init() inside Applet , it worked . Any thread that you launch through init() will be able to access local resources. No need of using java.security.AccessController to get any extra privileges.

                            The most important thing is to keep all the relevant classes(third party jars etc) in a single jar and that should be signed properly.


                            Please correct me if am wrong.

                            Thanks for all your support.
                            • 13. Re: Signed Applet: java.security.AccessControlException:access denied
                              EJP
                              The most important thing is to keep all the relevant classes(third party jars etc) in a single jar
                              That's not necessary.
                              and that should be signed properly.
                              That is necessary, and all jars must be signed by the same signer.
                              • 14. Re: Signed Applet: java.security.AccessControlException:access denied
                                843811
                                milind_kamboj: I am running into the exact same issue but when I launch a thread from init like so:
                                        Thread javascriptListener = new Thread() {
                                            @Override
                                            public void run() {
                                                while (true) {
                                                    
                                                    System.out.println(System.getProperty("user.home"));
                                
                                                    try {
                                                        sleep(1000);
                                                    } catch (Throwable t) {
                                                        t.printStackTrace();
                                                    }
                                                }
                                            }
                                        };
                                        javascriptListener.start();
                                I still get this:
                                Exception in thread "Thread-35" java.security.AccessControlException: access denied (java.util.PropertyPermission user.home read)
                                I think it might be jre version issue as there are many other people who describe the same thread technique elsewhere.

                                I am running 1.6_u16, can you tell me which version it worked for you in?
                                1 2 Previous Next