8344222: Remove calls to SecurityManager and doPrivileged in java.net.HttpURLConnection, java.net.HttpConnectSocketImpl, and javax.net.HttpsURLConnection after JEP 486 integration
Reviewed-by: dfuchs, jpai
This commit is contained in:
parent
9793e73bc1
commit
25dd51e4fc
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -40,7 +40,7 @@ import java.util.Set;
|
|||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*package*/ @SuppressWarnings("removal") class HttpConnectSocketImpl extends DelegatingSocketImpl {
|
/*package*/ class HttpConnectSocketImpl extends DelegatingSocketImpl {
|
||||||
|
|
||||||
private static final String httpURLClazzStr =
|
private static final String httpURLClazzStr =
|
||||||
"sun.net.www.protocol.http.HttpURLConnection";
|
"sun.net.www.protocol.http.HttpURLConnection";
|
||||||
@ -59,18 +59,11 @@ import java.util.Set;
|
|||||||
try {
|
try {
|
||||||
Class<?> httpClazz = Class.forName(httpURLClazzStr, true, null);
|
Class<?> httpClazz = Class.forName(httpURLClazzStr, true, null);
|
||||||
httpField = httpClazz.getDeclaredField("http");
|
httpField = httpClazz.getDeclaredField("http");
|
||||||
|
httpField.setAccessible(true);
|
||||||
doTunneling = httpClazz.getDeclaredMethod(doTunnelingStr);
|
doTunneling = httpClazz.getDeclaredMethod(doTunnelingStr);
|
||||||
Class<?> netClientClazz = Class.forName(netClientClazzStr, true, null);
|
Class<?> netClientClazz = Class.forName(netClientClazzStr, true, null);
|
||||||
serverSocketField = netClientClazz.getDeclaredField("serverSocket");
|
serverSocketField = netClientClazz.getDeclaredField("serverSocket");
|
||||||
|
serverSocketField.setAccessible(true);
|
||||||
java.security.AccessController.doPrivileged(
|
|
||||||
new java.security.PrivilegedAction<>() {
|
|
||||||
public Void run() {
|
|
||||||
httpField.setAccessible(true);
|
|
||||||
serverSocketField.setAccessible(true);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (ReflectiveOperationException x) {
|
} catch (ReflectiveOperationException x) {
|
||||||
throw new InternalError("Should not reach here", x);
|
throw new InternalError("Should not reach here", x);
|
||||||
}
|
}
|
||||||
@ -107,16 +100,12 @@ import java.util.Set;
|
|||||||
: epoint.getAddress().getHostAddress();
|
: epoint.getAddress().getHostAddress();
|
||||||
final int destPort = epoint.getPort();
|
final int destPort = epoint.getPort();
|
||||||
|
|
||||||
SecurityManager security = System.getSecurityManager();
|
|
||||||
if (security != null)
|
|
||||||
security.checkConnect(destHost, destPort);
|
|
||||||
|
|
||||||
if (destHost.contains(":"))
|
if (destHost.contains(":"))
|
||||||
destHost = "[" + destHost + "]";
|
destHost = "[" + destHost + "]";
|
||||||
|
|
||||||
// Connect to the HTTP proxy server
|
// Connect to the HTTP proxy server
|
||||||
String urlString = "http://" + destHost + ":" + destPort;
|
String urlString = "http://" + destHost + ":" + destPort;
|
||||||
Socket httpSocket = privilegedDoTunnel(urlString, timeout);
|
Socket httpSocket = doTunnel(urlString, timeout);
|
||||||
|
|
||||||
// Success!
|
// Success!
|
||||||
external_address = epoint;
|
external_address = epoint;
|
||||||
@ -164,22 +153,6 @@ import java.util.Set;
|
|||||||
optionsMap.put(opt, val);
|
optionsMap.put(opt, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Socket privilegedDoTunnel(final String urlString,
|
|
||||||
final int timeout)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return java.security.AccessController.doPrivileged(
|
|
||||||
new java.security.PrivilegedExceptionAction<>() {
|
|
||||||
public Socket run() throws IOException {
|
|
||||||
return doTunnel(urlString, timeout);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (java.security.PrivilegedActionException pae) {
|
|
||||||
throw (IOException) pae.getException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Socket doTunnel(String urlString, int connectTimeout)
|
private Socket doTunnel(String urlString, int connectTimeout)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
@ -368,12 +368,6 @@ public abstract class HttpURLConnection extends URLConnection {
|
|||||||
* @see #getFollowRedirects()
|
* @see #getFollowRedirects()
|
||||||
*/
|
*/
|
||||||
public static void setFollowRedirects(boolean set) {
|
public static void setFollowRedirects(boolean set) {
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sec = System.getSecurityManager();
|
|
||||||
if (sec != null) {
|
|
||||||
// seems to be the best check here...
|
|
||||||
sec.checkSetFactory();
|
|
||||||
}
|
|
||||||
followRedirects = set;
|
followRedirects = set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,13 +446,6 @@ public abstract class HttpURLConnection extends URLConnection {
|
|||||||
|
|
||||||
for (int i = 0; i < methods.length; i++) {
|
for (int i = 0; i < methods.length; i++) {
|
||||||
if (methods[i].equals(method)) {
|
if (methods[i].equals(method)) {
|
||||||
if (method.equals("TRACE")) {
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager s = System.getSecurityManager();
|
|
||||||
if (s != null) {
|
|
||||||
s.checkPermission(new NetPermission("allowHttpTrace"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.method = method;
|
this.method = method;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,6 @@ public abstract class HttpsURLConnection extends HttpURLConnection {
|
|||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"no default HostnameVerifier specified");
|
"no default HostnameVerifier specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultHostnameVerifier = v;
|
defaultHostnameVerifier = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +299,6 @@ public abstract class HttpsURLConnection extends HttpURLConnection {
|
|||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"no default SSLSocketFactory specified");
|
"no default SSLSocketFactory specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultSSLSocketFactory = sf;
|
defaultSSLSocketFactory = sf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +340,6 @@ public abstract class HttpsURLConnection extends HttpURLConnection {
|
|||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"no SSLSocketFactory specified");
|
"no SSLSocketFactory specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
sslSocketFactory = sf;
|
sslSocketFactory = sf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -165,6 +165,6 @@ class ProxyHandler extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws SecurityException {
|
public void close() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user