Skip to content

Commit 285eab6

Browse files
authored
fix: Create default wrapped clients only if necessary. (#163)
Create the default wrapped clients only if they have not been specified explicitly. S3Client.create or S3AsyncClient.create can fail in restrictive environments because they attempt to load profiles and credentials from disk, thus requiring java.io.FilePermission. This patch moves these calls from the class initializer to the build method, so users can prevent the calls by passing their own wrapped clients.
1 parent 74ed21d commit 285eab6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/java/software/amazon/encryption/s3/S3EncryptionClient.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ public void close() {
473473
// Make sure to keep both clients in mind when adding new builder options
474474
public static class Builder {
475475
// The non-encrypted APIs will use a default client.
476-
private S3Client _wrappedClient = S3Client.create();
477-
private S3AsyncClient _wrappedAsyncClient = S3AsyncClient.create();
476+
private S3Client _wrappedClient;
477+
private S3AsyncClient _wrappedAsyncClient;
478478

479479
private MultipartUploadObjectPipeline _multipartPipeline;
480480
private CryptographicMaterialsManager _cryptoMaterialsManager;
@@ -718,6 +718,14 @@ public S3EncryptionClient build() {
718718
throw new S3EncryptionClientException("Exactly one must be set of: crypto materials manager, keyring, AES key, RSA key pair, KMS key id");
719719
}
720720

721+
if (_wrappedClient == null) {
722+
_wrappedClient = S3Client.create();
723+
}
724+
725+
if (_wrappedAsyncClient == null) {
726+
_wrappedAsyncClient = S3AsyncClient.create();
727+
}
728+
721729
if (_keyring == null) {
722730
if (_aesKey != null) {
723731
_keyring = AesKeyring.builder()

0 commit comments

Comments
 (0)