Skip to content

Commit d41e8a8

Browse files
authored
Merge pull request #932 from theresa-m/securitymanager
Remove AccessController.doPrivileged uses from closed/src
2 parents da990c3 + f946e71 commit d41e8a8

File tree

3 files changed

+18
-50
lines changed

3 files changed

+18
-50
lines changed

closed/src/java.base/share/classes/java/io/ClassByNameCache.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ===========================================================================
3-
* (c) Copyright IBM Corp. 2017, 2022 All Rights Reserved
3+
* (c) Copyright IBM Corp. 2017, 2025 All Rights Reserved
44
* ===========================================================================
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -26,8 +26,6 @@
2626

2727
import java.lang.ref.ReferenceQueue;
2828
import java.lang.ref.WeakReference;
29-
import java.security.AccessController;
30-
import java.security.PrivilegedAction;
3129
import java.util.Objects;
3230
import java.util.concurrent.ConcurrentHashMap;
3331
/* ClassByNameCache is Primarily responsible for Caching the results of the className lookups and hence to avoid
@@ -63,8 +61,11 @@ public ClassByNameCache() {
6361
loader = loader.getParent();
6462
}
6563
setCanonicalSystemLoaderRef(null);
66-
AccessController.doPrivileged(
67-
new CreateReaperAction(this, staleLoaderRefs)).start();
64+
65+
Reaper reaper = new Reaper(this, staleLoaderRefs);
66+
com.ibm.oti.vm.VM.getVMLangAccess()
67+
.createThread(reaper, "ClassByNameCache Reaper", true, false, true, null)
68+
.start();
6869
}
6970
/*
7071
* sets Canonical Loader reference for the loader
@@ -197,22 +198,6 @@ Class<?> get() throws ClassNotFoundException {
197198
}
198199
}
199200

200-
private static final class CreateReaperAction
201-
implements PrivilegedAction<Thread> {
202-
private final ClassByNameCache cache;
203-
private final ReferenceQueue<Object> queue;
204-
205-
CreateReaperAction(ClassByNameCache cache, ReferenceQueue<Object> queue) {
206-
this.cache = cache;
207-
this.queue = queue;
208-
}
209-
210-
public Thread run() {
211-
Reaper reaper = new Reaper(cache, queue);
212-
return com.ibm.oti.vm.VM.getVMLangAccess().createThread(reaper, "ClassByNameCache Reaper", true, false, true, null);
213-
}
214-
}
215-
216201
private static final class Reaper implements Runnable {
217202
private final WeakReference<ClassByNameCache> cacheRef;
218203
private final ReferenceQueue<Object> queue;

closed/src/java.base/share/classes/jdk/crypto/jniprovider/NativeCrypto.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ private static long loadCryptoLibraries() {
117117
return osslVersion;
118118
}
119119

120-
@SuppressWarnings("removal")
121120
private NativeCrypto() {
122-
ossl_ver = AccessController.doPrivileged((PrivilegedAction<Long>) () -> loadCryptoLibraries()).longValue();
121+
ossl_ver = loadCryptoLibraries();
123122
if (ossl_ver != -1) {
124123
isOpenSSLFIPS = isOpenSSLFIPS();
125124
} else {

closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ===========================================================================
3-
* (c) Copyright IBM Corp. 2022, 2024 All Rights Reserved
3+
* (c) Copyright IBM Corp. 2022, 2025 All Rights Reserved
44
* ===========================================================================
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -24,10 +24,8 @@
2424
package openj9.internal.security;
2525

2626
import java.nio.charset.StandardCharsets;
27-
import java.security.AccessController;
2827
import java.security.MessageDigest;
2928
import java.security.NoSuchAlgorithmException;
30-
import java.security.PrivilegedAction;
3129
import java.security.Provider;
3230
import java.security.Provider.Service;
3331
import java.time.LocalDate;
@@ -93,30 +91,20 @@ public final class RestrictedSecurity {
9391
supportedPlatformsOpenJCEPlus.put("Arch", List.of("amd64", "ppc64", "s390x"));
9492
supportedPlatformsOpenJCEPlus.put("OS", List.of("Linux", "AIX", "Windows"));
9593

96-
@SuppressWarnings("removal")
97-
String[] props = AccessController.doPrivileged(
98-
new PrivilegedAction<>() {
99-
@Override
100-
public String[] run() {
101-
return new String[] { System.getProperty("semeru.fips"),
102-
System.getProperty("semeru.customprofile"),
103-
System.getProperty("os.name"),
104-
System.getProperty("os.arch"),
105-
System.getProperty("semeru.fips.allowsetproperties") };
106-
}
107-
});
94+
String osName = System.getProperty("os.name");
95+
String osArch = System.getProperty("os.arch");
10896

10997
boolean isOsSupported, isArchSupported;
11098
// Check whether the NSS FIPS solution is supported.
11199
isOsSupported = false;
112100
for (String os: supportedPlatformsNSS.get("OS")) {
113-
if (props[2].contains(os)) {
101+
if (osName.contains(os)) {
114102
isOsSupported = true;
115103
}
116104
}
117105
isArchSupported = false;
118106
for (String arch: supportedPlatformsNSS.get("Arch")) {
119-
if (props[3].contains(arch)) {
107+
if (osArch.contains(arch)) {
120108
isArchSupported = true;
121109
}
122110
}
@@ -125,13 +113,13 @@ public String[] run() {
125113
// Check whether the OpenJCEPlus FIPS solution is supported.
126114
isOsSupported = false;
127115
for (String os: supportedPlatformsOpenJCEPlus.get("OS")) {
128-
if (props[2].contains(os)) {
116+
if (osName.contains(os)) {
129117
isOsSupported = true;
130118
}
131119
}
132120
isArchSupported = false;
133121
for (String arch: supportedPlatformsOpenJCEPlus.get("Arch")) {
134-
if (props[3].contains(arch)) {
122+
if (osArch.contains(arch)) {
135123
isArchSupported = true;
136124
}
137125
}
@@ -140,8 +128,8 @@ public String[] run() {
140128
// Check the default solution to see if FIPS is supported.
141129
isFIPSSupported = isNSSSupported;
142130

143-
userEnabledFIPS = Boolean.parseBoolean(props[0]);
144-
allowSetProperties = Boolean.parseBoolean(props[4]);
131+
userEnabledFIPS = Boolean.getBoolean("semeru.fips");
132+
allowSetProperties = Boolean.getBoolean("semeru.fips.allowsetproperties");
145133

146134
if (userEnabledFIPS) {
147135
if (isFIPSSupported) {
@@ -151,12 +139,8 @@ public String[] run() {
151139
}
152140

153141
// If user has specified a profile, use that
154-
if (props[1] != null) {
155-
selectedProfile = props[1];
156-
userSetProfile = true;
157-
} else {
158-
userSetProfile = false;
159-
}
142+
selectedProfile = System.getProperty("semeru.customprofile");
143+
userSetProfile = selectedProfile != null;
160144

161145
// Check if FIPS is supported on this platform without explicitly setting a profile.
162146
if (userEnabledFIPS && !isFIPSSupported && !userSetProfile) {

0 commit comments

Comments
 (0)