Skip to content

Commit 4363ddc

Browse files
authored
Reduce calls to deprecated Java Platform methods (#792)
1 parent f8d6f87 commit 4363ddc

File tree

4 files changed

+22
-34
lines changed

4 files changed

+22
-34
lines changed

src/main/java/hudson/remoting/Engine.java

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,11 @@
4646
import java.nio.ByteBuffer;
4747
import java.nio.charset.StandardCharsets;
4848
import java.nio.file.Path;
49-
import java.security.AccessController;
5049
import java.security.KeyManagementException;
5150
import java.security.KeyStore;
5251
import java.security.KeyStoreException;
5352
import java.security.NoSuchAlgorithmException;
5453
import java.security.NoSuchProviderException;
55-
import java.security.PrivilegedActionException;
56-
import java.security.PrivilegedExceptionAction;
5754
import java.security.SecureRandom;
5855
import java.security.UnrecoverableKeyException;
5956
import java.security.cert.CertificateException;
@@ -1165,20 +1162,14 @@ public static Engine current() {
11651162

11661163
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "File path is loaded from system properties.")
11671164
static KeyStore getCacertsKeyStore()
1168-
throws PrivilegedActionException, KeyStoreException, NoSuchProviderException, CertificateException,
1169-
NoSuchAlgorithmException, IOException {
1170-
Map<String, String> properties =
1171-
AccessController.doPrivileged((PrivilegedExceptionAction<Map<String, String>>) () -> {
1172-
Map<String, String> result = new HashMap<>();
1173-
result.put("trustStore", System.getProperty("javax.net.ssl.trustStore"));
1174-
result.put("javaHome", System.getProperty("java.home"));
1175-
result.put(
1176-
"trustStoreType",
1177-
System.getProperty("javax.net.ssl.trustStoreType", KeyStore.getDefaultType()));
1178-
result.put("trustStoreProvider", System.getProperty("javax.net.ssl.trustStoreProvider", ""));
1179-
result.put("trustStorePasswd", System.getProperty("javax.net.ssl.trustStorePassword", ""));
1180-
return result;
1181-
});
1165+
throws KeyStoreException, NoSuchProviderException, CertificateException, NoSuchAlgorithmException,
1166+
IOException {
1167+
Map<String, String> properties = new HashMap<>();
1168+
properties.put("trustStore", System.getProperty("javax.net.ssl.trustStore"));
1169+
properties.put("javaHome", System.getProperty("java.home"));
1170+
properties.put("trustStoreType", System.getProperty("javax.net.ssl.trustStoreType", KeyStore.getDefaultType()));
1171+
properties.put("trustStoreProvider", System.getProperty("javax.net.ssl.trustStoreProvider", ""));
1172+
properties.put("trustStorePasswd", System.getProperty("javax.net.ssl.trustStorePassword", ""));
11821173
KeyStore keystore = null;
11831174

11841175
FileInputStream trustStoreStream = null;
@@ -1243,20 +1234,18 @@ static KeyStore getCacertsKeyStore()
12431234
}
12441235

12451236
@CheckForNull
1246-
private static FileInputStream getFileInputStream(final File file) throws PrivilegedActionException {
1247-
return AccessController.doPrivileged((PrivilegedExceptionAction<FileInputStream>) () -> {
1248-
try {
1249-
return file.exists() ? new FileInputStream(file) : null;
1250-
} catch (FileNotFoundException e) {
1251-
return null;
1252-
}
1253-
});
1237+
private static FileInputStream getFileInputStream(final File file) {
1238+
try {
1239+
return file.exists() ? new FileInputStream(file) : null;
1240+
} catch (FileNotFoundException e) {
1241+
return null;
1242+
}
12541243
}
12551244

12561245
@CheckForNull
12571246
private static SSLContext getSSLContext(List<X509Certificate> x509Certificates, boolean noCertificateCheck)
1258-
throws PrivilegedActionException, KeyStoreException, NoSuchProviderException, CertificateException,
1259-
NoSuchAlgorithmException, IOException, KeyManagementException {
1247+
throws KeyStoreException, NoSuchProviderException, CertificateException, NoSuchAlgorithmException,
1248+
IOException, KeyManagementException {
12601249
SSLContext sslContext = null;
12611250
if (noCertificateCheck) {
12621251
sslContext = SSLContext.getInstance("TLS");
@@ -1285,8 +1274,8 @@ private static SSLContext getSSLContext(List<X509Certificate> x509Certificates,
12851274
@CheckForNull
12861275
@Restricted(NoExternalUse.class)
12871276
static SSLSocketFactory getSSLSocketFactory(List<X509Certificate> x509Certificates, boolean noCertificateCheck)
1288-
throws PrivilegedActionException, KeyStoreException, NoSuchProviderException, CertificateException,
1289-
NoSuchAlgorithmException, IOException, KeyManagementException {
1277+
throws KeyStoreException, NoSuchProviderException, CertificateException, NoSuchAlgorithmException,
1278+
IOException, KeyManagementException {
12901279
SSLContext sslContext = getSSLContext(x509Certificates, noCertificateCheck);
12911280
return sslContext != null ? sslContext.getSocketFactory() : null;
12921281
}

src/main/java/hudson/remoting/Launcher.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.nio.charset.StandardCharsets;
4747
import java.nio.file.Path;
4848
import java.security.GeneralSecurityException;
49-
import java.security.PrivilegedActionException;
5049
import java.security.SecureRandom;
5150
import java.security.cert.CertificateException;
5251
import java.security.cert.CertificateFactory;
@@ -529,7 +528,7 @@ private synchronized void initialize() throws IOException {
529528
createX509Certificates();
530529
try {
531530
sslSocketFactory = Engine.getSSLSocketFactory(x509Certificates, noCertificateCheck);
532-
} catch (GeneralSecurityException | PrivilegedActionException e) {
531+
} catch (GeneralSecurityException e) {
533532
throw new RuntimeException(e);
534533
}
535534
if (noCertificateCheck) {

src/main/java/hudson/remoting/RemoteClassLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ private void definePackage(String name) {
490490
}
491491

492492
String packageName = name.substring(0, idx);
493-
if (getPackage(packageName) != null) { // already defined
493+
if (getDefinedPackage(packageName) != null) { // already defined
494494
return;
495495
}
496496

src/main/java/org/jenkinsci/remoting/protocol/cert/PublicKeyMatchingX509ExtendedTrustManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private void checkPublicKey(boolean client, X509Certificate[] chain) throws Cert
205205
throw new CertificateException(String.format(
206206
"Public key of the first certificate in chain (subject: '%s') "
207207
+ "(algorithm: '%s'; format: '%s') does not support binary encoding",
208-
chain[0].getSubjectDN(), chainKey.getAlgorithm(), chainKey.getFormat()));
208+
chain[0].getSubjectX500Principal(), chainKey.getAlgorithm(), chainKey.getFormat()));
209209
}
210210
synchronized (publicKeys) {
211211
if (publicKeys.isEmpty() ? (client ? !strictClient : !strictServer) : isTrusted(chainKey)) {
@@ -214,7 +214,7 @@ private void checkPublicKey(boolean client, X509Certificate[] chain) throws Cert
214214
}
215215
throw new CertificateException(String.format(
216216
"Public key of the first certificate in chain (subject: %s) " + "is not in the list of trusted keys",
217-
chain[0].getSubjectDN()));
217+
chain[0].getSubjectX500Principal()));
218218
}
219219

220220
/**

0 commit comments

Comments
 (0)