3333import software .amazon .awssdk .core .interceptor .ExecutionAttributes ;
3434import software .amazon .awssdk .core .signer .Signer ;
3535import software .amazon .awssdk .endpoints .EndpointProvider ;
36+ import software .amazon .awssdk .http .auth .spi .scheme .AuthSchemeProvider ;
3637import software .amazon .awssdk .metrics .MetricPublisher ;
3738import software .amazon .awssdk .utils .CollectionUtils ;
3839import software .amazon .awssdk .utils .Validate ;
@@ -53,6 +54,7 @@ public abstract class RequestOverrideConfiguration {
5354 private final List <MetricPublisher > metricPublishers ;
5455 private final ExecutionAttributes executionAttributes ;
5556 private final EndpointProvider endpointProvider ;
57+ private final AuthSchemeProvider authSchemeProvider ;
5658 private final CompressionConfiguration compressionConfiguration ;
5759 private final List <SdkPlugin > plugins ;
5860
@@ -66,6 +68,7 @@ protected RequestOverrideConfiguration(Builder<?> builder) {
6668 this .metricPublishers = Collections .unmodifiableList (new ArrayList <>(builder .metricPublishers ()));
6769 this .executionAttributes = ExecutionAttributes .unmodifiableExecutionAttributes (builder .executionAttributes ());
6870 this .endpointProvider = builder .endpointProvider ();
71+ this .authSchemeProvider = builder .authSchemeProvider ();
6972 this .compressionConfiguration = builder .compressionConfiguration ();
7073 this .plugins = Collections .unmodifiableList (new ArrayList <>(builder .plugins ()));
7174 }
@@ -177,6 +180,14 @@ public Optional<EndpointProvider> endpointProvider() {
177180 return Optional .ofNullable (endpointProvider );
178181 }
179182
183+ /**
184+ * Returns the auth scheme provider for resolving the auth scheme for this request. This supersedes the
185+ * auth scheme provider set on the client.
186+ */
187+ public Optional <AuthSchemeProvider > authSchemeProvider () {
188+ return Optional .ofNullable (authSchemeProvider );
189+ }
190+
180191 /**
181192 * Returns the compression configuration object, if present, which includes options to enable/disable compression and set
182193 * the minimum compression threshold. This compression config object supersedes the compression config object set on the
@@ -204,6 +215,7 @@ public boolean equals(Object o) {
204215 Objects .equals (metricPublishers , that .metricPublishers ) &&
205216 Objects .equals (executionAttributes , that .executionAttributes ) &&
206217 Objects .equals (endpointProvider , that .endpointProvider ) &&
218+ Objects .equals (authSchemeProvider , that .authSchemeProvider ) &&
207219 Objects .equals (compressionConfiguration , that .compressionConfiguration ) &&
208220 Objects .equals (plugins , that .plugins );
209221 }
@@ -220,6 +232,7 @@ public int hashCode() {
220232 hashCode = 31 * hashCode + Objects .hashCode (metricPublishers );
221233 hashCode = 31 * hashCode + Objects .hashCode (executionAttributes );
222234 hashCode = 31 * hashCode + Objects .hashCode (endpointProvider );
235+ hashCode = 31 * hashCode + Objects .hashCode (authSchemeProvider );
223236 hashCode = 31 * hashCode + Objects .hashCode (compressionConfiguration );
224237 hashCode = 31 * hashCode + Objects .hashCode (plugins );
225238 return hashCode ;
@@ -456,13 +469,57 @@ default B putRawQueryParameter(String name, String value) {
456469 * over the endpointProvider set on the client while resolving the endpoint for the requests.
457470 * If this value is null, then the client level endpointProvider is used for resolving the endpoint.
458471 *
459- * @param endpointProvider Endpoint Provider that will override the resolving the endpoint for the request.
472+ * @param endpointProvider Endpoint Provider that will override client's configured or default EndpointProvider
473+ * for the request.
460474 * @return This object for method chaining
461475 */
462476 B endpointProvider (EndpointProvider endpointProvider );
463477
464478 EndpointProvider endpointProvider ();
465479
480+ /**
481+ * Sets the auth scheme provider to use for resolving the auth scheme of the request. This auth scheme provider gets
482+ * priority over the auth scheme provider set on the client while resolving the auth scheme for the requests.
483+ * If this value is null, then the client level auth scheme provider is used for resolving the auth scheme.
484+ *
485+ * <p>Example — overriding the signing region for a single request:
486+ * {@snippet :
487+ * // Create a custom auth scheme provider that overrides the signing region.
488+ * // This wraps the default provider and modifies the resolved auth scheme options.
489+ * S3AuthSchemeProvider defaultProvider = S3AuthSchemeProvider.defaultProvider();
490+ *
491+ * S3AuthSchemeProvider customRegionProvider = params -> {
492+ * List<AuthSchemeOption> options = defaultProvider.resolveAuthScheme(params);
493+ * return options.stream()
494+ * .map(option -> option.toBuilder()
495+ * .putSignerProperty(AwsV4HttpSigner.REGION_NAME, "eu-west-1")
496+ * .build())
497+ * .collect(Collectors.toList());
498+ * };
499+ *
500+ * S3Client s3 = S3Client.builder()
501+ * .region(Region.US_EAST_1)
502+ * .build();
503+ *
504+ * // Override the auth scheme provider for a single request
505+ * GetObjectResponse response = s3.getObject(
506+ * GetObjectRequest.builder()
507+ * .bucket("my-bucket")
508+ * .key("my-key")
509+ * .overrideConfiguration(c -> c.authSchemeProvider(customRegionProvider))
510+ * .build(),
511+ * ResponseTransformer.toBytes()
512+ * );
513+ * }
514+ *
515+ * @param authSchemeProvider Auth scheme provider that will override the client's configured or default
516+ * AuthSchemeProvider for the request.
517+ * @return This object for method chaining
518+ */
519+ B authSchemeProvider (AuthSchemeProvider authSchemeProvider );
520+
521+ AuthSchemeProvider authSchemeProvider ();
522+
466523 /**
467524 * Sets the {@link CompressionConfiguration} for this request. The order of precedence, from highest to lowest,
468525 * for this setting is: 1) Per request configuration 2) Client configuration 3) Environment variables 4) Profile setting.
@@ -546,6 +603,7 @@ protected abstract static class BuilderImpl<B extends Builder> implements Builde
546603 private List <MetricPublisher > metricPublishers = new ArrayList <>();
547604 private ExecutionAttributes .Builder executionAttributesBuilder = ExecutionAttributes .builder ();
548605 private EndpointProvider endpointProvider ;
606+ private AuthSchemeProvider authSchemeProvider ;
549607 private CompressionConfiguration compressionConfiguration ;
550608 private List <SdkPlugin > plugins = new ArrayList <>();
551609
@@ -563,6 +621,7 @@ protected BuilderImpl(RequestOverrideConfiguration sdkRequestOverrideConfig) {
563621 metricPublishers (sdkRequestOverrideConfig .metricPublishers ());
564622 executionAttributes (sdkRequestOverrideConfig .executionAttributes ());
565623 endpointProvider (sdkRequestOverrideConfig .endpointProvider );
624+ authSchemeProvider (sdkRequestOverrideConfig .authSchemeProvider );
566625 compressionConfiguration (sdkRequestOverrideConfig .compressionConfiguration );
567626 plugins (sdkRequestOverrideConfig .plugins );
568627 }
@@ -734,6 +793,21 @@ public EndpointProvider endpointProvider() {
734793 return endpointProvider ;
735794 }
736795
796+ @ Override
797+ public B authSchemeProvider (AuthSchemeProvider authSchemeProvider ) {
798+ this .authSchemeProvider = authSchemeProvider ;
799+ return (B ) this ;
800+ }
801+
802+ public void setAuthSchemeProvider (AuthSchemeProvider authSchemeProvider ) {
803+ authSchemeProvider (authSchemeProvider );
804+ }
805+
806+ @ Override
807+ public AuthSchemeProvider authSchemeProvider () {
808+ return authSchemeProvider ;
809+ }
810+
737811 @ Override
738812 public B compressionConfiguration (CompressionConfiguration compressionConfiguration ) {
739813 this .compressionConfiguration = compressionConfiguration ;
0 commit comments