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) 2001, 2019, 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
@ -333,6 +333,7 @@ class WinNTFileSystem extends FileSystem {
drive other than the current drive, insist that the caller
have read permission on the result */
String p = drive + (':' + dir + slashify(path.substring(2)));
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
try {
if (security != null) security.checkRead(p);
@ -350,6 +351,7 @@ class WinNTFileSystem extends FileSystem {
private String getUserPath() {
/* For both compatibility and security,
we must look this up every time */
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPropertyAccess("user.dir");
@ -614,6 +616,7 @@ class WinNTFileSystem extends FileSystem {
private boolean access(String path) {
try {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) security.checkRead(path);
return true;

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
@ -71,6 +71,7 @@ final class ProcessImpl extends Process {
* to append to a file does not open the file in a manner that guarantees
* that writes by the child process will be atomic.
*/
@SuppressWarnings("removal")
private static FileOutputStream newFileOutputStream(File f, boolean append)
throws IOException
{
@ -417,6 +418,7 @@ final class ProcessImpl extends Process {
private InputStream stdout_stream;
private InputStream stderr_stream;
@SuppressWarnings("removal")
private ProcessImpl(String cmd[],
final String envblock,
final String path,
@ -608,6 +610,7 @@ final class ProcessImpl extends Process {
@Override
public ProcessHandle toHandle() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission("manageProcess"));

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 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
@ -43,6 +43,7 @@ class PlainSocketImpl extends AbstractPlainSocketImpl {
private static final JavaIOFileDescriptorAccess fdAccess =
SharedSecrets.getJavaIOFileDescriptorAccess();
@SuppressWarnings("removal")
private static final boolean preferIPv4Stack =
Boolean.parseBoolean(AccessController.doPrivileged(
new GetPropertyAction("java.net.preferIPv4Stack", "false")));
@ -53,6 +54,7 @@ class PlainSocketImpl extends AbstractPlainSocketImpl {
private static final boolean useExclusiveBind;
static {
@SuppressWarnings("removal")
String exclBindProp = AccessController.doPrivileged(
new GetPropertyAction("sun.net.useExclusiveBind", ""));
useExclusiveBind = exclBindProp.isEmpty()

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 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
@ -71,6 +71,7 @@ public class NTLMAuthentication extends AuthenticationInfo {
defaultDomain = props.getProperty("http.auth.ntlm.domain", "domain");
String ntlmCacheProp = props.getProperty("jdk.ntlm.cache", "true");
ntlmCache = Boolean.parseBoolean(ntlmCacheProp);
@SuppressWarnings("removal")
String modeProp = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<String>() {
public String run() {
@ -86,6 +87,7 @@ public class NTLMAuthentication extends AuthenticationInfo {
authMode = TransparentAuth.DISABLED;
}
@SuppressWarnings("removal")
private void init0() {
hostname = java.security.AccessController.doPrivileged(

View file

@ -215,6 +215,7 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController {
/* if the JAR file is cached, the permission will always be there */
if (result != null) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
Permission perm = getPermission(result);

View file

@ -32,6 +32,7 @@ import java.security.PrivilegedAction;
* Creates this platform's default SelectorProvider
*/
@SuppressWarnings("removal")
public class DefaultSelectorProvider {
private static final SelectorProviderImpl INSTANCE;
static {

View file

@ -188,6 +188,7 @@ class PipeImpl
* loopback connection on older editions of Windows. When buffering is
* disabled then it sets TCP_NODELAY on the sink channel.
*/
@SuppressWarnings("removal")
PipeImpl(SelectorProvider sp, boolean buffering) throws IOException {
Initializer initializer = new Initializer(sp);
try {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 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
@ -50,6 +50,7 @@ class UnixDomainSocketsUtil {
* 3. %TEMP%
* 4. ${java.io.tmpdir}
*/
@SuppressWarnings("removal")
static String getTempDir() {
PrivilegedAction<String> action = () -> {
String s = NetProperties.get("jdk.net.unixdomain.tmpdir");

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -115,11 +115,12 @@ class WindowsAsynchronousServerSocketChannelImpl
*/
private class AcceptTask implements Runnable, Iocp.ResultHandler {
private final WindowsAsynchronousSocketChannelImpl channel;
@SuppressWarnings("removal")
private final AccessControlContext acc;
private final PendingFuture<AsynchronousSocketChannel,Object> result;
AcceptTask(WindowsAsynchronousSocketChannelImpl channel,
AccessControlContext acc,
@SuppressWarnings("removal") AccessControlContext acc,
PendingFuture<AsynchronousSocketChannel,Object> result)
{
this.channel = channel;
@ -138,6 +139,7 @@ class WindowsAsynchronousServerSocketChannelImpl
}
// caller must have acquired read lock for the listener and child channel.
@SuppressWarnings("removal")
void finishAccept() throws IOException {
/**
* Set local/remote addresses. This is currently very inefficient
@ -329,6 +331,7 @@ class WindowsAsynchronousServerSocketChannelImpl
// need calling context when there is security manager as
// permission check may be done in a different thread without
// any application call frames on the stack
@SuppressWarnings("removal")
AccessControlContext acc = (System.getSecurityManager() == null) ?
null : AccessController.getContext();

View file

@ -309,6 +309,7 @@ class WindowsAsynchronousSocketChannelImpl
}
}
@SuppressWarnings("removal")
private void doPrivilegedBind(final SocketAddress sa) throws IOException {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
@ -338,6 +339,7 @@ class WindowsAsynchronousSocketChannelImpl
InetSocketAddress isa = Net.checkAddress(remote);
// permission check
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkConnect(isa.getAddress().getHostAddress(), isa.getPort());

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -66,6 +66,7 @@ class WindowsAclFileAttributeView
boolean checkRead,
boolean checkWrite)
{
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
if (checkRead)

View file

@ -293,6 +293,7 @@ class WindowsChannelFactory {
// permission check
if (pathToCheck != null) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
if (flags.read)

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -77,6 +77,7 @@ class WindowsFileCopy {
// check permissions. If the source file is a symbolic link then
// later we must also check LinkPermission
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
source.checkRead();
@ -292,6 +293,7 @@ class WindowsFileCopy {
throw new UnsupportedOperationException("Unsupported copy option");
}
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
source.checkWrite();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -103,6 +103,7 @@ class WindowsFileSystem
// iterate over roots, ignoring those that the security manager denies
ArrayList<Path> result = new ArrayList<>();
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
for (int i = 0; i <= 25; i++) { // 0->A, 1->B, 2->C...
if ((drives & (1 << i)) != 0) {
@ -185,6 +186,7 @@ class WindowsFileSystem
@Override
public Iterable<FileStore> getFileStores() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -391,6 +391,7 @@ class WindowsFileSystemProvider
mask |= FILE_WRITE_DATA;
}
if (x) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkExec(file.getPathForPermissionCheck());
@ -489,6 +490,7 @@ class WindowsFileSystemProvider
@Override
public FileStore getFileStore(Path obj) throws IOException {
WindowsPath file = WindowsPath.toWindowsPath(obj);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission("getFileStoreAttributes"));
@ -548,6 +550,7 @@ class WindowsFileSystemProvider
}
// permission check
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new LinkPermission("symbolic"));
@ -603,6 +606,7 @@ class WindowsFileSystemProvider
WindowsPath existing = WindowsPath.toWindowsPath(obj2);
// permission check
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new LinkPermission("hard"));
@ -625,6 +629,7 @@ class WindowsFileSystemProvider
WindowsFileSystem fs = link.getFileSystem();
// permission check
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
FilePermission perm = new FilePermission(link.getPathForPermissionCheck(),

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -90,6 +90,7 @@ class WindowsLinkSupport {
* Returns the final path of a given path as a String. This should be used
* prior to calling Win32 system calls that do not follow links.
*/
@SuppressWarnings("removal")
static String getFinalPath(WindowsPath input, boolean followLinks)
throws IOException
{

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -880,6 +880,7 @@ class WindowsPath implements Path {
}
void checkRead() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkRead(getPathForPermissionCheck());
@ -887,6 +888,7 @@ class WindowsPath implements Path {
}
void checkWrite() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkWrite(getPathForPermissionCheck());
@ -894,6 +896,7 @@ class WindowsPath implements Path {
}
void checkDelete() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkDelete(getPathForPermissionCheck());
@ -911,6 +914,7 @@ class WindowsPath implements Path {
return this;
// permission check as per spec
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPropertyAccess("user.dir");
@ -945,6 +949,7 @@ class WindowsPath implements Path {
// copy of the modifiers and check for the Windows specific FILE_TREE
// modifier. When the modifier is present then check that permission
// has been granted recursively.
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
boolean watchSubtree = false;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -91,6 +91,7 @@ class WindowsUserDefinedFileAttributeView
return Collections.unmodifiableList(list);
}
@SuppressWarnings("removal")
@Override
public List<String> list() throws IOException {
if (System.getSecurityManager() != null)
@ -98,6 +99,7 @@ class WindowsUserDefinedFileAttributeView
return listUsingStreamEnumeration();
}
@SuppressWarnings("removal")
@Override
public int size(String name) throws IOException {
if (System.getSecurityManager() != null)
@ -125,6 +127,7 @@ class WindowsUserDefinedFileAttributeView
}
}
@SuppressWarnings("removal")
@Override
public int read(String name, ByteBuffer dst) throws IOException {
if (System.getSecurityManager() != null)
@ -160,6 +163,7 @@ class WindowsUserDefinedFileAttributeView
}
}
@SuppressWarnings("removal")
@Override
public int write(String name, ByteBuffer src) throws IOException {
if (System.getSecurityManager() != null)
@ -216,6 +220,7 @@ class WindowsUserDefinedFileAttributeView
}
}
@SuppressWarnings("removal")
@Override
public void delete(String name) throws IOException {
if (System.getSecurityManager() != null)

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -133,6 +133,7 @@ class WindowsUserPrincipals {
}
static UserPrincipal lookup(String name) throws IOException {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission("lookupUserInformation"));