8266459: Implement JEP 411: Deprecate the Security Manager for Removal

Co-authored-by: Sean Mullan <mullan@openjdk.org>
Co-authored-by: Lance Andersen <lancea@openjdk.org>
Co-authored-by: Weijun Wang <weijun@openjdk.org>
Reviewed-by: erikj, darcy, chegar, naoto, joehw, alanb, mchung, kcr, prr, lancea
This commit is contained in:
Weijun Wang 2021-06-02 11:57:31 +00:00
parent 19450b9951
commit 6765f90250
826 changed files with 2734 additions and 757 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,7 @@ package sun.net;
import java.security.PrivilegedAction;
import java.security.Security;
@SuppressWarnings("removal")
public final class InetAddressCachePolicy {
// Controls the cache policy for successful lookups only

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -40,6 +40,7 @@ import java.util.Properties;
*
*/
@SuppressWarnings("removal")
public class NetProperties {
private static Properties props = new Properties();
static {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -39,6 +39,7 @@ import java.security.PrivilegedAction;
*
* @author Jonathan Payne
*/
@SuppressWarnings("removal")
public class NetworkClient {
/* Default value of read timeout, if not specified (infinity) */
public static final int DEFAULT_READ_TIMEOUT = -1;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -65,6 +65,7 @@ public class ResourceManager {
numSockets = new AtomicInteger();
}
@SuppressWarnings("removal")
public static void beforeUdpCreate() throws SocketException {
if (System.getSecurityManager() != null) {
if (numSockets.incrementAndGet() > maxSockets) {
@ -74,6 +75,7 @@ public class ResourceManager {
}
}
@SuppressWarnings("removal")
public static void afterUdpClose() {
if (System.getSecurityManager() != null) {
numSockets.decrementAndGet();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -55,6 +55,7 @@ public abstract class FtpClientProvider {
* {@link RuntimePermission}{@code ("ftpClientProvider")}
*/
protected FtpClientProvider() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission("ftpClientProvider"));
@ -134,6 +135,7 @@ public abstract class FtpClientProvider {
*
* @return The system-wide default FtpClientProvider
*/
@SuppressWarnings("removal")
public static FtpClientProvider provider() {
synchronized (lock) {
if (provider != null) {

View file

@ -48,6 +48,7 @@ import sun.net.ftp.*;
import sun.util.logging.PlatformLogger;
@SuppressWarnings("removal")
public class FtpClient extends sun.net.ftp.FtpClient {
private static int defaultSoTimeout;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -92,6 +92,7 @@ public class DefaultProxySelector extends ProxySelector {
static {
final String key = "java.net.useSystemProxies";
@SuppressWarnings("removal")
Boolean b = AccessController.doPrivileged(
new PrivilegedAction<Boolean>() {
public Boolean run() {
@ -103,6 +104,7 @@ public class DefaultProxySelector extends ProxySelector {
}
}
@SuppressWarnings("removal")
public static int socksProxyVersion() {
return AccessController.doPrivileged(
new PrivilegedAction<Integer>() {
@ -211,6 +213,7 @@ public class DefaultProxySelector extends ProxySelector {
* System properties it does help having only 1 call to doPrivileged.
* Be mindful what you do in here though!
*/
@SuppressWarnings("removal")
Proxy[] proxyArray = AccessController.doPrivileged(
new PrivilegedAction<Proxy[]>() {
public Proxy[] run() {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -352,6 +352,7 @@ public class IPAddressUtil {
}
}
@SuppressWarnings("removal")
private static InetAddress findScopedAddress(InetAddress address) {
PrivilegedExceptionAction<List<InetAddress>> pa = () -> NetworkInterface.networkInterfaces()
.flatMap(NetworkInterface::inetAddresses)

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -93,6 +93,7 @@ public final class SocketExceptions {
// msg, or if the type doesn't support detail msgs, return given
// instance.
@SuppressWarnings("removal")
private static IOException create(IOException e, String msg) {
return AccessController.doPrivileged(new PrivilegedAction<IOException>() {
public IOException run() {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,6 +33,7 @@ import java.util.Enumeration;
import java.util.Properties;
import java.util.StringTokenizer;
@SuppressWarnings("removal")
public class MimeTable implements FileNameMap {
/** Keyed by content type, returns MimeEntries */
private Hashtable<String, MimeEntry> entries

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -65,6 +65,7 @@ public class HttpCapture {
private static synchronized void init() {
initialized = true;
@SuppressWarnings("removal")
String rulesFile = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<>() {
public String run() {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -353,6 +353,7 @@ public class HttpClient extends NetworkClient {
ret.authenticatorKey = httpuc.getAuthenticatorKey();
}
} else {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
if (ret.proxy == Proxy.NO_PROXY || ret.proxy == null) {
@ -544,6 +545,7 @@ public class HttpClient extends NetworkClient {
/*
* call openServer in a privileged block
*/
@SuppressWarnings("removal")
private void privilegedOpenServer(final InetSocketAddress server)
throws IOException
{
@ -575,6 +577,7 @@ public class HttpClient extends NetworkClient {
*/
protected void openServer() throws IOException {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
lock();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -62,6 +62,7 @@ public class KeepAliveCache
*/
static final int MAX_CONNECTIONS = 5;
static int result = -1;
@SuppressWarnings("removal")
static int getMaxConnections() {
if (result == -1) {
result = AccessController.doPrivileged(
@ -90,6 +91,7 @@ public class KeepAliveCache
* @param url The URL contains info about the host and port
* @param http The HttpClient to be cached
*/
@SuppressWarnings("removal")
public void put(final URL url, Object obj, HttpClient http) {
cacheLock.lock();
try {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -158,6 +158,7 @@ class KeepAliveStream extends MeteredStream implements Hurryable {
}
}
@SuppressWarnings("removal")
private static void queueForCleanup(KeepAliveCleanerEntry kace) {
queue.lock();
try {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -64,6 +64,7 @@ class KeepAliveStreamCleaner
static {
final String maxDataKey = "http.KeepAlive.remainingData";
@SuppressWarnings("removal")
int maxData = AccessController.doPrivileged(
new PrivilegedAction<Integer>() {
public Integer run() {
@ -72,6 +73,7 @@ class KeepAliveStreamCleaner
MAX_DATA_REMAINING = maxData;
final String maxCapacityKey = "http.KeepAlive.queuedConnections";
@SuppressWarnings("removal")
int maxCapacity = AccessController.doPrivileged(
new PrivilegedAction<Integer>() {
public Integer run() {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -235,6 +235,7 @@ public class FtpURLConnection extends URLConnection {
/**
* Do we have to use a proxy?
*/
@SuppressWarnings("removal")
ProxySelector sel = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<ProxySelector>() {
public ProxySelector run() {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -53,6 +53,7 @@ import sun.net.www.HeaderParser;
// policy in HttpURLConnection. A failure on baz.foo.com shouldn't
// uncache foo.com!
@SuppressWarnings("removal")
public abstract class AuthenticationInfo extends AuthCacheValue implements Cloneable {
@java.io.Serial

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -64,6 +64,7 @@ class DigestAuthentication extends AuthenticationInfo {
private static final boolean delimCompatFlag;
static {
@SuppressWarnings("removal")
Boolean b = AccessController.doPrivileged(
new PrivilegedAction<>() {
public Boolean run() {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -219,6 +219,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
"Via"
};
@SuppressWarnings("removal")
private static String getNetProperty(String name) {
PrivilegedAction<String> pa = () -> NetProperties.get(name);
return AccessController.doPrivileged(pa);
@ -454,6 +455,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* privileged request password authentication
*
*/
@SuppressWarnings("removal")
private static PasswordAuthentication
privilegedRequestPasswordAuthentication(
final Authenticator authenticator,
@ -766,6 +768,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
}
private boolean checkSetHost() {
@SuppressWarnings("removal")
SecurityManager s = System.getSecurityManager();
if (s != null) {
String name = s.getClass().getName();
@ -786,6 +789,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
}
private void checkURLFile() {
@SuppressWarnings("removal")
SecurityManager s = System.getSecurityManager();
if (s != null) {
String name = s.getClass().getName();
@ -909,6 +913,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
return u;
}
@SuppressWarnings("removal")
protected HttpURLConnection(URL u, Proxy p, Handler handler)
throws IOException {
super(checkURL(u));
@ -1008,6 +1013,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
//
// Same as java.net.URL.hostsEqual
//
@SuppressWarnings("removal")
private static boolean hostsEqual(URL u1, URL u2) {
final String h1 = u1.getHost();
final String h2 = u2.getHost();
@ -1066,6 +1072,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
return false;
}
@SuppressWarnings("removal")
private String getHostAndPort(URL url) {
String host = url.getHost();
final String hostarg = host;
@ -1092,6 +1099,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
return host + ":" + Integer.toString(port);
}
@SuppressWarnings("removal")
protected void plainConnect() throws IOException {
lock();
try {
@ -1133,6 +1141,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
return socketPermission;
}
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
@ -1205,6 +1214,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
/**
* Do we have to use a proxy?
*/
@SuppressWarnings("removal")
ProxySelector sel =
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<>() {
@ -1367,6 +1377,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* - get input, [read input,] get output, [write output]
*/
@SuppressWarnings("removal")
@Override
public OutputStream getOutputStream() throws IOException {
lock();
@ -1554,6 +1565,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
} // end of getting cookies
}
@SuppressWarnings("removal")
@Override
public InputStream getInputStream() throws IOException {
lock();
@ -2025,6 +2037,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
private IOException getChainedException(final IOException rememberedException) {
try {
final Object[] args = { rememberedException.getMessage() };
@SuppressWarnings("removal")
IOException chainedException =
java.security.AccessController.doPrivileged(
new java.security.PrivilegedExceptionAction<>() {
@ -2340,7 +2353,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* Gets the authentication for an HTTP proxy, and applies it to
* the connection.
*/
@SuppressWarnings("fallthrough")
@SuppressWarnings({"removal","fallthrough"})
private AuthenticationInfo getHttpProxyAuthentication(AuthenticationHeader authhdr) {
assert isLockHeldByCurrentThread();
@ -2731,6 +2744,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* resets the url, re-connects, and resets the request
* property.
*/
@SuppressWarnings("removal")
private boolean followRedirect() throws IOException {
if (!getInstanceFollowRedirects()) {
return false;
@ -2815,6 +2829,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
String proxyHost = locUrl.getHost();
int proxyPort = locUrl.getPort();
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkConnect(proxyHost, proxyPort);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -382,6 +382,7 @@ final class HttpsClient extends HttpClient
ret.authenticatorKey = httpuc.getAuthenticatorKey();
}
} else {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
if (ret.proxy == Proxy.NO_PROXY || ret.proxy == null) {

View file

@ -189,6 +189,7 @@ public class URLJarFile extends JarFile {
* Given a URL, retrieves a JAR file, caches it to disk, and creates a
* cached JAR file object.
*/
@SuppressWarnings("removal")
private static JarFile retrieve(final URL url, final URLJarFileCloseController closeController) throws IOException {
/*
* See if interface is set, then call retrieve function of the class

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -47,6 +47,7 @@ import sun.net.www.URLConnection;
* URLConnection implementation that can be used to connect to resources
* contained in the runtime image.
*/
@SuppressWarnings("removal")
public class JavaRuntimeURLConnection extends URLConnection {
// ImageReader to access resources in jimage

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -68,6 +68,7 @@ public class MailToURLConnection extends URLConnection {
String str = System.getProperty("user.fromaddr");
if (str == null) {
// Perform the property security check for user.name
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPropertyAccess("user.name");