8344303: Remove usage of URLUtil.getConnectPermission from sun.awt.SunToolkit and sun.awt.image.URLImageSource
Reviewed-by: prr, azvegint
This commit is contained in:
parent
7be94d043d
commit
a6220fa903
@ -291,7 +291,6 @@ module java.base {
|
||||
java.security.jgss,
|
||||
jdk.naming.dns;
|
||||
exports sun.net.util to
|
||||
java.desktop,
|
||||
java.net.http,
|
||||
jdk.jconsole,
|
||||
jdk.sctp;
|
||||
|
@ -25,10 +25,7 @@
|
||||
|
||||
package sun.net.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLPermission;
|
||||
import java.security.Permission;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@ -87,27 +84,5 @@ public class URLUtil {
|
||||
|
||||
return strForm.toString();
|
||||
}
|
||||
|
||||
public static Permission getConnectPermission(URL url) throws IOException {
|
||||
String urlStringLowerCase = url.toString().toLowerCase(Locale.ROOT);
|
||||
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());
|
||||
@SuppressWarnings("deprecation")
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,6 @@ import sun.awt.image.MultiResolutionToolkitImage;
|
||||
import sun.awt.image.ToolkitImage;
|
||||
import sun.awt.image.URLImageSource;
|
||||
import sun.font.FontDesignMetrics;
|
||||
import sun.net.util.URLUtil;
|
||||
import sun.util.logging.PlatformLogger;
|
||||
|
||||
import static java.awt.RenderingHints.KEY_TEXT_ANTIALIASING;
|
||||
@ -686,7 +685,6 @@ public abstract class SunToolkit extends Toolkit
|
||||
static final SoftCache urlImgCache = new SoftCache();
|
||||
|
||||
static Image getImageFromHash(Toolkit tk, URL url) {
|
||||
checkPermissions(url);
|
||||
synchronized (urlImgCache) {
|
||||
String key = url.toString();
|
||||
Image img = (Image)urlImgCache.get(key);
|
||||
@ -765,7 +763,6 @@ public abstract class SunToolkit extends Toolkit
|
||||
|
||||
@Override
|
||||
public Image createImage(URL url) {
|
||||
checkPermissions(url);
|
||||
return createImage(new URLImageSource(url));
|
||||
}
|
||||
|
||||
@ -882,7 +879,6 @@ public abstract class SunToolkit extends Toolkit
|
||||
@SuppressWarnings("try")
|
||||
protected static boolean imageExists(URL url) {
|
||||
if (url != null) {
|
||||
checkPermissions(url);
|
||||
try (InputStream is = url.openStream()) {
|
||||
return true;
|
||||
}catch(IOException e){
|
||||
@ -900,22 +896,6 @@ public abstract class SunToolkit extends Toolkit
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkPermissions(URL url) {
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
try {
|
||||
java.security.Permission perm =
|
||||
URLUtil.getConnectPermission(url);
|
||||
if (perm != null) {
|
||||
sm.checkPermission(perm);
|
||||
}
|
||||
} catch (java.io.IOException ioe) {
|
||||
sm.checkConnect(url.getHost(), url.getPort());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans {@code imageList} for best-looking image of specified dimensions.
|
||||
* Image can be scaled and/or padded with transparency.
|
||||
|
@ -31,7 +31,6 @@ 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;
|
||||
@ -40,21 +39,7 @@ public class URLImageSource extends InputStreamImageSource {
|
||||
int actualPort;
|
||||
|
||||
public URLImageSource(URL u) {
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
try {
|
||||
java.security.Permission perm =
|
||||
URLUtil.getConnectPermission(u);
|
||||
if (perm != null) {
|
||||
sm.checkPermission(perm);
|
||||
}
|
||||
} catch (java.io.IOException ioe) {
|
||||
sm.checkConnect(u.getHost(), u.getPort());
|
||||
}
|
||||
}
|
||||
this.url = u;
|
||||
|
||||
}
|
||||
|
||||
public URLImageSource(String href) throws MalformedURLException {
|
||||
|
Loading…
Reference in New Issue
Block a user