Skip to content

Commit 6a5256e

Browse files
author
Stuart Marks
committed
8344149: Remove usage of Security Manager from java.rmi
Reviewed-by: rriggs, kevinw, aefimov
1 parent 0b1f571 commit 6a5256e

27 files changed

+173
-716
lines changed

src/java.rmi/share/classes/java/rmi/MarshalledObject.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -35,8 +35,6 @@
3535
import java.io.ObjectStreamConstants;
3636
import java.io.OutputStream;
3737
import java.io.Serializable;
38-
import java.security.AccessController;
39-
import java.security.PrivilegedAction;
4038

4139
import sun.rmi.server.MarshalInputStream;
4240
import sun.rmi.server.MarshalOutputStream;
@@ -317,21 +315,17 @@ private static class MarshalledObjectInputStream
317315
* <code>null</code>, then all annotations will be
318316
* <code>null</code>.
319317
*/
320-
@SuppressWarnings("removal")
321318
MarshalledObjectInputStream(InputStream objIn, InputStream locIn,
322319
ObjectInputFilter filter)
323320
throws IOException
324321
{
325322
super(objIn);
326323
this.locIn = (locIn == null ? null : new ObjectInputStream(locIn));
327324
if (filter != null) {
328-
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
329-
MarshalledObjectInputStream.this.setObjectInputFilter(filter);
330-
if (MarshalledObjectInputStream.this.locIn != null) {
331-
MarshalledObjectInputStream.this.locIn.setObjectInputFilter(filter);
332-
}
333-
return null;
334-
});
325+
MarshalledObjectInputStream.this.setObjectInputFilter(filter);
326+
if (MarshalledObjectInputStream.this.locIn != null) {
327+
MarshalledObjectInputStream.this.locIn.setObjectInputFilter(filter);
328+
}
335329
}
336330
}
337331

src/java.rmi/share/classes/java/rmi/server/LogStream.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -120,14 +120,6 @@ public static synchronized PrintStream getDefaultStream() {
120120
*/
121121
@Deprecated
122122
public static synchronized void setDefaultStream(PrintStream newDefault) {
123-
@SuppressWarnings("removal")
124-
SecurityManager sm = System.getSecurityManager();
125-
126-
if (sm != null) {
127-
sm.checkPermission(
128-
new java.util.logging.LoggingPermission("control", null));
129-
}
130-
131123
defaultStream = newDefault;
132124
}
133125

src/java.rmi/share/classes/java/rmi/server/ObjID.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,8 +30,6 @@
3030
import java.io.ObjectInput;
3131
import java.io.ObjectOutput;
3232
import java.io.Serializable;
33-
import java.security.AccessController;
34-
import java.security.PrivilegedAction;
3533
import java.security.SecureRandom;
3634
import java.util.concurrent.atomic.AtomicLong;
3735

@@ -242,9 +240,7 @@ public String toString() {
242240
}
243241

244242
private static boolean useRandomIDs() {
245-
@SuppressWarnings("removal")
246-
String value = AccessController.doPrivileged(
247-
(PrivilegedAction<String>) () -> System.getProperty("java.rmi.server.randomIDs"));
243+
String value = System.getProperty("java.rmi.server.randomIDs");
248244
return value == null ? true : Boolean.parseBoolean(value);
249245
}
250246
}

src/java.rmi/share/classes/java/rmi/server/RMIClassLoader.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
import java.net.MalformedURLException;
2929
import java.net.URL;
30-
import java.security.AccessController;
31-
import java.security.PrivilegedAction;
3230
import java.util.Iterator;
3331
import java.util.ServiceLoader;
3432

@@ -112,12 +110,7 @@ public class RMIClassLoader {
112110
newDefaultProviderInstance();
113111

114112
/** provider instance */
115-
@SuppressWarnings("removal")
116-
private static final RMIClassLoaderSpi provider =
117-
AccessController.doPrivileged(
118-
new PrivilegedAction<RMIClassLoaderSpi>() {
119-
public RMIClassLoaderSpi run() { return initializeProvider(); }
120-
});
113+
private static final RMIClassLoaderSpi provider = initializeProvider();
121114

122115
/*
123116
* Disallow anyone from creating one of these.
@@ -538,11 +531,6 @@ public static String getClassAnnotation(Class<?> cl) {
538531
* @since 1.4
539532
*/
540533
public static RMIClassLoaderSpi getDefaultProviderInstance() {
541-
@SuppressWarnings("removal")
542-
SecurityManager sm = System.getSecurityManager();
543-
if (sm != null) {
544-
sm.checkPermission(new RuntimePermission("setFactory"));
545-
}
546534
return defaultProvider;
547535
}
548536

src/java.rmi/share/classes/java/rmi/server/RMISocketFactory.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@ public static synchronized void setSocketFactory(RMISocketFactory fac)
131131
if (factory != null) {
132132
throw new SocketException("factory already defined");
133133
}
134-
@SuppressWarnings("removal")
135-
SecurityManager security = System.getSecurityManager();
136-
if (security != null) {
137-
security.checkSetFactory();
138-
}
139134
factory = fac;
140135
}
141136

@@ -181,11 +176,6 @@ public static synchronized RMISocketFactory getDefaultSocketFactory() {
181176
*/
182177
public static synchronized void setFailureHandler(RMIFailureHandler fh)
183178
{
184-
@SuppressWarnings("removal")
185-
SecurityManager security = System.getSecurityManager();
186-
if (security != null) {
187-
security.checkSetFactory();
188-
}
189179
handler = fh;
190180
}
191181

src/java.rmi/share/classes/sun/rmi/log/ReliableLog.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,9 +27,6 @@
2727

2828
import java.io.*;
2929
import java.lang.reflect.Constructor;
30-
import java.rmi.server.RMIClassLoader;
31-
import java.security.AccessController;
32-
import java.security.PrivilegedAction;
3330

3431
/**
3532
* This class is a simple implementation of a reliable Log. The
@@ -132,15 +129,13 @@ public class ReliableLog {
132129
* if an exception occurs during invocation of the handler's
133130
* snapshot method or if other IOException occurs.
134131
*/
135-
@SuppressWarnings("removal")
136132
public ReliableLog(String dirPath,
137133
LogHandler handler,
138134
boolean pad)
139135
throws IOException
140136
{
141137
super();
142-
this.Debug = AccessController.doPrivileged(
143-
(PrivilegedAction<Boolean>) () -> Boolean.getBoolean("sun.rmi.log.debug"));
138+
this.Debug = Boolean.getBoolean("sun.rmi.log.debug");
144139
dir = new File(dirPath);
145140
if (!(dir.exists() && dir.isDirectory())) {
146141
// create directory
@@ -331,19 +326,10 @@ public synchronized void update(Object value, boolean forceToDisk)
331326
private static Constructor<? extends LogFile>
332327
getLogClassConstructor() {
333328

334-
@SuppressWarnings("removal")
335-
String logClassName = AccessController.doPrivileged(
336-
(PrivilegedAction<String>) () -> System.getProperty("sun.rmi.log.class"));
329+
String logClassName = System.getProperty("sun.rmi.log.class");
337330
if (logClassName != null) {
338331
try {
339-
@SuppressWarnings("removal")
340-
ClassLoader loader =
341-
AccessController.doPrivileged(
342-
new PrivilegedAction<ClassLoader>() {
343-
public ClassLoader run() {
344-
return ClassLoader.getSystemClassLoader();
345-
}
346-
});
332+
ClassLoader loader = ClassLoader.getSystemClassLoader();
347333
Class<? extends LogFile> cl =
348334
loader.loadClass(logClassName).asSubclass(LogFile.class);
349335
return cl.getConstructor(String.class, String.class);

src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ public String[] list()
263263
* Check that the caller has access to perform indicated operation.
264264
* The client must be on same the same host as this server.
265265
*/
266-
@SuppressWarnings("removal")
267266
public static void checkAccess(String op) throws AccessException {
268267

269268
try {
@@ -370,7 +369,6 @@ private static URL[] pathToURLs(String path) {
370369
* {@link ObjectInputFilter.Status#REJECTED} if rejected,
371370
* otherwise {@link ObjectInputFilter.Status#UNDECIDED}
372371
*/
373-
@SuppressWarnings("removal")
374372
private static ObjectInputFilter.Status registryFilter(ObjectInputFilter.FilterInfo filterInfo) {
375373
if (registryFilter != null) {
376374
ObjectInputFilter.Status status = registryFilter.checkInput(filterInfo);

src/java.rmi/share/classes/sun/rmi/runtime/Log.java

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,7 +30,6 @@
3030
import java.io.OutputStream;
3131
import java.lang.StackWalker.StackFrame;
3232
import java.rmi.server.LogStream;
33-
import java.security.PrivilegedAction;
3433
import java.util.Set;
3534
import java.util.logging.Handler;
3635
import java.util.logging.SimpleFormatter;
@@ -69,9 +68,7 @@ public abstract class Log {
6968
/* selects log implementation */
7069
private static final LogFactory logFactory;
7170
static {
72-
@SuppressWarnings("removal")
73-
boolean useOld = java.security.AccessController.doPrivileged(
74-
(PrivilegedAction<Boolean>) () -> Boolean.getBoolean("sun.rmi.log.useOld"));
71+
boolean useOld = Boolean.getBoolean("sun.rmi.log.useOld");
7572

7673
/* set factory to select the logging facility to use */
7774
logFactory = (useOld ? (LogFactory) new LogStreamLogFactory() :
@@ -177,17 +174,12 @@ public Log createLog(final String loggerName, String oldLogName,
177174
private static class LoggerLog extends Log {
178175

179176
/* alternate console handler for RMI loggers */
180-
@SuppressWarnings("removal")
181-
private static final Handler alternateConsole =
182-
java.security.AccessController.doPrivileged(
183-
new java.security.PrivilegedAction<Handler>() {
184-
public Handler run() {
185-
InternalStreamHandler alternate =
186-
new InternalStreamHandler(System.err);
187-
alternate.setLevel(Level.ALL);
188-
return alternate;
189-
}
190-
});
177+
private static final Handler alternateConsole;
178+
static {
179+
var alternate = new InternalStreamHandler(System.err);
180+
alternate.setLevel(Level.ALL);
181+
alternateConsole = alternate;
182+
}
191183

192184
/** handler to which messages are copied */
193185
private InternalStreamHandler copyHandler = null;
@@ -199,22 +191,14 @@ public Handler run() {
199191
private LoggerPrintStream loggerSandwich;
200192

201193
/** creates a Log which will delegate to the given logger */
202-
@SuppressWarnings("removal")
203194
private LoggerLog(final Logger logger, final Level level) {
204195
this.logger = logger;
205196

206-
if (level != null){
207-
java.security.AccessController.doPrivileged(
208-
new java.security.PrivilegedAction<Void>() {
209-
public Void run() {
210-
if (!logger.isLoggable(level)) {
211-
logger.setLevel(level);
212-
}
213-
logger.addHandler(alternateConsole);
214-
return null;
215-
}
216-
}
217-
);
197+
if (level != null) {
198+
if (!logger.isLoggable(level)) {
199+
logger.setLevel(level);
200+
}
201+
logger.addHandler(alternateConsole);
218202
}
219203
}
220204

@@ -247,8 +231,6 @@ public String toString() {
247231
/**
248232
* Set the output stream associated with the RMI server call
249233
* logger.
250-
*
251-
* Calling code needs LoggingPermission "control".
252234
*/
253235
public synchronized void setOutputStream(OutputStream out) {
254236
if (out != null) {

src/java.rmi/share/classes/sun/rmi/runtime/NewThreadAction.java

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,13 +25,11 @@
2525

2626
package sun.rmi.runtime;
2727

28-
import java.security.AccessController;
29-
import java.security.PrivilegedAction;
30-
import sun.security.util.SecurityConstants;
31-
3228
/**
33-
* A PrivilegedAction for creating a new thread conveniently with an
34-
* AccessController.doPrivileged construct.
29+
* A utility class for creating threads. The constructors take a
30+
* variety of parameters to configure the thread. The run() method
31+
* creates and sets up the thread and returns it, but does not
32+
* start it.
3533
*
3634
* All constructors allow the choice of the Runnable for the new
3735
* thread to execute, the name of the new thread (which will be
@@ -48,34 +46,27 @@
4846
*
4947
* @author Peter Jones
5048
**/
51-
public final class NewThreadAction implements PrivilegedAction<Thread> {
49+
public final class NewThreadAction {
5250

5351
/** cached reference to the system (root) thread group */
54-
@SuppressWarnings("removal")
55-
static final ThreadGroup systemThreadGroup =
56-
AccessController.doPrivileged(new PrivilegedAction<ThreadGroup>() {
57-
public ThreadGroup run() {
58-
ThreadGroup group = Thread.currentThread().getThreadGroup();
59-
ThreadGroup parent;
60-
while ((parent = group.getParent()) != null) {
61-
group = parent;
62-
}
63-
return group;
64-
}
65-
});
52+
static final ThreadGroup systemThreadGroup;
53+
static {
54+
ThreadGroup group = Thread.currentThread().getThreadGroup();
55+
ThreadGroup parent;
56+
while ((parent = group.getParent()) != null) {
57+
group = parent;
58+
}
59+
systemThreadGroup = group;
60+
}
61+
6662

6763
/**
68-
* special child of the system thread group for running tasks that
69-
* may execute user code, so that the security policy for threads in
70-
* the system thread group will not apply
64+
* Special child of the system thread group for running tasks that
65+
* may execute user code. The need for a separate thread group may
66+
* be a vestige of it having had a different security policy from
67+
* the system thread group, so this might no longer be necessary.
7168
*/
72-
@SuppressWarnings("removal")
73-
static final ThreadGroup userThreadGroup =
74-
AccessController.doPrivileged(new PrivilegedAction<ThreadGroup>() {
75-
public ThreadGroup run() {
76-
return new ThreadGroup(systemThreadGroup, "RMI Runtime");
77-
}
78-
});
69+
static final ThreadGroup userThreadGroup = new ThreadGroup(systemThreadGroup, "RMI Runtime");
7970

8071
private final ThreadGroup group;
8172
private final Runnable runnable;
@@ -128,11 +119,6 @@ public NewThreadAction(Runnable runnable, String name, boolean daemon,
128119
}
129120

130121
public Thread run() {
131-
@SuppressWarnings("removal")
132-
SecurityManager sm = System.getSecurityManager();
133-
if (sm != null) {
134-
sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
135-
}
136122
Thread t = new Thread(group, runnable, "RMI " + name);
137123
t.setContextClassLoader(ClassLoader.getSystemClassLoader());
138124
t.setDaemon(daemon);

0 commit comments

Comments
 (0)