Skip to content

Commit b470229

Browse files
committed
Move AWS IAM authentication into nested class.
Having the AWS IAM authentication code inside the method body creating AwsIamAuthentication causes class loading of the AwsCredentialsProvider class although the return type is ClientAuthentication. With the code moved to an inner class, we mitigate that issue without actually knowing why the JVM attempts to load AwsIamAuthentication even the method isn't used. Closes gh-786
1 parent f459450 commit b470229

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

spring-vault-core/src/main/java/org/springframework/vault/config/EnvironmentVaultConfiguration.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.springframework.vault.authentication.AppRoleAuthenticationOptions.RoleId;
4040
import org.springframework.vault.authentication.AppRoleAuthenticationOptions.SecretId;
4141
import org.springframework.vault.authentication.AwsEc2AuthenticationOptions.AwsEc2AuthenticationOptionsBuilder;
42-
import org.springframework.vault.authentication.AwsIamAuthenticationOptions.AwsIamAuthenticationOptionsBuilder;
4342
import org.springframework.vault.authentication.AzureMsiAuthenticationOptions.AzureMsiAuthenticationOptionsBuilder;
4443
import org.springframework.vault.authentication.CubbyholeAuthenticationOptions.CubbyholeAuthenticationOptionsBuilder;
4544
import org.springframework.vault.authentication.KubernetesAuthenticationOptions.KubernetesAuthenticationOptionsBuilder;
@@ -389,11 +388,7 @@ protected ClientAuthentication awsIamAuthentication() {
389388
Assert.isTrue(StringUtils.hasText(role),
390389
"Vault AWS-IAM authentication: Role (vault.aws-iam.role) must not be empty");
391390

392-
AwsIamAuthenticationOptionsBuilder builder = AwsIamAuthenticationOptions.builder()
393-
.role(role)
394-
.credentialsProvider(DefaultCredentialsProvider.create());
395-
396-
return new AwsIamAuthentication(builder.build(), restOperations());
391+
return AwsIam.doCreateIamAuthentication(role, restOperations());
397392
}
398393

399394
protected ClientAuthentication azureMsiAuthentication() {
@@ -491,4 +486,18 @@ enum AuthenticationMethod {
491486

492487
}
493488

489+
static class AwsIam {
490+
491+
static ClientAuthentication doCreateIamAuthentication(String role, RestOperations restOperations) {
492+
493+
AwsIamAuthenticationOptions.AwsIamAuthenticationOptionsBuilder builder = AwsIamAuthenticationOptions
494+
.builder()
495+
.role(role)
496+
.credentialsProvider(DefaultCredentialsProvider.create());
497+
498+
return new AwsIamAuthentication(builder.build(), restOperations);
499+
}
500+
501+
}
502+
494503
}

0 commit comments

Comments
 (0)