Skip to content

Commit 40d23a0

Browse files
committed
8267543: Post JEP 411 refactoring: security
Reviewed-by: mullan
1 parent 4767758 commit 40d23a0

File tree

19 files changed

+80
-79
lines changed

19 files changed

+80
-79
lines changed

src/java.base/share/classes/com/sun/crypto/provider/JceKeyStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,6 @@ public void engineStore(OutputStream stream, char[] password)
683683
* @exception CertificateException if any of the certificates in the
684684
* keystore could not be loaded
685685
*/
686-
@SuppressWarnings("removal")
687686
public void engineLoad(InputStream stream, char[] password)
688687
throws IOException, NoSuchAlgorithmException, CertificateException
689688
{
@@ -838,7 +837,8 @@ public void engineLoad(InputStream stream, char[] password)
838837
ois = new ObjectInputStream(dis);
839838
final ObjectInputStream ois2 = ois;
840839
// Set a deserialization checker
841-
AccessController.doPrivileged(
840+
@SuppressWarnings("removal")
841+
var dummy = AccessController.doPrivileged(
842842
(PrivilegedAction<Void>)() -> {
843843
ois2.setObjectInputFilter(
844844
new DeserializationChecker(fullLength));

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -987,10 +987,9 @@ public static KeyStore getInstance(String type, Provider provider)
987987
* if no such property exists.
988988
* @see java.security.Security security properties
989989
*/
990-
@SuppressWarnings("removal")
991990
public static final String getDefaultType() {
992-
String kstype;
993-
kstype = AccessController.doPrivileged(new PrivilegedAction<>() {
991+
@SuppressWarnings("removal")
992+
String kstype = AccessController.doPrivileged(new PrivilegedAction<>() {
994993
public String run() {
995994
return Security.getProperty(KEYSTORE_TYPE);
996995
}
@@ -1957,7 +1956,6 @@ public ProtectionParameter getProtectionParameter(String alias)
19571956
* of either PasswordProtection or CallbackHandlerProtection; or
19581957
* if file does not exist or does not refer to a normal file
19591958
*/
1960-
@SuppressWarnings("removal")
19611959
public static Builder newInstance(String type, Provider provider,
19621960
File file, ProtectionParameter protection) {
19631961
if ((type == null) || (file == null) || (protection == null)) {
@@ -1974,8 +1972,9 @@ public static Builder newInstance(String type, Provider provider,
19741972
("File does not exist or it does not refer " +
19751973
"to a normal file: " + file);
19761974
}
1977-
return new FileBuilder(type, provider, file, protection,
1978-
AccessController.getContext());
1975+
@SuppressWarnings("removal")
1976+
var acc = AccessController.getContext();
1977+
return new FileBuilder(type, provider, file, protection, acc);
19791978
}
19801979

19811980
/**

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
* @since 1.1
5252
*/
5353

54-
@SuppressWarnings("removal")
5554
public final class Security {
5655

5756
/* Are we debugging? -- for developers */
@@ -72,7 +71,8 @@ private static class ProviderProperty {
7271
// things in initialize that might require privs.
7372
// (the FileInputStream call and the File.exists call,
7473
// the securityPropFile call, etc)
75-
AccessController.doPrivileged(new PrivilegedAction<>() {
74+
@SuppressWarnings("removal")
75+
var dummy = AccessController.doPrivileged(new PrivilegedAction<>() {
7676
public Void run() {
7777
initialize();
7878
return null;
@@ -761,6 +761,7 @@ static Object[] getImpl(String algorithm, String type, Provider provider,
761761
* @see java.security.SecurityPermission
762762
*/
763763
public static String getProperty(String key) {
764+
@SuppressWarnings("removal")
764765
SecurityManager sm = System.getSecurityManager();
765766
if (sm != null) {
766767
sm.checkPermission(new SecurityPermission("getProperty."+
@@ -828,13 +829,15 @@ private static void invalidateSMCache(String key) {
828829
}
829830

830831
private static void check(String directive) {
832+
@SuppressWarnings("removal")
831833
SecurityManager security = System.getSecurityManager();
832834
if (security != null) {
833835
security.checkSecurityAccess(directive);
834836
}
835837
}
836838

837839
private static void checkInsertProvider(String name) {
840+
@SuppressWarnings("removal")
838841
SecurityManager security = System.getSecurityManager();
839842
if (security != null) {
840843
try {

src/java.base/share/classes/javax/crypto/ProviderVerifier.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ final class ProviderVerifier {
8383
* In OpenJDK, we just need to examine the "cryptoperms" file to see
8484
* if any permissions were bundled together with this jar file.
8585
*/
86-
@SuppressWarnings("removal")
8786
void verify() throws IOException {
8887

8988
// Short-circuit. If we weren't asked to save any, we're done.
@@ -102,7 +101,8 @@ void verify() throws IOException {
102101

103102
// Get a link to the Jarfile to search.
104103
try {
105-
jf = AccessController.doPrivileged(
104+
@SuppressWarnings("removal")
105+
var tmp = AccessController.doPrivileged(
106106
new PrivilegedExceptionAction<JarFile>() {
107107
public JarFile run() throws Exception {
108108
JarURLConnection conn =
@@ -113,6 +113,7 @@ public JarFile run() throws Exception {
113113
return conn.getJarFile();
114114
}
115115
});
116+
jf = tmp;
116117
} catch (java.security.PrivilegedActionException pae) {
117118
throw new SecurityException("Cannot load " + url.toString(),
118119
pae.getCause());

src/java.base/share/classes/sun/security/jca/ProviderConfig.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public String toString() {
160160
/**
161161
* Get the provider object. Loads the provider if it is not already loaded.
162162
*/
163-
@SuppressWarnings({"removal","deprecation"})
163+
@SuppressWarnings("deprecation")
164164
Provider getProvider() {
165165
// volatile variable load
166166
Provider p = provider;
@@ -188,7 +188,8 @@ Provider getProvider() {
188188
p = new sun.security.ssl.SunJSSE();
189189
} else if (provName.equals("Apple") || provName.equals("apple.security.AppleProvider")) {
190190
// need to use reflection since this class only exists on MacOsx
191-
p = AccessController.doPrivileged(new PrivilegedAction<Provider>() {
191+
@SuppressWarnings("removal")
192+
var tmp = AccessController.doPrivileged(new PrivilegedAction<Provider>() {
192193
public Provider run() {
193194
try {
194195
Class<?> c = Class.forName("apple.security.AppleProvider");
@@ -208,6 +209,7 @@ public Provider run() {
208209
}
209210
}
210211
});
212+
p = tmp;
211213
} else {
212214
if (isLoading) {
213215
// because this method is synchronized, this can only

src/java.base/share/classes/sun/security/provider/MD4.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
*
4444
* @author Andreas Sterbenz
4545
*/
46-
@SuppressWarnings("removal")
4746
public final class MD4 extends DigestBase {
4847

4948
// state of this object
@@ -71,7 +70,8 @@ public final class MD4 extends DigestBase {
7170
@java.io.Serial
7271
private static final long serialVersionUID = -8850464997518327965L;
7372
};
74-
AccessController.doPrivileged(new PrivilegedAction<Void>() {
73+
@SuppressWarnings("removal")
74+
var dummy = AccessController.doPrivileged(new PrivilegedAction<Void>() {
7575
public Void run() {
7676
md4Provider.put("MessageDigest.MD4", "sun.security.provider.MD4");
7777
return null;

src/java.base/share/classes/sun/security/provider/SunEntries.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
* - JavaLoginConfig is the default file-based LoginModule Configuration type.
8282
*/
8383

84-
@SuppressWarnings("removal")
8584
public final class SunEntries {
8685

8786
// the default algo used by SecureRandom class for new SecureRandom() calls
@@ -325,10 +324,8 @@ private void addWithAlias(Provider p, String type, String algo, String cn,
325324
static final String URL_DEV_RANDOM = "file:/dev/random";
326325
static final String URL_DEV_URANDOM = "file:/dev/urandom";
327326

328-
private static final String seedSource;
329-
330-
static {
331-
seedSource = AccessController.doPrivileged(
327+
@SuppressWarnings("removal")
328+
private static final String seedSource = AccessController.doPrivileged(
332329
new PrivilegedAction<String>() {
333330

334331
@Override
@@ -345,6 +342,7 @@ public String run() {
345342
}
346343
});
347344

345+
static {
348346
DEF_SECURE_RANDOM_ALGO = (NativePRNG.isAvailable() &&
349347
(seedSource.equals(URL_DEV_URANDOM) ||
350348
seedSource.equals(URL_DEV_RANDOM)) ?

src/java.base/share/classes/sun/security/ssl/SSLEngineImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,6 @@ private static class DelegatedTask implements Runnable {
11951195
this.engine = engineInstance;
11961196
}
11971197

1198-
@SuppressWarnings("removal")
11991198
@Override
12001199
public void run() {
12011200
engine.engineLock.lock();
@@ -1206,7 +1205,8 @@ public void run() {
12061205
}
12071206

12081207
try {
1209-
AccessController.doPrivileged(
1208+
@SuppressWarnings("removal")
1209+
var dummy = AccessController.doPrivileged(
12101210
new DelegatedAction(hc), engine.conContext.acc);
12111211
} catch (PrivilegedActionException pae) {
12121212
// Get the handshake context again in case the

src/java.base/share/classes/sun/security/util/AnchorCertificates.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
* The purpose of this class is to determine the trust anchor certificates is in
4444
* the cacerts file. This is used for PKIX CertPath checking.
4545
*/
46-
@SuppressWarnings("removal")
4746
public class AnchorCertificates {
4847

4948
private static final Debug debug = Debug.getInstance("certpath");
@@ -52,7 +51,8 @@ public class AnchorCertificates {
5251
private static Set<X500Principal> certIssuers = Collections.emptySet();
5352

5453
static {
55-
AccessController.doPrivileged(new PrivilegedAction<>() {
54+
@SuppressWarnings("removal")
55+
var dummy = AccessController.doPrivileged(new PrivilegedAction<>() {
5656
@Override
5757
public Void run() {
5858
File f = new File(FilePaths.cacerts());

src/java.base/share/classes/sun/security/util/KeyStoreDelegator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ public class KeyStoreDelegator extends KeyStoreSpi {
5555
private KeyStoreSpi keystore; // the delegate
5656
private boolean compatModeEnabled = true;
5757

58-
@SuppressWarnings("removal")
5958
public KeyStoreDelegator(
6059
String primaryType,
6160
Class<? extends KeyStoreSpi> primaryKeyStore,
6261
String secondaryType,
6362
Class<? extends KeyStoreSpi> secondaryKeyStore) {
6463

6564
// Check whether compatibility mode has been disabled
66-
compatModeEnabled = "true".equalsIgnoreCase(
67-
AccessController.doPrivileged((PrivilegedAction<String>) () ->
68-
Security.getProperty(KEYSTORE_TYPE_COMPAT)));
65+
@SuppressWarnings("removal")
66+
var prop = AccessController.doPrivileged((PrivilegedAction<String>) () ->
67+
Security.getProperty(KEYSTORE_TYPE_COMPAT));
68+
compatModeEnabled = "true".equalsIgnoreCase(prop);
6969

7070
if (compatModeEnabled) {
7171
this.primaryType = primaryType;

src/java.base/share/classes/sun/security/util/UntrustedCertificates.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
* <b>Attention</b>: This check is NOT meant to replace the standard PKI-defined
4343
* validation check, neither is it used as an alternative to CRL.
4444
*/
45-
@SuppressWarnings("removal")
4645
public final class UntrustedCertificates {
4746

4847
private static final Debug debug = Debug.getInstance("certpath");
@@ -52,7 +51,8 @@ public final class UntrustedCertificates {
5251
private static final String algorithm;
5352

5453
static {
55-
AccessController.doPrivileged(new PrivilegedAction<Void>() {
54+
@SuppressWarnings("removal")
55+
var dummy = AccessController.doPrivileged(new PrivilegedAction<Void>() {
5656
@Override
5757
public Void run() {
5858
File f = new File(StaticProperty.javaHome(),

src/java.management/share/classes/com/sun/jmx/remote/security/JMXPluggableAuthenticator.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public final class JMXPluggableAuthenticator implements JMXAuthenticator {
8585
* @exception SecurityException if the authentication mechanism cannot be
8686
* initialized.
8787
*/
88-
@SuppressWarnings("removal")
8988
public JMXPluggableAuthenticator(Map<?, ?> env) {
9089

9190
String loginConfigName = null;
@@ -107,6 +106,7 @@ public JMXPluggableAuthenticator(Map<?, ?> env) {
107106

108107
} else {
109108
// use the default JAAS login configuration (file-based)
109+
@SuppressWarnings("removal")
110110
SecurityManager sm = System.getSecurityManager();
111111
if (sm != null) {
112112
sm.checkPermission(
@@ -117,7 +117,8 @@ public JMXPluggableAuthenticator(Map<?, ?> env) {
117117
final String pf = passwordFile;
118118
final String hashPass = hashPasswords;
119119
try {
120-
loginContext = AccessController.doPrivileged(
120+
@SuppressWarnings("removal")
121+
var tmp = AccessController.doPrivileged(
121122
new PrivilegedExceptionAction<LoginContext>() {
122123
public LoginContext run() throws LoginException {
123124
return new LoginContext(
@@ -127,6 +128,7 @@ public LoginContext run() throws LoginException {
127128
new FileLoginConfig(pf, hashPass));
128129
}
129130
});
131+
loginContext = tmp;
130132
} catch (PrivilegedActionException pae) {
131133
throw (LoginException) pae.getException();
132134
}
@@ -156,7 +158,6 @@ public LoginContext run() throws LoginException {
156158
* @exception SecurityException if the server cannot authenticate the user
157159
* with the provided credentials.
158160
*/
159-
@SuppressWarnings("removal")
160161
public Subject authenticate(Object credentials) {
161162
// Verify that credentials is of type String[].
162163
//
@@ -193,7 +194,8 @@ public Subject authenticate(Object credentials) {
193194
try {
194195
loginContext.login();
195196
final Subject subject = loginContext.getSubject();
196-
AccessController.doPrivileged(new PrivilegedAction<Void>() {
197+
@SuppressWarnings("removal")
198+
var dummy = AccessController.doPrivileged(new PrivilegedAction<Void>() {
197199
public Void run() {
198200
subject.setReadOnly();
199201
return null;

src/java.security.jgss/share/classes/sun/security/jgss/krb5/Krb5Context.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ public final boolean isProtReady() {
592592
* to send the token to its peer for processing.
593593
* @exception GSSException
594594
*/
595-
@SuppressWarnings("removal")
596595
public final byte[] initSecContext(InputStream is, int mechTokenSize)
597596
throws GSSException {
598597

@@ -642,14 +641,16 @@ public final byte[] initSecContext(InputStream is, int mechTokenSize)
642641
* for this service in the Subject and reuse it
643642
*/
644643

644+
@SuppressWarnings("removal")
645645
final AccessControlContext acc =
646646
AccessController.getContext();
647647

648648
if (GSSUtil.useSubjectCredsOnly(caller)) {
649649
KerberosTicket kerbTicket = null;
650650
try {
651651
// get service ticket from caller's subject
652-
kerbTicket = AccessController.doPrivileged(
652+
@SuppressWarnings("removal")
653+
var tmp = AccessController.doPrivileged(
653654
new PrivilegedExceptionAction<KerberosTicket>() {
654655
public KerberosTicket run() throws Exception {
655656
// XXX to be cleaned
@@ -667,6 +668,7 @@ public KerberosTicket run() throws Exception {
667668
peerName.getKrb5PrincipalName().getName(),
668669
acc);
669670
}});
671+
kerbTicket = tmp;
670672
} catch (PrivilegedActionException e) {
671673
if (DEBUG) {
672674
System.out.println("Attempt to obtain service"
@@ -706,6 +708,7 @@ public KerberosTicket run() throws Exception {
706708
tgt);
707709
}
708710
if (GSSUtil.useSubjectCredsOnly(caller)) {
711+
@SuppressWarnings("removal")
709712
final Subject subject =
710713
AccessController.doPrivileged(
711714
new java.security.PrivilegedAction<Subject>() {
@@ -724,7 +727,8 @@ public Subject run() {
724727
*/
725728
final KerberosTicket kt =
726729
Krb5Util.credsToTicket(serviceCreds);
727-
AccessController.doPrivileged (
730+
@SuppressWarnings("removal")
731+
var dummy = AccessController.doPrivileged (
728732
new java.security.PrivilegedAction<Void>() {
729733
public Void run() {
730734
subject.getPrivateCredentials().add(kt);

0 commit comments

Comments
 (0)