Skip to content

Commit 50d9edb

Browse files
committed
chore: use SecurityManager only for JDKs up to 24
1 parent 6741bc8 commit 50d9edb

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

modules/kernel/src/org/apache/axis2/java/security/AccessController.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858

5959
public class AccessController {
60+
private static final boolean SUPPORTS_SECURITY_MANAGER = Runtime.version().feature() < 24;
6061

6162
/**
6263
* Performs the specified <code>PrivilegedAction</code> with privileges
@@ -71,8 +72,7 @@ public class AccessController {
7172
* @see #doPrivileged(PrivilegedExceptionAction)
7273
*/
7374
public static <T> T doPrivileged(PrivilegedAction<T> action) {
74-
SecurityManager sm = System.getSecurityManager();
75-
if (sm == null) {
75+
if (!SUPPORTS_SECURITY_MANAGER || System.getSecurityManager() == null) {
7676
return (action.run());
7777
} else {
7878
return java.security.AccessController.doPrivileged(action);
@@ -101,8 +101,7 @@ public static <T> T doPrivileged(PrivilegedAction<T> action) {
101101
* @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext)
102102
*/
103103
public static <T> T doPrivileged(PrivilegedAction<T> action, AccessControlContext context) {
104-
SecurityManager sm = System.getSecurityManager();
105-
if (sm == null) {
104+
if (!SUPPORTS_SECURITY_MANAGER || System.getSecurityManager() == null) {
106105
return action.run();
107106
} else {
108107
return java.security.AccessController.doPrivileged(action, context);
@@ -126,8 +125,7 @@ public static <T> T doPrivileged(PrivilegedAction<T> action, AccessControlContex
126125
*/
127126
public static <T> T doPrivileged(PrivilegedExceptionAction<T> action)
128127
throws PrivilegedActionException {
129-
SecurityManager sm = System.getSecurityManager();
130-
if (sm == null) {
128+
if (!SUPPORTS_SECURITY_MANAGER || System.getSecurityManager() == null) {
131129
try {
132130
return action.run();
133131
} catch (java.lang.RuntimeException e) {
@@ -167,8 +165,7 @@ public static <T> T doPrivileged(PrivilegedExceptionAction<T> action,
167165
AccessControlContext context)
168166
throws PrivilegedActionException {
169167

170-
SecurityManager sm = System.getSecurityManager();
171-
if (sm == null) {
168+
if (!SUPPORTS_SECURITY_MANAGER || System.getSecurityManager() == null) {
172169
try {
173170
return action.run();
174171
} catch (java.lang.RuntimeException e) {
@@ -206,7 +203,9 @@ public static AccessControlContext getContext() {
206203
* is not permitted, based on the current security policy.
207204
*/
208205
public static void checkPermission(Permission perm) throws AccessControlException {
209-
java.security.AccessController.checkPermission(perm);
206+
if (SUPPORTS_SECURITY_MANAGER) {
207+
java.security.AccessController.checkPermission(perm);
208+
}
210209
}
211210

212211
/**

modules/kernel/test/org/apache/axis2/java/security/driver/Java2SecTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import java.util.Calendar;
3939
import java.util.TimeZone;
4040

41+
import static org.junit.Assume.assumeTrue;
42+
4143
/**
4244
* Java2SecTest demostrates the usages of AccessController class and Policy file(s) while Security Manager is enabled:
4345
* 1. testNoPrivilegePassed shows the usage of no AccessController but it still work fine
@@ -68,6 +70,12 @@ public Java2SecTest() {
6870
System.out.println("Current time => " + sdf.format(cal.getTime()) + "\n");
6971
}
7072

73+
@Override
74+
public void setUp() throws Exception {
75+
// Security Manager was removed after that
76+
assumeTrue(Runtime.version().feature() < 24);
77+
}
78+
7179
// Constructor
7280
public Java2SecTest(String arg) {
7381
super(arg);

0 commit comments

Comments
 (0)