8033530: [regression] Applet fails to load resources or connect back to server under some scenarios
Reviewed-by: mchung, michaelm, serb, ddehaven
--- a/jdk/src/java.base/share/classes/sun/net/util/URLUtil.java Mon Jun 01 14:59:20 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/net/util/URLUtil.java Thu Jun 04 11:18:52 2015 -0700
@@ -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);
+ }
}
--- a/jdk/src/java.desktop/share/classes/sun/awt/SunToolkit.java Mon Jun 01 14:59:20 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/sun/awt/SunToolkit.java Thu Jun 04 11:18:52 2015 -0700
@@ -66,6 +66,7 @@
import sun.awt.image.URLImageSource;
import sun.font.FontDesignMetrics;
import sun.misc.SoftCache;
+import sun.net.util.URLUtil;
import sun.security.action.GetBooleanAction;
import sun.security.action.GetPropertyAction;
import sun.util.logging.PlatformLogger;
@@ -875,7 +876,7 @@
if (sm != null) {
try {
java.security.Permission perm =
- url.openConnection().getPermission();
+ URLUtil.getConnectPermission(url);
if (perm != null) {
try {
sm.checkPermission(perm);
--- a/jdk/src/java.desktop/share/classes/sun/awt/image/URLImageSource.java Mon Jun 01 14:59:20 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/sun/awt/image/URLImageSource.java Thu Jun 04 11:18:52 2015 -0700
@@ -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);