8033530: [regression] Applet fails to load resources or connect back to server under some scenarios

Reviewed-by: mchung, michaelm, serb, ddehaven
This commit is contained in:
Daniil Titov 2015-06-04 11:18:52 -07:00
parent 40f869686c
commit 8c644ca310
3 changed files with 28 additions and 2 deletions

View File

@ -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 @@ public class URLUtil {
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);
}
}

View File

@ -66,6 +66,7 @@ import sun.awt.image.ToolkitImage;
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 @@ public abstract class SunToolkit extends Toolkit
if (sm != null) {
try {
java.security.Permission perm =
url.openConnection().getPermission();
URLUtil.getConnectPermission(url);
if (perm != null) {
try {
sm.checkPermission(perm);

View File

@ -31,6 +31,7 @@ import java.net.HttpURLConnection;
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 @@ public class URLImageSource extends InputStreamImageSource {
if (sm != null) {
try {
java.security.Permission perm =
u.openConnection().getPermission();
URLUtil.getConnectPermission(u);
if (perm != null) {
try {
sm.checkPermission(perm);