Skip to content

Commit 466d831

Browse files
authored
[8.x] Make NotEntitledException inherit from AccessControlException for compatibility purposes (#124321) (#124418)
* Make NotEntitledException inherit from AccessControlException for compatibility purposes (#124321) Even if the contract for JDK methods using the SecurityManager states that the exception throw is of type SecurityException, many libraries (including our own, apparently!) violates that and use the type actually thrown by SecurityManager, AccessControlException. A prime example is the GCS/CSP libraries. In order to maintain compatibility for them, we need to inherit from the more specific AccessControlException; this is less desirable, as AccessControlException is marked as deprecated for removal alongside the other SecurityManager classes, but we discussed and found this is the best short term solution. More work will be needed -- again, this is a short term solution. Replaces #123984 * cleanup exceptions
1 parent e90d6d2 commit 466d831

File tree

8 files changed

+11
-38
lines changed

8 files changed

+11
-38
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/api/NotEntitledException.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99

1010
package org.elasticsearch.entitlement.runtime.api;
1111

12-
public class NotEntitledException extends SecurityException {
12+
import java.security.AccessControlException;
13+
14+
public class NotEntitledException extends AccessControlException {
1315
public NotEntitledException(String message) {
1416
super(message);
1517
}
16-
17-
public NotEntitledException(String message, Throwable cause) {
18-
super(message, cause);
19-
}
2018
}

libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/PemKeyConfig.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
package org.elasticsearch.common.ssl;
1111

1212
import org.elasticsearch.core.Tuple;
13-
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
1413

1514
import java.io.IOException;
1615
import java.nio.file.Path;
17-
import java.security.AccessControlException;
1816
import java.security.GeneralSecurityException;
1917
import java.security.KeyStore;
2018
import java.security.PrivateKey;
@@ -126,10 +124,8 @@ private PrivateKey getPrivateKey(Path path) {
126124
throw new SslConfigException("could not load ssl private key file [" + path + "]");
127125
}
128126
return privateKey;
129-
} catch (AccessControlException e) {
127+
} catch (SecurityException e) {
130128
throw SslFileUtil.accessControlFailure(KEY_FILE_TYPE, List.of(path), e, configBasePath);
131-
} catch (NotEntitledException e) {
132-
throw SslFileUtil.notEntitledFailure(KEY_FILE_TYPE, List.of(path), e, configBasePath);
133129
} catch (IOException e) {
134130
throw SslFileUtil.ioException(KEY_FILE_TYPE, List.of(path), e);
135131
} catch (GeneralSecurityException e) {
@@ -140,7 +136,7 @@ private PrivateKey getPrivateKey(Path path) {
140136
private List<Certificate> getCertificates(Path path) {
141137
try {
142138
return PemUtils.readCertificates(Collections.singleton(path));
143-
} catch (AccessControlException e) {
139+
} catch (SecurityException e) {
144140
throw SslFileUtil.accessControlFailure(CERT_FILE_TYPE, List.of(path), e, configBasePath);
145141
} catch (IOException e) {
146142
throw SslFileUtil.ioException(CERT_FILE_TYPE, List.of(path), e);

libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/PemTrustConfig.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99

1010
package org.elasticsearch.common.ssl;
1111

12-
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
13-
1412
import java.io.IOException;
1513
import java.io.InputStream;
1614
import java.nio.file.Path;
17-
import java.security.AccessControlException;
1815
import java.security.GeneralSecurityException;
1916
import java.security.KeyStore;
2017
import java.security.cert.Certificate;
@@ -99,10 +96,8 @@ private Path resolveFile(String other) {
9996
private List<Certificate> readCertificates(List<Path> paths) {
10097
try {
10198
return PemUtils.readCertificates(paths);
102-
} catch (AccessControlException e) {
99+
} catch (SecurityException e) {
103100
throw SslFileUtil.accessControlFailure(CA_FILE_TYPE, paths, e, basePath);
104-
} catch (NotEntitledException e) {
105-
throw SslFileUtil.notEntitledFailure(CA_FILE_TYPE, paths, e, basePath);
106101
} catch (IOException e) {
107102
throw SslFileUtil.ioException(CA_FILE_TYPE, paths, e);
108103
} catch (GeneralSecurityException e) {

libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/PemUtils.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.elasticsearch.common.ssl;
1111

1212
import org.elasticsearch.core.CharArrays;
13-
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
1413

1514
import java.io.BufferedReader;
1615
import java.io.IOException;
@@ -19,7 +18,6 @@
1918
import java.nio.charset.StandardCharsets;
2019
import java.nio.file.Files;
2120
import java.nio.file.Path;
22-
import java.security.AccessControlException;
2321
import java.security.AlgorithmParameters;
2422
import java.security.GeneralSecurityException;
2523
import java.security.KeyFactory;
@@ -111,10 +109,8 @@ public static PrivateKey readPrivateKey(Path path, Supplier<char[]> passwordSupp
111109
throw new SslConfigException("could not load ssl private key file [" + path + "]");
112110
}
113111
return privateKey;
114-
} catch (AccessControlException e) {
112+
} catch (SecurityException e) {
115113
throw SslFileUtil.accessControlFailure("PEM private key", List.of(path), e, null);
116-
} catch (NotEntitledException e) {
117-
throw SslFileUtil.notEntitledFailure("PEM private key", List.of(path), e, null);
118114
} catch (IOException e) {
119115
throw SslFileUtil.ioException("PEM private key", List.of(path), e);
120116
} catch (GeneralSecurityException e) {

libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/SslFileUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.nio.file.AccessDeniedException;
1717
import java.nio.file.NoSuchFileException;
1818
import java.nio.file.Path;
19-
import java.security.AccessControlException;
2019
import java.security.GeneralSecurityException;
2120
import java.security.UnrecoverableKeyException;
2221
import java.util.List;
@@ -84,7 +83,7 @@ static SslConfigException notEntitledFailure(String fileType, List<Path> paths,
8483
return innerAccessControlFailure(fileType, paths, cause, basePath);
8584
}
8685

87-
static SslConfigException accessControlFailure(String fileType, List<Path> paths, AccessControlException cause, Path basePath) {
86+
static SslConfigException accessControlFailure(String fileType, List<Path> paths, SecurityException cause, Path basePath) {
8887
return innerAccessControlFailure(fileType, paths, cause, basePath);
8988
}
9089

libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/StoreKeyConfig.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111

1212
import org.elasticsearch.core.Nullable;
1313
import org.elasticsearch.core.Tuple;
14-
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
1514

1615
import java.io.IOException;
1716
import java.nio.file.Path;
18-
import java.security.AccessControlException;
1917
import java.security.GeneralSecurityException;
2018
import java.security.KeyStore;
2119
import java.security.KeyStoreException;
@@ -167,10 +165,8 @@ private KeyStore processKeyStore(KeyStore keyStore) {
167165
private KeyStore readKeyStore(Path path) {
168166
try {
169167
return KeyStoreUtil.readKeyStore(path, type, storePassword);
170-
} catch (AccessControlException e) {
168+
} catch (SecurityException e) {
171169
throw SslFileUtil.accessControlFailure("[" + type + "] keystore", List.of(path), e, configBasePath);
172-
} catch (NotEntitledException e) {
173-
throw SslFileUtil.notEntitledFailure("[" + type + "] keystore", List.of(path), e, configBasePath);
174170
} catch (IOException e) {
175171
throw SslFileUtil.ioException("[" + type + "] keystore", List.of(path), e);
176172
} catch (GeneralSecurityException e) {

libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/StoreTrustConfig.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99

1010
package org.elasticsearch.common.ssl;
1111

12-
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
13-
1412
import java.io.IOException;
1513
import java.nio.file.Path;
16-
import java.security.AccessControlException;
1714
import java.security.GeneralSecurityException;
1815
import java.security.KeyStore;
1916
import java.security.cert.X509Certificate;
@@ -95,10 +92,8 @@ public X509ExtendedTrustManager createTrustManager() {
9592
private KeyStore readKeyStore(Path path) {
9693
try {
9794
return KeyStoreUtil.readKeyStore(path, type, password);
98-
} catch (AccessControlException e) {
95+
} catch (SecurityException e) {
9996
throw SslFileUtil.accessControlFailure(fileTypeForException(), List.of(path), e, configBasePath);
100-
} catch (NotEntitledException e) {
101-
throw SslFileUtil.notEntitledFailure(fileTypeForException(), List.of(path), e, configBasePath);
10297
} catch (IOException e) {
10398
throw SslFileUtil.ioException(fileTypeForException(), List.of(path), e, getAdditionalErrorDetails());
10499
} catch (GeneralSecurityException e) {

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLConfigurationReloader.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
import org.elasticsearch.action.support.PlainActionFuture;
1313
import org.elasticsearch.common.ssl.SslConfiguration;
1414
import org.elasticsearch.core.TimeValue;
15-
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
1615
import org.elasticsearch.watcher.FileChangesListener;
1716
import org.elasticsearch.watcher.FileWatcher;
1817
import org.elasticsearch.watcher.ResourceWatcherService;
1918
import org.elasticsearch.watcher.ResourceWatcherService.Frequency;
2019

2120
import java.io.IOException;
2221
import java.nio.file.Path;
23-
import java.security.AccessControlException;
2422
import java.util.ArrayList;
2523
import java.util.Collection;
2624
import java.util.HashMap;
@@ -110,7 +108,7 @@ private static void startWatching(
110108
fileWatcher.addListener(changeListener);
111109
try {
112110
resourceWatcherService.add(fileWatcher, Frequency.HIGH);
113-
} catch (IOException | AccessControlException | NotEntitledException e) {
111+
} catch (IOException | SecurityException e) {
114112
logger.error("failed to start watching directory [{}] for ssl configurations [{}] - {}", path, configurations, e);
115113
}
116114
});

0 commit comments

Comments
 (0)