Skip to content

Commit fc610da

Browse files
authored
Merge pull request #2021 from beyonnex-io/bugfix/mongo-aws-iam-auth
remove the use of try for StsClient to avoid closing the client prema…
2 parents 01fdc5a + 5ab6b17 commit fc610da

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

internal/utils/persistence/src/main/java/org/eclipse/ditto/internal/utils/persistence/mongo/auth/AwsAuthenticationHelper.java

+16-17
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,24 @@ public static MongoCredential provideAwsIamBasedMongoCredential(
6161
}
6262

6363
final Supplier<AwsCredential> awsFreshCredentialSupplier;
64-
try (final StsClient stsClient = stsClientBuilder.build()) {
65-
awsFreshCredentialSupplier = () -> {
66-
LOGGER.info("Supplying AWS IAM credentials, assuming role <{}> in session name <{}>",
67-
awsRoleArn, awsSessionName);
64+
final StsClient stsClient = stsClientBuilder.build();
65+
awsFreshCredentialSupplier = () -> {
66+
LOGGER.info("Supplying AWS IAM credentials, assuming role <{}> in session name <{}>",
67+
awsRoleArn, awsSessionName);
6868

69-
// assume role using the AWS SDK
70-
final AssumeRoleRequest roleRequest = AssumeRoleRequest.builder()
71-
.roleArn(awsRoleArn)
72-
.roleSessionName(awsSessionName)
73-
.build();
74-
final AssumeRoleResponse roleResponse = stsClient.assumeRole(roleRequest);
75-
final Credentials awsCredentials = roleResponse.credentials();
69+
// assume role using the AWS SDK
70+
final AssumeRoleRequest roleRequest = AssumeRoleRequest.builder()
71+
.roleArn(awsRoleArn)
72+
.roleSessionName(awsSessionName)
73+
.build();
74+
final AssumeRoleResponse roleResponse = stsClient.assumeRole(roleRequest);
75+
final Credentials awsCredentials = roleResponse.credentials();
7676

77-
return new AwsCredential(awsCredentials.accessKeyId(), awsCredentials.secretAccessKey(),
78-
awsCredentials.sessionToken());
79-
};
77+
return new AwsCredential(awsCredentials.accessKeyId(), awsCredentials.secretAccessKey(),
78+
awsCredentials.sessionToken());
79+
};
8080

81-
return MongoCredential.createAwsCredential(null, null)
82-
.withMechanismProperty(MongoCredential.AWS_CREDENTIAL_PROVIDER_KEY, awsFreshCredentialSupplier);
83-
}
81+
return MongoCredential.createAwsCredential(null, null)
82+
.withMechanismProperty(MongoCredential.AWS_CREDENTIAL_PROVIDER_KEY, awsFreshCredentialSupplier);
8483
}
8584
}

0 commit comments

Comments
 (0)