Search in sources :

Example 1 with Signer

use of software.amazon.awssdk.core.signer.Signer in project aws-sdk-java-v2 by aws.

the class ProfileFileConfigurationTest method profileIsHonoredForCredentialsAndRegion.

@Test
public void profileIsHonoredForCredentialsAndRegion() {
    EnvironmentVariableHelper.run(env -> {
        env.remove(SdkSystemSetting.AWS_REGION);
        env.remove(SdkSystemSetting.AWS_ACCESS_KEY_ID);
        env.remove(SdkSystemSetting.AWS_SECRET_ACCESS_KEY);
        String profileContent = "[profile foo]\n" + "region = us-banana-46\n" + "aws_access_key_id = profileIsHonoredForCredentials_akid\n" + "aws_secret_access_key = profileIsHonoredForCredentials_skid";
        String profileName = "foo";
        Signer signer = mock(NoOpSigner.class);
        ProtocolRestJsonClient client = ProtocolRestJsonClient.builder().overrideConfiguration(overrideConfig(profileContent, profileName, signer)).build();
        Mockito.when(signer.sign(any(), any())).thenCallRealMethod();
        try {
            client.allTypes();
        } catch (SdkClientException e) {
        // expected
        }
        ArgumentCaptor<SdkHttpFullRequest> httpRequest = ArgumentCaptor.forClass(SdkHttpFullRequest.class);
        ArgumentCaptor<ExecutionAttributes> attributes = ArgumentCaptor.forClass(ExecutionAttributes.class);
        Mockito.verify(signer).sign(httpRequest.capture(), attributes.capture());
        AwsCredentials credentials = attributes.getValue().getAttribute(AwsSignerExecutionAttribute.AWS_CREDENTIALS);
        assertThat(credentials.accessKeyId()).isEqualTo("profileIsHonoredForCredentials_akid");
        assertThat(credentials.secretAccessKey()).isEqualTo("profileIsHonoredForCredentials_skid");
        Region region = attributes.getValue().getAttribute(AwsExecutionAttribute.AWS_REGION);
        assertThat(region.id()).isEqualTo("us-banana-46");
        assertThat(httpRequest.getValue().getUri().getHost()).contains("us-banana-46");
    });
}
Also used : NoOpSigner(software.amazon.awssdk.core.signer.NoOpSigner) Signer(software.amazon.awssdk.core.signer.Signer) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) Region(software.amazon.awssdk.regions.Region) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) Test(org.junit.jupiter.api.Test)

Example 2 with Signer

use of software.amazon.awssdk.core.signer.Signer in project aws-sdk-java-v2 by aws.

the class SigningStage method signRequest.

/**
 * Sign the request if the signer if provided and credentials are present.
 */
private SdkHttpFullRequest signRequest(SdkHttpFullRequest request, RequestExecutionContext context) throws Exception {
    updateInterceptorContext(request, context.executionContext());
    Signer signer = context.signer();
    MetricCollector metricCollector = context.attemptMetricCollector();
    if (shouldSign(signer)) {
        adjustForClockSkew(context.executionAttributes());
        Pair<SdkHttpFullRequest, Duration> measuredSign = MetricUtils.measureDuration(() -> signer.sign(request, context.executionAttributes()));
        metricCollector.reportMetric(CoreMetric.SIGNING_DURATION, measuredSign.right());
        SdkHttpFullRequest signedRequest = measuredSign.left();
        if (signer instanceof AsyncRequestBodySigner) {
            // Transform request body provider with signing operator
            AsyncRequestBody transformedRequestProvider = ((AsyncRequestBodySigner) signer).signAsyncRequestBody(signedRequest, context.requestProvider(), context.executionAttributes());
            context.requestProvider(transformedRequestProvider);
        }
        updateInterceptorContext(signedRequest, context.executionContext());
        return signedRequest;
    }
    return request;
}
Also used : AsyncRequestBodySigner(software.amazon.awssdk.core.signer.AsyncRequestBodySigner) Signer(software.amazon.awssdk.core.signer.Signer) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) Duration(java.time.Duration) AsyncRequestBodySigner(software.amazon.awssdk.core.signer.AsyncRequestBodySigner)

Example 3 with Signer

use of software.amazon.awssdk.core.signer.Signer in project aws-sdk-java-v2 by aws.

the class DefaultJsonClient method applySignerOverride.

private <T extends JsonRequest> T applySignerOverride(T request, Signer signer) {
    if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) {
        return request;
    }
    Consumer<AwsRequestOverrideConfiguration.Builder> signerOverride = b -> b.signer(signer).build();
    AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration().map(c -> c.toBuilder().applyMutation(signerOverride).build()).orElse((AwsRequestOverrideConfiguration.builder().applyMutation(signerOverride).build()));
    return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build();
}
Also used : ExceptionMetadata(software.amazon.awssdk.protocols.core.ExceptionMetadata) GetWithoutRequiredMembersResponse(software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersResponse) GetWithoutRequiredMembersRequestMarshaller(software.amazon.awssdk.services.json.transform.GetWithoutRequiredMembersRequestMarshaller) StreamingInputOutputOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.StreamingInputOutputOperationRequestMarshaller) StreamingInputOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.StreamingInputOperationRequestMarshaller) GetOperationWithChecksumRequest(software.amazon.awssdk.services.json.model.GetOperationWithChecksumRequest) ResponseTransformer(software.amazon.awssdk.core.sync.ResponseTransformer) JsonException(software.amazon.awssdk.services.json.model.JsonException) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) ApiName(software.amazon.awssdk.core.ApiName) GetWithoutRequiredMembersRequest(software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersRequest) PutOperationWithChecksumResponse(software.amazon.awssdk.services.json.model.PutOperationWithChecksumResponse) SdkClientOption(software.amazon.awssdk.core.client.config.SdkClientOption) StreamingInputOperationRequest(software.amazon.awssdk.services.json.model.StreamingInputOperationRequest) HostnameValidator(software.amazon.awssdk.utils.HostnameValidator) StreamingOutputOperationResponse(software.amazon.awssdk.services.json.model.StreamingOutputOperationResponse) APostOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.APostOperationRequestMarshaller) StreamingInputOperationResponse(software.amazon.awssdk.services.json.model.StreamingInputOperationResponse) PaginatedOperationWithResultKeyResponse(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) OperationWithChecksumRequiredRequest(software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredRequest) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) APostOperationWithOutputResponse(software.amazon.awssdk.services.json.model.APostOperationWithOutputResponse) GetOperationWithChecksumRequestMarshaller(software.amazon.awssdk.services.json.transform.GetOperationWithChecksumRequestMarshaller) List(java.util.List) APostOperationRequest(software.amazon.awssdk.services.json.model.APostOperationRequest) APostOperationResponse(software.amazon.awssdk.services.json.model.APostOperationResponse) PaginatedOperationWithoutResultKeyResponse(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyResponse) StreamingInputOutputOperationRequest(software.amazon.awssdk.services.json.model.StreamingInputOutputOperationRequest) GetOperationWithChecksumResponse(software.amazon.awssdk.services.json.model.GetOperationWithChecksumResponse) SyncClientHandler(software.amazon.awssdk.core.client.handler.SyncClientHandler) APostOperationWithOutputRequestMarshaller(software.amazon.awssdk.services.json.transform.APostOperationWithOutputRequestMarshaller) PutOperationWithChecksumRequestMarshaller(software.amazon.awssdk.services.json.transform.PutOperationWithChecksumRequestMarshaller) HttpResponseHandler(software.amazon.awssdk.core.http.HttpResponseHandler) Aws4UnsignedPayloadSigner(software.amazon.awssdk.auth.signer.Aws4UnsignedPayloadSigner) JsonRequest(software.amazon.awssdk.services.json.model.JsonRequest) Generated(software.amazon.awssdk.annotations.Generated) OperationWithChecksumRequiredRequestMarshaller(software.amazon.awssdk.services.json.transform.OperationWithChecksumRequiredRequestMarshaller) PaginatedOperationWithResultKeyRequestMarshaller(software.amazon.awssdk.services.json.transform.PaginatedOperationWithResultKeyRequestMarshaller) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) Signer(software.amazon.awssdk.core.signer.Signer) PaginatedOperationWithoutResultKeyRequestMarshaller(software.amazon.awssdk.services.json.transform.PaginatedOperationWithoutResultKeyRequestMarshaller) AwsJsonProtocol(software.amazon.awssdk.protocols.json.AwsJsonProtocol) PutOperationWithChecksumRequest(software.amazon.awssdk.services.json.model.PutOperationWithChecksumRequest) PaginatedOperationWithResultKeyIterable(software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyIterable) OperationWithChecksumRequiredResponse(software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredResponse) PaginatedOperationWithoutResultKeyIterable(software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyIterable) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) VersionInfo(software.amazon.awssdk.core.util.VersionInfo) HttpChecksumRequired(software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired) PaginatedOperationWithResultKeyRequest(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest) AwsSyncClientHandler(software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler) CoreMetric(software.amazon.awssdk.core.metrics.CoreMetric) BaseAwsJsonProtocolFactory(software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory) InvalidInputException(software.amazon.awssdk.services.json.model.InvalidInputException) RequestOverrideConfiguration(software.amazon.awssdk.core.RequestOverrideConfiguration) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) PaginatedOperationWithoutResultKeyRequest(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest) StreamingOutputOperationRequest(software.amazon.awssdk.services.json.model.StreamingOutputOperationRequest) SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Logger(software.amazon.awssdk.utils.Logger) APostOperationWithOutputRequest(software.amazon.awssdk.services.json.model.APostOperationWithOutputRequest) Consumer(java.util.function.Consumer) HttpChecksum(software.amazon.awssdk.core.interceptor.trait.HttpChecksum) StreamingOutputOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.StreamingOutputOperationRequestMarshaller) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) StreamingInputOutputOperationResponse(software.amazon.awssdk.services.json.model.StreamingInputOutputOperationResponse) StreamingRequestMarshaller(software.amazon.awssdk.core.runtime.transform.StreamingRequestMarshaller) RequestBody(software.amazon.awssdk.core.sync.RequestBody) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) AwsJsonProtocolFactory(software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory) Collections(java.util.Collections) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration)

Example 4 with Signer

use of software.amazon.awssdk.core.signer.Signer in project aws-sdk-java-v2 by aws.

the class DefaultXmlAsyncClient method applySignerOverride.

private <T extends XmlRequest> T applySignerOverride(T request, Signer signer) {
    if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) {
        return request;
    }
    Consumer<AwsRequestOverrideConfiguration.Builder> signerOverride = b -> b.signer(signer).build();
    AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration().map(c -> c.toBuilder().applyMutation(signerOverride).build()).orElse((AwsRequestOverrideConfiguration.builder().applyMutation(signerOverride).build()));
    return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build();
}
Also used : ExceptionMetadata(software.amazon.awssdk.protocols.core.ExceptionMetadata) AwsAsyncClientHandler(software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler) StreamingOutputOperationRequestMarshaller(software.amazon.awssdk.services.xml.transform.StreamingOutputOperationRequestMarshaller) EventStreamOperationResponseHandler(software.amazon.awssdk.services.xml.model.EventStreamOperationResponseHandler) GetOperationWithChecksumRequestMarshaller(software.amazon.awssdk.services.xml.transform.GetOperationWithChecksumRequestMarshaller) XmlRequest(software.amazon.awssdk.services.xml.model.XmlRequest) LoggerFactory(org.slf4j.LoggerFactory) StreamingOutputOperationRequest(software.amazon.awssdk.services.xml.model.StreamingOutputOperationRequest) RestEventStreamAsyncResponseTransformer(software.amazon.awssdk.awscore.eventstream.RestEventStreamAsyncResponseTransformer) StreamingInputOperationResponse(software.amazon.awssdk.services.xml.model.StreamingInputOperationResponse) XmlException(software.amazon.awssdk.services.xml.model.XmlException) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) GetOperationWithChecksumResponse(software.amazon.awssdk.services.xml.model.GetOperationWithChecksumResponse) APostOperationRequest(software.amazon.awssdk.services.xml.model.APostOperationRequest) AsyncStreamingRequestMarshaller(software.amazon.awssdk.core.runtime.transform.AsyncStreamingRequestMarshaller) AsyncResponseTransformer(software.amazon.awssdk.core.async.AsyncResponseTransformer) SdkClientOption(software.amazon.awssdk.core.client.config.SdkClientOption) StreamingInputOperationRequest(software.amazon.awssdk.services.xml.model.StreamingInputOperationRequest) AsyncClientHandler(software.amazon.awssdk.core.client.handler.AsyncClientHandler) EventStreamOperationRequest(software.amazon.awssdk.services.xml.model.EventStreamOperationRequest) PutOperationWithChecksumRequestMarshaller(software.amazon.awssdk.services.xml.transform.PutOperationWithChecksumRequestMarshaller) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) XmlOperationMetadata(software.amazon.awssdk.protocols.xml.XmlOperationMetadata) OperationWithChecksumRequiredRequestMarshaller(software.amazon.awssdk.services.xml.transform.OperationWithChecksumRequiredRequestMarshaller) SdkPojoBuilder(software.amazon.awssdk.core.SdkPojoBuilder) EventStreamOperationRequestMarshaller(software.amazon.awssdk.services.xml.transform.EventStreamOperationRequestMarshaller) APostOperationRequestMarshaller(software.amazon.awssdk.services.xml.transform.APostOperationRequestMarshaller) List(java.util.List) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) AwsXmlProtocolFactory(software.amazon.awssdk.protocols.xml.AwsXmlProtocolFactory) AsyncAws4Signer(software.amazon.awssdk.auth.signer.AsyncAws4Signer) SdkAdvancedAsyncClientOption(software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption) HttpResponseHandler(software.amazon.awssdk.core.http.HttpResponseHandler) Generated(software.amazon.awssdk.annotations.Generated) AsyncResponseTransformerUtils(software.amazon.awssdk.core.async.AsyncResponseTransformerUtils) GetOperationWithChecksumRequest(software.amazon.awssdk.services.xml.model.GetOperationWithChecksumRequest) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) Signer(software.amazon.awssdk.core.signer.Signer) OperationWithChecksumRequiredRequest(software.amazon.awssdk.services.xml.model.OperationWithChecksumRequiredRequest) EventStreamAsyncResponseTransformer(software.amazon.awssdk.awscore.eventstream.EventStreamAsyncResponseTransformer) StreamingOutputOperationResponse(software.amazon.awssdk.services.xml.model.StreamingOutputOperationResponse) EventStreamTaggedUnionPojoSupplier(software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionPojoSupplier) PutOperationWithChecksumResponse(software.amazon.awssdk.services.xml.model.PutOperationWithChecksumResponse) CompletableFutureUtils(software.amazon.awssdk.utils.CompletableFutureUtils) CompletableFuture(java.util.concurrent.CompletableFuture) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) Response(software.amazon.awssdk.core.Response) HttpChecksumRequired(software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired) StreamingInputOperationRequestMarshaller(software.amazon.awssdk.services.xml.transform.StreamingInputOperationRequestMarshaller) CoreMetric(software.amazon.awssdk.core.metrics.CoreMetric) APostOperationWithOutputResponse(software.amazon.awssdk.services.xml.model.APostOperationWithOutputResponse) RequestOverrideConfiguration(software.amazon.awssdk.core.RequestOverrideConfiguration) EventStream(software.amazon.awssdk.services.xml.model.EventStream) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) Logger(org.slf4j.Logger) SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Executor(java.util.concurrent.Executor) APostOperationWithOutputRequestMarshaller(software.amazon.awssdk.services.xml.transform.APostOperationWithOutputRequestMarshaller) Pair(software.amazon.awssdk.utils.Pair) APostOperationResponse(software.amazon.awssdk.services.xml.model.APostOperationResponse) Consumer(java.util.function.Consumer) HttpChecksum(software.amazon.awssdk.core.interceptor.trait.HttpChecksum) InvalidInputException(software.amazon.awssdk.services.xml.model.InvalidInputException) APostOperationWithOutputRequest(software.amazon.awssdk.services.xml.model.APostOperationWithOutputRequest) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) PutOperationWithChecksumRequest(software.amazon.awssdk.services.xml.model.PutOperationWithChecksumRequest) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) EventStreamOperationResponse(software.amazon.awssdk.services.xml.model.EventStreamOperationResponse) OperationWithChecksumRequiredResponse(software.amazon.awssdk.services.xml.model.OperationWithChecksumRequiredResponse) FunctionalUtils.runAndLogError(software.amazon.awssdk.utils.FunctionalUtils.runAndLogError) Collections(java.util.Collections) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) SdkPojoBuilder(software.amazon.awssdk.core.SdkPojoBuilder)

Example 5 with Signer

use of software.amazon.awssdk.core.signer.Signer in project aws-sdk-java-v2 by aws.

the class AwsExecutionContextBuilder method invokeInterceptorsAndCreateExecutionContext.

/**
 * Used by both sync and async clients to create the execution context, and run initial interceptors.
 */
public static <InputT extends SdkRequest, OutputT extends SdkResponse> ExecutionContext invokeInterceptorsAndCreateExecutionContext(ClientExecutionParams<InputT, OutputT> executionParams, SdkClientConfiguration clientConfig) {
    // Note: This is currently copied to DefaultS3Presigner and other presigners.
    // Don't edit this without considering those
    SdkRequest originalRequest = executionParams.getInput();
    MetricCollector metricCollector = resolveMetricCollector(executionParams);
    ExecutionAttributes executionAttributes = mergeExecutionAttributeOverrides(executionParams.executionAttributes(), clientConfig.option(SdkClientOption.EXECUTION_ATTRIBUTES), originalRequest.overrideConfiguration().map(c -> c.executionAttributes()).orElse(null));
    executionAttributes.putAttribute(InternalCoreExecutionAttribute.EXECUTION_ATTEMPT, 1).putAttribute(AwsSignerExecutionAttribute.SERVICE_CONFIG, clientConfig.option(SdkClientOption.SERVICE_CONFIGURATION)).putAttribute(AwsSignerExecutionAttribute.SERVICE_SIGNING_NAME, clientConfig.option(AwsClientOption.SERVICE_SIGNING_NAME)).putAttribute(AwsExecutionAttribute.AWS_REGION, clientConfig.option(AwsClientOption.AWS_REGION)).putAttribute(AwsExecutionAttribute.ENDPOINT_PREFIX, clientConfig.option(AwsClientOption.ENDPOINT_PREFIX)).putAttribute(AwsSignerExecutionAttribute.SIGNING_REGION, clientConfig.option(AwsClientOption.SIGNING_REGION)).putAttribute(SdkInternalExecutionAttribute.IS_FULL_DUPLEX, executionParams.isFullDuplex()).putAttribute(SdkInternalExecutionAttribute.HAS_INITIAL_REQUEST_EVENT, executionParams.hasInitialRequestEvent()).putAttribute(SdkExecutionAttribute.CLIENT_TYPE, clientConfig.option(SdkClientOption.CLIENT_TYPE)).putAttribute(SdkExecutionAttribute.SERVICE_NAME, clientConfig.option(SdkClientOption.SERVICE_NAME)).putAttribute(SdkExecutionAttribute.PROFILE_FILE, clientConfig.option(SdkClientOption.PROFILE_FILE)).putAttribute(SdkExecutionAttribute.PROFILE_NAME, clientConfig.option(SdkClientOption.PROFILE_NAME)).putAttribute(AwsExecutionAttribute.DUALSTACK_ENDPOINT_ENABLED, clientConfig.option(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED)).putAttribute(AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED, clientConfig.option(AwsClientOption.FIPS_ENDPOINT_ENABLED)).putAttribute(SdkExecutionAttribute.OPERATION_NAME, executionParams.getOperationName()).putAttribute(SdkExecutionAttribute.CLIENT_ENDPOINT, clientConfig.option(SdkClientOption.ENDPOINT)).putAttribute(SdkExecutionAttribute.ENDPOINT_OVERRIDDEN, clientConfig.option(SdkClientOption.ENDPOINT_OVERRIDDEN)).putAttribute(SdkInternalExecutionAttribute.DISABLE_HOST_PREFIX_INJECTION, clientConfig.option(SdkAdvancedClientOption.DISABLE_HOST_PREFIX_INJECTION)).putAttribute(SdkExecutionAttribute.SIGNER_OVERRIDDEN, clientConfig.option(SdkClientOption.SIGNER_OVERRIDDEN)).putAttribute(RESOLVED_CHECKSUM_SPECS, HttpChecksumResolver.getResolvedChecksumSpecs(executionAttributes));
    ExecutionInterceptorChain executionInterceptorChain = new ExecutionInterceptorChain(clientConfig.option(SdkClientOption.EXECUTION_INTERCEPTORS));
    InterceptorContext interceptorContext = InterceptorContext.builder().request(originalRequest).asyncRequestBody(executionParams.getAsyncRequestBody()).requestBody(executionParams.getRequestBody()).build();
    interceptorContext = runInitialInterceptors(interceptorContext, executionAttributes, executionInterceptorChain);
    Signer signer = resolveSigner(interceptorContext.request(), clientConfig.option(SdkAdvancedClientOption.SIGNER));
    // beforeExecution and modifyRequest interceptors should avoid dependency on credentials,
    // since they should be resolved after the interceptors run
    AwsCredentials credentials = resolveCredentials(clientConfig.option(AwsClientOption.CREDENTIALS_PROVIDER), originalRequest, metricCollector);
    executionAttributes.putAttribute(AwsSignerExecutionAttribute.AWS_CREDENTIALS, credentials);
    executionAttributes.putAttribute(HttpChecksumConstant.SIGNING_METHOD, resolveSigningMethodUsed(signer, executionAttributes, credentials));
    return ExecutionContext.builder().interceptorChain(executionInterceptorChain).interceptorContext(interceptorContext).executionAttributes(executionAttributes).signer(signer).metricCollector(metricCollector).build();
}
Also used : Signer(software.amazon.awssdk.core.signer.Signer) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkRequest(software.amazon.awssdk.core.SdkRequest) ExecutionInterceptorChain(software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain) InterceptorContext(software.amazon.awssdk.core.interceptor.InterceptorContext) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Aggregations

Signer (software.amazon.awssdk.core.signer.Signer)14 List (java.util.List)8 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)7 AsyncRequestBody (software.amazon.awssdk.core.async.AsyncRequestBody)6 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)6 SdkClientOption (software.amazon.awssdk.core.client.config.SdkClientOption)6 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)6 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)6 MetricPublisher (software.amazon.awssdk.metrics.MetricPublisher)6 Collections (java.util.Collections)5 ArrayList (java.util.ArrayList)4 Consumer (java.util.function.Consumer)4 Test (org.junit.Test)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 Mockito.verify (org.mockito.Mockito.verify)4 AsyncAws4Signer (software.amazon.awssdk.auth.signer.AsyncAws4Signer)4 SIGNER (software.amazon.awssdk.core.client.config.SdkAdvancedClientOption.SIGNER)4 Method (java.lang.reflect.Method)3 URI (java.net.URI)3 Duration (java.time.Duration)3