Search in sources :

Example 1 with Presigner

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

the class DefaultS3Presigner method initializePresignedRequest.

/**
 * Initialize the provided presigned request.
 */
private void initializePresignedRequest(PresignedRequest.Builder presignedRequest, ExecutionContext execCtx, SdkHttpFullRequest signedHttpRequest) {
    SdkBytes signedPayload = signedHttpRequest.contentStreamProvider().map(p -> SdkBytes.fromInputStream(p.newStream())).orElse(null);
    List<String> signedHeadersQueryParam = signedHttpRequest.firstMatchingRawQueryParameters("X-Amz-SignedHeaders");
    Validate.validState(!signedHeadersQueryParam.isEmpty(), "Only SigV4 presigners are supported at this time, but the configured " + "presigner (%s) did not seem to generate a SigV4 signature.", execCtx.signer());
    Map<String, List<String>> signedHeaders = signedHeadersQueryParam.stream().flatMap(h -> Stream.of(h.split(";"))).collect(toMap(h -> h, h -> signedHttpRequest.firstMatchingHeader(h).map(Collections::singletonList).orElseGet(ArrayList::new)));
    boolean isBrowserExecutable = signedHttpRequest.method() == SdkHttpMethod.GET && signedPayload == null && (signedHeaders.isEmpty() || (signedHeaders.size() == 1 && signedHeaders.containsKey("host")));
    presignedRequest.expiration(execCtx.executionAttributes().getAttribute(PRESIGNER_EXPIRATION)).isBrowserExecutable(isBrowserExecutable).httpRequest(signedHttpRequest).signedHeaders(signedHeaders).signedPayload(signedPayload);
}
Also used : InterceptorContext(software.amazon.awssdk.core.interceptor.InterceptorContext) PutObjectPresignRequest(software.amazon.awssdk.services.s3.presigner.model.PutObjectPresignRequest) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) SdkBytes(software.amazon.awssdk.core.SdkBytes) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) PresignedPutObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) PutObjectRequest(software.amazon.awssdk.services.s3.model.PutObjectRequest) SdkClientOption(software.amazon.awssdk.core.client.config.SdkClientOption) URI(java.net.URI) Validate(software.amazon.awssdk.utils.Validate) PresignedGetObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest) PresignRequest(software.amazon.awssdk.awscore.presigner.PresignRequest) PresignedUploadPartRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedUploadPartRequest) PresignedRequest(software.amazon.awssdk.awscore.presigner.PresignedRequest) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) CompleteMultipartUploadRequest(software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest) PresignedCompleteMultipartUploadRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedCompleteMultipartUploadRequest) Instant(java.time.Instant) PutObjectRequestMarshaller(software.amazon.awssdk.services.s3.transform.PutObjectRequestMarshaller) UploadPartPresignRequest(software.amazon.awssdk.services.s3.presigner.model.UploadPartPresignRequest) List(java.util.List) Stream(java.util.stream.Stream) PresignedCreateMultipartUploadRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedCreateMultipartUploadRequest) Optional(java.util.Optional) S3Configuration(software.amazon.awssdk.services.s3.S3Configuration) SdkRequest(software.amazon.awssdk.core.SdkRequest) AbortMultipartUploadRequest(software.amazon.awssdk.services.s3.model.AbortMultipartUploadRequest) PRESIGNER_EXPIRATION(software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute.PRESIGNER_EXPIRATION) CollectionUtils.mergeLists(software.amazon.awssdk.utils.CollectionUtils.mergeLists) AbortMultipartUploadRequestMarshaller(software.amazon.awssdk.services.s3.transform.AbortMultipartUploadRequestMarshaller) ExecutionInterceptorChain(software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain) ClientType(software.amazon.awssdk.core.ClientType) ExecutionContext(software.amazon.awssdk.core.http.ExecutionContext) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) Function(java.util.function.Function) PresignedAbortMultipartUploadRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedAbortMultipartUploadRequest) FunctionalUtils.invokeSafely(software.amazon.awssdk.utils.FunctionalUtils.invokeSafely) ArrayList(java.util.ArrayList) S3Presigner(software.amazon.awssdk.services.s3.presigner.S3Presigner) Presigner(software.amazon.awssdk.core.signer.Presigner) ClasspathInterceptorChainFactory(software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory) GetObjectRequestMarshaller(software.amazon.awssdk.services.s3.transform.GetObjectRequestMarshaller) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkHttpMethod(software.amazon.awssdk.http.SdkHttpMethod) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) SdkDefaultClientBuilder(software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder) UploadPartRequestMarshaller(software.amazon.awssdk.services.s3.transform.UploadPartRequestMarshaller) CompleteMultipartUploadRequestMarshaller(software.amazon.awssdk.services.s3.transform.CompleteMultipartUploadRequestMarshaller) AwsSignerExecutionAttribute(software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute) UploadPartRequest(software.amazon.awssdk.services.s3.model.UploadPartRequest) SdkExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkExecutionAttribute) CreateMultipartUploadPresignRequest(software.amazon.awssdk.services.s3.presigner.model.CreateMultipartUploadPresignRequest) AwsExecutionContextBuilder(software.amazon.awssdk.awscore.internal.AwsExecutionContextBuilder) SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) Logger(software.amazon.awssdk.utils.Logger) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) CompleteMultipartUploadPresignRequest(software.amazon.awssdk.services.s3.presigner.model.CompleteMultipartUploadPresignRequest) GetObjectPresignRequest(software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest) AwsExecutionAttribute(software.amazon.awssdk.awscore.AwsExecutionAttribute) ContentStreamProvider(software.amazon.awssdk.http.ContentStreamProvider) AwsS3ProtocolFactory(software.amazon.awssdk.protocols.xml.AwsS3ProtocolFactory) AwsS3V4Signer(software.amazon.awssdk.auth.signer.AwsS3V4Signer) AbortMultipartUploadPresignRequest(software.amazon.awssdk.services.s3.presigner.model.AbortMultipartUploadPresignRequest) CreateMultipartUploadRequestMarshaller(software.amazon.awssdk.services.s3.transform.CreateMultipartUploadRequestMarshaller) AwsDefaultClientBuilder(software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder) DefaultServiceEndpointBuilder(software.amazon.awssdk.awscore.endpoint.DefaultServiceEndpointBuilder) RequestBody(software.amazon.awssdk.core.sync.RequestBody) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) CreateMultipartUploadRequest(software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest) Collections(java.util.Collections) IoUtils(software.amazon.awssdk.utils.IoUtils) SdkBytes(software.amazon.awssdk.core.SdkBytes) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with Presigner

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

the class DefaultPollyPresigner method presignRequest.

private SdkHttpFullRequest presignRequest(PollyRequest requestToPresign, SdkHttpFullRequest marshalledRequest, ExecutionAttributes executionAttributes) {
    Presigner presigner = resolvePresigner(requestToPresign);
    SdkHttpFullRequest presigned = presigner.presign(marshalledRequest, executionAttributes);
    List<String> signedHeadersQueryParam = presigned.firstMatchingRawQueryParameters("X-Amz-SignedHeaders");
    Validate.validState(!signedHeadersQueryParam.isEmpty(), "Only SigV4 presigners are supported at this time, but the configured " + "presigner (%s) did not seem to generate a SigV4 signature.", presigner);
    return presigned;
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) PollyPresigner(software.amazon.awssdk.services.polly.presigner.PollyPresigner) Presigner(software.amazon.awssdk.core.signer.Presigner)

Aggregations

Presigner (software.amazon.awssdk.core.signer.Presigner)2 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)2 URI (java.net.URI)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Stream (java.util.stream.Stream)1 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)1 AwsCredentials (software.amazon.awssdk.auth.credentials.AwsCredentials)1 AwsCredentialsProvider (software.amazon.awssdk.auth.credentials.AwsCredentialsProvider)1 AwsS3V4Signer (software.amazon.awssdk.auth.signer.AwsS3V4Signer)1 AwsSignerExecutionAttribute (software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute)1 PRESIGNER_EXPIRATION (software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute.PRESIGNER_EXPIRATION)1 AwsExecutionAttribute (software.amazon.awssdk.awscore.AwsExecutionAttribute)1 AwsDefaultClientBuilder (software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder)1