|
31 | 31 | import software.amazon.awssdk.auth.credentials.AwsCredentials; |
32 | 32 | import software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute; |
33 | 33 | import software.amazon.awssdk.awscore.AwsExecutionAttribute; |
| 34 | +import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; |
34 | 35 | import software.amazon.awssdk.awscore.client.config.AwsClientOption; |
35 | 36 | import software.amazon.awssdk.awscore.internal.authcontext.AuthorizationStrategy; |
36 | 37 | import software.amazon.awssdk.awscore.internal.authcontext.AuthorizationStrategyFactory; |
@@ -307,14 +308,36 @@ private static void putAuthSchemeResolutionAttributes(ExecutionAttributes execut |
307 | 308 | // request preferred over client. |
308 | 309 | Map<String, AuthScheme<?>> authSchemes = clientConfig.option(SdkClientOption.AUTH_SCHEMES); |
309 | 310 |
|
310 | | - IdentityProviders identityProviders = clientConfig.option(SdkClientOption.IDENTITY_PROVIDERS); |
| 311 | + IdentityProviders identityProviders = resolveIdentityProviders(originalRequest, clientConfig); |
311 | 312 |
|
312 | 313 | executionAttributes |
313 | 314 | .putAttribute(SdkInternalExecutionAttribute.AUTH_SCHEME_RESOLVER, authSchemeProvider) |
314 | 315 | .putAttribute(SdkInternalExecutionAttribute.AUTH_SCHEMES, authSchemes) |
315 | 316 | .putAttribute(SdkInternalExecutionAttribute.IDENTITY_PROVIDERS, identityProviders); |
316 | 317 | } |
317 | 318 |
|
| 319 | + private static IdentityProviders resolveIdentityProviders(SdkRequest originalRequest, |
| 320 | + SdkClientConfiguration clientConfig) { |
| 321 | + IdentityProviders identityProviders = clientConfig.option(SdkClientOption.IDENTITY_PROVIDERS); |
| 322 | + |
| 323 | + // identityProviders can be null, for new core with old client. In this case, even if AwsRequestOverrideConfiguration |
| 324 | + // has credentialsIdentityProvider set (because it is in new core), it is ok to not setup IDENTITY_PROVIDERS, as old |
| 325 | + // client won't have AUTH_SCHEME_PROVIDER/AUTH_SCHEMES set either, which are also needed for SRA logic. |
| 326 | + if (identityProviders == null) { |
| 327 | + return null; |
| 328 | + } |
| 329 | + |
| 330 | + return originalRequest |
| 331 | + .overrideConfiguration() |
| 332 | + .filter(c -> c instanceof AwsRequestOverrideConfiguration) |
| 333 | + .map(c -> (AwsRequestOverrideConfiguration) c) |
| 334 | + .map(c -> identityProviders.copy(b -> { |
| 335 | + c.credentialsIdentityProvider().ifPresent(b::putIdentityProvider); |
| 336 | + c.tokenIdentityProvider().ifPresent(b::putIdentityProvider); |
| 337 | + })) |
| 338 | + .orElse(identityProviders); |
| 339 | + } |
| 340 | + |
318 | 341 | /** |
319 | 342 | * Finalize {@link SdkRequest} by running beforeExecution and modifyRequest interceptors. |
320 | 343 | * |
|
0 commit comments