Skip to content

Commit 576161d

Browse files
committed
8266459: Implement JEP 411: Deprecate the Security Manager for Removal
1 parent 79b3944 commit 576161d

File tree

21 files changed

+205
-33
lines changed

21 files changed

+205
-33
lines changed

make/RunTests.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ define SetupRunJtregTestBody
769769
-vmoption:-XX:MaxRAMPercentage=$$($1_JTREG_MAX_RAM_PERCENTAGE) \
770770
-vmoption:-Djava.io.tmpdir="$$($1_TEST_TMP_DIR)"
771771

772-
$1_JTREG_BASIC_OPTIONS += -automatic -ignore:quiet
772+
$1_JTREG_BASIC_OPTIONS += -automatic -ignore:quiet -Djavatest.security.noSecurityManager=true
773773

774774
# Make it possible to specify the JIB_DATA_DIR for tests using the
775775
# JIB Artifact resolver

src/java.base/share/classes/java/lang/SecurityManager.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,36 +80,37 @@
8080
* <p>
8181
* Environments using a security manager will typically set the security
8282
* manager at startup. In the JDK implementation, this is done by setting
83-
* the system property {@code java.security.manager} on the command line to
84-
* the class name of the security manager. It can also be set to the empty
85-
* String ("") or the special token "{@code default}" to use the
83+
* the system property {@systemProperty java.security.manager} on the command
84+
* line to the class name of the security manager. It can also be set to the
85+
* empty String ("") or the special token "{@code default}" to use the
8686
* default {@code java.lang.SecurityManager}. If a class name is specified,
8787
* it must be {@code java.lang.SecurityManager} or a public subclass and have
8888
* a public no-arg constructor. The class is loaded by the
8989
* {@linkplain ClassLoader#getSystemClassLoader() built-in system class loader}
90-
* if it is not {@code java.lang.SecurityManager}. If the
91-
* {@code java.security.manager} system property is not set, the default value
92-
* is {@code null}, which means a security manager will not be set at startup.
90+
* if it is not {@code java.lang.SecurityManager}.
9391
* <p>
9492
* The Java run-time may also allow, but is not required to allow, the security
9593
* manager to be set dynamically by invoking the
9694
* {@link System#setSecurityManager(SecurityManager) setSecurityManager} method.
97-
* In the JDK implementation, if the Java virtual machine is started with
98-
* the {@code java.security.manager} system property set to the special token
99-
* "{@code disallow}" then a security manager will not be set at startup and
100-
* cannot be set dynamically (the
95+
* In the JDK implementation, the default value of the
96+
* {@systemProperty java.security.manager} system property, if not set, is
97+
* the special token "{@code disallow}". If the Java virtual machine is
98+
* started with the {@systemProperty java.security.manager} system property
99+
* not set or set to "{@code disallow}" then a security manager will not be
100+
* set at startup and cannot be set dynamically (the
101101
* {@link System#setSecurityManager(SecurityManager) setSecurityManager}
102102
* method will throw an {@code UnsupportedOperationException}). If the
103-
* {@code java.security.manager} system property is not set or is set to the
103+
* {@systemProperty java.security.manager} system property is set to the
104104
* special token "{@code allow}", then a security manager will not be set at
105105
* startup but can be set dynamically. Finally, if the
106-
* {@code java.security.manager} system property is set to the class name of
107-
* the security manager, or to the empty String ("") or the special token
108-
* "{@code default}", then a security manager is set at startup (as described
109-
* previously) and can also be subsequently replaced (or disabled) dynamically
110-
* (subject to the policy of the currently installed security manager). The
111-
* following table illustrates the behavior of the JDK implementation for the
112-
* different settings of the {@code java.security.manager} system property:
106+
* {@systemProperty java.security.manager} system property is set to the
107+
* class name of the security manager, or to the empty String ("") or the
108+
* special token "{@code default}", then a security manager is set at startup
109+
* (as described previously) and can also be subsequently replaced (or
110+
* disabled) dynamically (subject to the policy of the currently installed
111+
* security manager). The following table illustrates the behavior of the JDK
112+
* implementation for the different settings of the
113+
* {@systemProperty java.security.manager} system property:
113114
* <table class="striped">
114115
* <caption style="display:none">property value,
115116
* the SecurityManager set at startup,
@@ -167,8 +168,6 @@
167168
*
168169
* </tbody>
169170
* </table>
170-
* <p> A future release of the JDK may change the default value of the
171-
* {@code java.security.manager} system property to "{@code disallow}".
172171
* <p>
173172
* The current security manager is returned by the
174173
* {@link System#getSecurityManager() getSecurityManager} method.
@@ -313,7 +312,12 @@
313312
* @see java.security.ProtectionDomain
314313
*
315314
* @since 1.0
315+
* @deprecated The Security Manager is deprecated and subject to removal in a
316+
* future release. There is no replacement for the Security Manager.
317+
* See <a href="https://openjdk.java.net/jeps/411">JEP 411</a> for
318+
* discussion and alternatives.
316319
*/
320+
@Deprecated(since="17", forRemoval=true)
317321
public class SecurityManager {
318322

319323
/*
@@ -1084,7 +1088,7 @@ public void checkMulticast(InetAddress maddr) {
10841088
* @deprecated Use #checkPermission(java.security.Permission) instead
10851089
* @see #checkPermission(java.security.Permission) checkPermission
10861090
*/
1087-
@Deprecated(since="1.4")
1091+
@Deprecated(since="1.4", forRemoval=true)
10881092
public void checkMulticast(InetAddress maddr, byte ttl) {
10891093
String host = maddr.getHostAddress();
10901094
if (!host.startsWith("[") && host.indexOf(':') != -1) {

src/java.base/share/classes/java/lang/System.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,16 @@ private static void checkIO() {
338338
* security manager has been established, then no action is taken and
339339
* the method simply returns.
340340
*
341-
* @implNote In the JDK implementation, if the Java virtual machine is
342-
* started with the system property {@code java.security.manager} set to
343-
* the special token "{@code disallow}" then the {@code setSecurityManager}
344-
* method cannot be used to set a security manager.
341+
* @implNote In the JDK implementation, the default value of the
342+
* {@systemProperty java.security.manager} system property, if not set, is
343+
* the special token "{@code disallow}". If the Java virtual machine is
344+
* started with the {@systemProperty java.security.manager} system property
345+
* set to the special token "{@code allow}", then a security manager can
346+
* be set dynamically. If the Java virtual machine is started with the
347+
* system property {@systemProperty java.security.manager} not set or set
348+
* to "{@code disallow}" then a security manager cannot be set
349+
* dynamically (the {@code setSecurityManager} method will throw an
350+
* {@code UnsupportedOperationException}).
345351
*
346352
* @param sm the security manager or {@code null}
347353
* @throws SecurityException
@@ -353,7 +359,14 @@ private static void checkIO() {
353359
* @see #getSecurityManager
354360
* @see SecurityManager#checkPermission
355361
* @see java.lang.RuntimePermission
362+
* @deprecated This method is only useful in conjunction with
363+
* {@linkplain SecurityManager the Security Manager}, which is
364+
* deprecated and subject to removal in a future release.
365+
* Consequently, this method is also deprecated and subject to
366+
* removal. There is no replacement for the Security Manager or this
367+
* method.
356368
*/
369+
@Deprecated(since="17", forRemoval=true)
357370
public static void setSecurityManager(SecurityManager sm) {
358371
if (allowSecurityManager()) {
359372
if (security == null) {
@@ -419,7 +432,14 @@ public Object run() {
419432
* current application, then that security manager is returned;
420433
* otherwise, {@code null} is returned.
421434
* @see #setSecurityManager
435+
* @deprecated This method is only useful in conjunction with
436+
* {@linkplain SecurityManager the Security Manager}, which is
437+
* deprecated and subject to removal in a future release.
438+
* Consequently, this method is also deprecated and subject to
439+
* removal. There is no replacement for the Security Manager or this
440+
* method.
422441
*/
442+
@Deprecated(since="17", forRemoval=true)
423443
public static SecurityManager getSecurityManager() {
424444
if (allowSecurityManager()) {
425445
return security;
@@ -2148,7 +2168,12 @@ private static void initPhase3() {
21482168
allowSecurityManager = MAYBE;
21492169
}
21502170
} else {
2151-
allowSecurityManager = MAYBE;
2171+
allowSecurityManager = NEVER;
2172+
}
2173+
2174+
if (allowSecurityManager != NEVER) {
2175+
System.err.println("WARNING: The Security Manager is deprecated" +
2176+
" and will be removed in a future release.");
21522177
}
21532178

21542179
// initializing the system class loader

src/java.base/share/classes/java/lang/Thread.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,14 @@ public final boolean isDaemon() {
14241424
* @throws SecurityException if the current thread is not allowed to
14251425
* access this thread.
14261426
* @see SecurityManager#checkAccess(Thread)
1427-
*/
1427+
* @deprecated This method is only useful in conjunction with
1428+
* {@linkplain SecurityManager the Security Manager}, which is
1429+
* deprecated and subject to removal in a future release.
1430+
* Consequently, this method is also deprecated and subject to
1431+
* removal. There is no replacement for the Security Manager or this
1432+
* method.
1433+
*/
1434+
@Deprecated(since="17", forRemoval=true)
14281435
public final void checkAccess() {
14291436
SecurityManager security = System.getSecurityManager();
14301437
if (security != null) {

src/java.base/share/classes/java/lang/ThreadGroup.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,14 @@ public final boolean parentOf(ThreadGroup g) {
320320
* access this thread group.
321321
* @see java.lang.SecurityManager#checkAccess(java.lang.ThreadGroup)
322322
* @since 1.0
323+
* @deprecated This method is only useful in conjunction with
324+
* {@linkplain SecurityManager the Security Manager}, which is
325+
* deprecated and subject to removal in a future release.
326+
* Consequently, this method is also deprecated and subject to
327+
* removal. There is no replacement for the Security Manager or this
328+
* method.
323329
*/
330+
@Deprecated(since="17", forRemoval=true)
324331
public final void checkAccess() {
325332
SecurityManager security = System.getSecurityManager();
326333
if (security != null) {

src/java.base/share/classes/java/security/AccessControlContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,14 @@
7575
*
7676
* @author Roland Schemers
7777
* @since 1.2
78+
* @deprecated This class is only useful in conjunction with
79+
* {@linkplain SecurityManager the Security Manager}, which is deprecated
80+
* and subject to removal in a future release. Consequently, this class
81+
* is also deprecated and subject to removal. There is no replacement for
82+
* the Security Manager or this class.
7883
*/
7984

85+
@Deprecated(since="17", forRemoval=true)
8086
public final class AccessControlContext {
8187

8288
private ProtectionDomain[] context;

src/java.base/share/classes/java/security/AccessControlException.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@
3939
* @author Li Gong
4040
* @author Roland Schemers
4141
* @since 1.2
42+
* @deprecated This class is only useful in conjunction with
43+
* {@linkplain SecurityManager the Security Manager}, which is deprecated
44+
* and subject to removal in a future release. Consequently, this class
45+
* is also deprecated and subject to removal. There is no replacement for
46+
* the Security Manager or this class.
4247
*/
4348

49+
@Deprecated(since="17", forRemoval=true)
4450
public class AccessControlException extends SecurityException {
4551

4652
@java.io.Serial

src/java.base/share/classes/java/security/AccessController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,14 @@
271271
* @author Li Gong
272272
* @author Roland Schemers
273273
* @since 1.2
274+
* @deprecated This class is only useful in conjunction with
275+
* {@linkplain SecurityManager the Security Manager}, which is deprecated
276+
* and subject to removal in a future release. Consequently, this class
277+
* is also deprecated and subject to removal. There is no replacement for
278+
* the Security Manager or this class.
274279
*/
275280

281+
@Deprecated(since="17", forRemoval=true)
276282
public final class AccessController {
277283

278284
/**

src/java.base/share/classes/java/security/DomainCombiner.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@
7777
* @see AccessController
7878
* @see AccessControlContext
7979
* @since 1.3
80+
* @deprecated This class is only useful in conjunction with
81+
* {@linkplain SecurityManager the Security Manager}, which is deprecated
82+
* and subject to removal in a future release. Consequently, this class
83+
* is also deprecated and subject to removal. There is no replacement for
84+
* the Security Manager or this class.
8085
*/
86+
@Deprecated(since="17", forRemoval=true)
8187
public interface DomainCombiner {
8288

8389
/**

src/java.base/share/classes/java/security/Policy.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,14 @@
8383
* @see java.security.ProtectionDomain
8484
* @see java.security.Permission
8585
* @see java.security.Security security properties
86+
* @deprecated This class is only useful in conjunction with
87+
* {@linkplain SecurityManager the Security Manager}, which is deprecated
88+
* and subject to removal in a future release. Consequently, this class
89+
* is also deprecated and subject to removal. There is no replacement for
90+
* the Security Manager or this class.
8691
*/
8792

93+
@Deprecated(since="17", forRemoval=true)
8894
public abstract class Policy {
8995

9096
/**
@@ -810,7 +816,13 @@ public void refresh() {
810816
* This represents a marker interface for Policy parameters.
811817
*
812818
* @since 1.6
819+
* @deprecated This class is only useful in conjunction with
820+
* {@linkplain SecurityManager the Security Manager}, which is
821+
* deprecated and subject to removal in a future release.
822+
* Consequently, this class is also deprecated and subject to removal.
823+
* There is no replacement for the Security Manager or this class.
813824
*/
825+
@Deprecated(since="17", forRemoval=true)
814826
public static interface Parameters { }
815827

816828
/**

0 commit comments

Comments
 (0)