提交 a4a37abd 编写于 作者: D dtitov

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

Reviewed-by: ngthomas, michaelm
上级 4a92fecc
......@@ -50,6 +50,7 @@ import sun.misc.SoftCache;
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 @@ 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);
......@@ -796,7 +797,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);
......
......@@ -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);
......
......@@ -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);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册