From a6220fa90362980fce2fc56e70c7c9a7ed7e11c5 Mon Sep 17 00:00:00 2001 From: Harshitha Onkar Date: Sun, 24 Nov 2024 06:22:45 +0000 Subject: [PATCH] 8344303: Remove usage of URLUtil.getConnectPermission from sun.awt.SunToolkit and sun.awt.image.URLImageSource Reviewed-by: prr, azvegint --- src/java.base/share/classes/module-info.java | 1 - .../share/classes/sun/net/util/URLUtil.java | 25 ------------------- .../share/classes/sun/awt/SunToolkit.java | 20 --------------- .../classes/sun/awt/image/URLImageSource.java | 15 ----------- 4 files changed, 61 deletions(-) diff --git a/src/java.base/share/classes/module-info.java b/src/java.base/share/classes/module-info.java index 057bae02efc..5a44adeb294 100644 --- a/src/java.base/share/classes/module-info.java +++ b/src/java.base/share/classes/module-info.java @@ -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; diff --git a/src/java.base/share/classes/sun/net/util/URLUtil.java b/src/java.base/share/classes/sun/net/util/URLUtil.java index 055742baf2f..3a7800394b6 100644 --- a/src/java.base/share/classes/sun/net/util/URLUtil.java +++ b/src/java.base/share/classes/sun/net/util/URLUtil.java @@ -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); - } } diff --git a/src/java.desktop/share/classes/sun/awt/SunToolkit.java b/src/java.desktop/share/classes/sun/awt/SunToolkit.java index 1dc6c2f3920..439167d6642 100644 --- a/src/java.desktop/share/classes/sun/awt/SunToolkit.java +++ b/src/java.desktop/share/classes/sun/awt/SunToolkit.java @@ -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. diff --git a/src/java.desktop/share/classes/sun/awt/image/URLImageSource.java b/src/java.desktop/share/classes/sun/awt/image/URLImageSource.java index 0cb44ae64b0..93d339e3fe1 100644 --- a/src/java.desktop/share/classes/sun/awt/image/URLImageSource.java +++ b/src/java.desktop/share/classes/sun/awt/image/URLImageSource.java @@ -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 {