changeset 246:7f0a8910a2a8

Fix PR723: AccessControlException while downloading resource
author Deepak Bhole <dbhole@redhat.com>
date Fri, 27 May 2011 18:01:27 -0400
parents 1d10dbc851d7
children 36376d58c0ab
files ChangeLog netx/net/sourceforge/jnlp/cache/ResourceTracker.java
diffstat 2 files changed, 25 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri May 27 18:00:02 2011 -0400
+++ b/ChangeLog	Fri May 27 18:01:27 2011 -0400
@@ -1,3 +1,12 @@
+2011-05-27  Deepak Bhole <dbhole@redhat.com>
+
+	PR723: AccessControlException while downloading resource
+	* netx/net/sourceforge/jnlp/cache/ResourceTracker.java
+	(Downloader): Make class private.
+	(Downloader::run): Call processResource via doPrivileged since
+	resources may get added at run time from application code via
+	JNLPClassLoader::addNewJar().
+
 2011-05-27  Deepak Bhole <dbhole@redhat.com>
 
 	PR735: Firefox 4 sometimes freezes if the applet calls showDocument()
--- a/netx/net/sourceforge/jnlp/cache/ResourceTracker.java	Fri May 27 18:00:02 2011 -0400
+++ b/netx/net/sourceforge/jnlp/cache/ResourceTracker.java	Fri May 27 18:01:27 2011 -0400
@@ -28,6 +28,8 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
@@ -1078,7 +1080,7 @@
     /**
      * This class downloads and initializes the queued resources.
      */
-    class Downloader implements Runnable {
+    private class Downloader implements Runnable {
         Resource resource = null;
 
         public void run() {
@@ -1100,7 +1102,19 @@
                 }
 
                 try {
-                    processResource(resource);
+
+                    // Resource processing involves writing to files 
+                    // (cache entry trackers, the files themselves, etc.)
+                    // and it therefore needs to be privileged
+
+                    final Resource fResource = resource;
+                    AccessController.doPrivileged(new PrivilegedAction<Void>() {
+                        public Void run() {
+                            processResource(fResource);                            
+                            return null;
+                        }
+                    });
+
                 } catch (Exception ex) {
                     if (JNLPRuntime.isDebug())
                         ex.printStackTrace();