diff --git a/wrapper/src/main/java/software/amazon/jdbc/authentication/AwsCredentialsManager.java b/wrapper/src/main/java/software/amazon/jdbc/authentication/AwsCredentialsManager.java index 3158a842b..2b33cb851 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/authentication/AwsCredentialsManager.java +++ b/wrapper/src/main/java/software/amazon/jdbc/authentication/AwsCredentialsManager.java @@ -18,11 +18,13 @@ import java.util.Properties; import java.util.concurrent.locks.ReentrantLock; +import org.checkerframework.checker.nullness.qual.Nullable; import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; import software.amazon.jdbc.HostSpec; import software.amazon.jdbc.PropertyDefinition; import software.amazon.jdbc.util.Messages; +import software.amazon.jdbc.util.StringUtils; public class AwsCredentialsManager { private static AwsCredentialsProviderHandler handler = null; @@ -64,7 +66,11 @@ public static AwsCredentialsProvider getProvider(final HostSpec hostSpec, final } } - private static AwsCredentialsProvider getDefaultProvider() { - return DefaultCredentialsProvider.create(); + private static AwsCredentialsProvider getDefaultProvider(final @Nullable String awsProfileName) { + DefaultCredentialsProvider.Builder builder = DefaultCredentialsProvider.builder(); + if (!StringUtils.isNullOrEmpty(awsProfileName)) { + builder.profileName(awsProfileName); + } + return builder.build(); } } diff --git a/wrapper/src/test/java/software/amazon/jdbc/authentication/AwsCredentialsManagerTest.java b/wrapper/src/test/java/software/amazon/jdbc/authentication/AwsCredentialsManagerTest.java index e2dfbd101..6028f5706 100644 --- a/wrapper/src/test/java/software/amazon/jdbc/authentication/AwsCredentialsManagerTest.java +++ b/wrapper/src/test/java/software/amazon/jdbc/authentication/AwsCredentialsManagerTest.java @@ -86,7 +86,6 @@ public void testAwsCredentialsManager() { @Test public void testNullProvider() { AwsCredentialsManager.setCustomHandler(((hostSpec, props) -> null)); - assertThrows(IllegalArgumentException.class, - () -> AwsCredentialsManager.getProvider(mockHostSpec, mockProps)); + assertTrue(AwsCredentialsManager.getProvider(mockHostSpec, mockProps) instanceof DefaultCredentialsProvider); } }