changeset 9764:3f97e99977ce

8033530: Applet fails to load resources or connect back to server under some scenarios Reviewed-by: ngthomas, michaelm
author dtitov
date Fri, 14 Feb 2014 13:07:33 -0800
parents 5c9cf6d4698e
children 32639f1b7880
files src/share/classes/sun/awt/SunToolkit.java src/share/classes/sun/awt/image/URLImageSource.java src/share/classes/sun/net/util/URLUtil.java
diffstat 3 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/awt/SunToolkit.java	Wed Feb 12 11:39:49 2014 -0800
+++ b/src/share/classes/sun/awt/SunToolkit.java	Fri Feb 14 13:07:33 2014 -0800
@@ -50,6 +50,7 @@
 import sun.font.FontDesignMetrics;
 import sun.awt.im.InputContext;
 import sun.awt.image.*;
+import sun.net.util.URLUtil;
 import sun.security.action.GetPropertyAction;
 import sun.security.action.GetBooleanAction;
 import java.lang.reflect.InvocationTargetException;
@@ -720,7 +721,7 @@
         if (sm != null) {
             try {
                 java.security.Permission perm =
-                    url.openConnection().getPermission();
+                    URLUtil.getConnectPermission(url);
                 if (perm != null) {
                     try {
                         sm.checkPermission(perm);
@@ -796,7 +797,7 @@
         if (sm != null) {
             try {
                 java.security.Permission perm =
-                    url.openConnection().getPermission();
+                        URLUtil.getConnectPermission(url);
                 if (perm != null) {
                     try {
                         sm.checkPermission(perm);
--- a/src/share/classes/sun/awt/image/URLImageSource.java	Wed Feb 12 11:39:49 2014 -0800
+++ b/src/share/classes/sun/awt/image/URLImageSource.java	Fri Feb 14 13:07:33 2014 -0800
@@ -31,6 +31,7 @@
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.MalformedURLException;
+import sun.net.util.URLUtil;
 
 public class URLImageSource extends InputStreamImageSource {
     URL url;
@@ -43,7 +44,7 @@
         if (sm != null) {
             try {
                 java.security.Permission perm =
-                    u.openConnection().getPermission();
+                      URLUtil.getConnectPermission(u);
                 if (perm != null) {
                     try {
                         sm.checkPermission(perm);
--- a/src/share/classes/sun/net/util/URLUtil.java	Wed Feb 12 11:39:49 2014 -0800
+++ b/src/share/classes/sun/net/util/URLUtil.java	Fri Feb 14 13:07:33 2014 -0800
@@ -25,7 +25,10 @@
 
 package sun.net.util;
 
+import java.io.IOException;
 import java.net.URL;
+import java.net.URLPermission;
+import java.security.Permission;
 
 /**
  * URL Utility class.
@@ -76,5 +79,26 @@
 
         return strForm.toString();
     }
+
+    public static Permission getConnectPermission(URL url) throws IOException {
+        String urlStringLowerCase = url.toString().toLowerCase();
+        if (urlStringLowerCase.startsWith("http:") || urlStringLowerCase.startsWith("https:")) {
+            return getURLConnectPermission(url);
+        } else if (urlStringLowerCase.startsWith("jar:http:") || urlStringLowerCase.startsWith("jar:https:")) {
+            String urlString = url.toString();
+            int bangPos = urlString.indexOf("!/");
+            urlString = urlString.substring(4, bangPos > -1 ? bangPos : urlString.length());
+            URL u = new URL(urlString);
+            return getURLConnectPermission(u);
+            // If protocol is HTTP or HTTPS than use URLPermission object
+        } else {
+            return url.openConnection().getPermission();
+        }
+    }
+
+    private static Permission getURLConnectPermission(URL url) {
+        String urlString = url.getProtocol() + "://" + url.getAuthority() + url.getPath();
+        return new URLPermission(urlString);
+    }
 }