Search in sources :

Example 91 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class PresignRequestHandlerTest method testSourceRegionRemovedFromOriginalRequest.

@Test
public void testSourceRegionRemovedFromOriginalRequest() {
    CopyDbClusterSnapshotRequest request = makeTestRequest();
    SdkHttpFullRequest marshalled = marshallRequest(request);
    SdkHttpRequest actual = modifyHttpRequest(presignInterceptor, request, marshalled);
    assertFalse(actual.rawQueryParameters().containsKey("SourceRegion"));
}
Also used : SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) CopyDbClusterSnapshotRequest(software.amazon.awssdk.services.neptune.model.CopyDbClusterSnapshotRequest) Test(org.junit.jupiter.api.Test)

Example 92 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class PresignRequestHandlerTest method testParsesDestinationRegionfromRequestEndpoint.

@Test
public void testParsesDestinationRegionfromRequestEndpoint() throws URISyntaxException {
    CopyDbClusterSnapshotRequest request = CopyDbClusterSnapshotRequest.builder().sourceRegion("us-east-1").build();
    Region destination = Region.of("us-west-2");
    SdkHttpFullRequest marshalled = marshallRequest(request);
    final SdkHttpRequest presignedRequest = modifyHttpRequest(presignInterceptor, request, marshalled);
    final URI presignedUrl = new URI(presignedRequest.rawQueryParameters().get("PreSignedUrl").get(0));
    assertTrue(presignedUrl.toString().contains("DestinationRegion=" + destination.id()));
}
Also used : SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) CopyDbClusterSnapshotRequest(software.amazon.awssdk.services.neptune.model.CopyDbClusterSnapshotRequest) Region(software.amazon.awssdk.regions.Region) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 93 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class DefaultPollyPresigner method presign.

/**
 * Generate a {@link PresignedRequest} from a {@link PresignedRequest} and {@link PollyRequest}.
 */
private <T extends PresignedRequest.Builder, U extends PollyRequest> T presign(T presignedRequest, PresignRequest presignRequest, U requestToPresign, Function<U, SdkHttpFullRequest.Builder> requestMarshaller) {
    ExecutionAttributes execAttrs = createExecutionAttributes(presignRequest, requestToPresign);
    SdkHttpFullRequest marshalledRequest = marshallRequest(requestToPresign, requestMarshaller);
    SdkHttpFullRequest signedHttpRequest = presignRequest(requestToPresign, marshalledRequest, execAttrs);
    initializePresignedRequest(presignedRequest, execAttrs, signedHttpRequest);
    return presignedRequest;
}
Also used : ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest)

Example 94 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest 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.rawQueryParameters().get("X-Amz-SignedHeaders");
    Validate.validState(signedHeadersQueryParam != null, "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)

Example 95 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class DefaultRdsUtilities method generateAuthenticationToken.

@Override
public String generateAuthenticationToken(GenerateAuthenticationTokenRequest request) {
    SdkHttpFullRequest httpRequest = SdkHttpFullRequest.builder().method(SdkHttpMethod.GET).protocol("https").host(request.hostname()).port(request.port()).encodedPath("/").putRawQueryParameter("DBUser", request.username()).putRawQueryParameter("Action", "connect").build();
    Instant expirationTime = Instant.now(clock).plus(EXPIRATION_DURATION);
    Aws4PresignerParams presignRequest = Aws4PresignerParams.builder().signingClockOverride(clock).expirationTime(expirationTime).awsCredentials(resolveCredentials(request).resolveCredentials()).signingName("rds-db").signingRegion(resolveRegion(request)).build();
    SdkHttpFullRequest fullRequest = signer.presign(httpRequest, presignRequest);
    String signedUrl = fullRequest.getUri().toString();
    // Note: This must be the real RDS hostname, not proxy or tunnels
    return StringUtils.replacePrefixIgnoreCase(signedUrl, "https://", "");
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Instant(java.time.Instant) Aws4PresignerParams(software.amazon.awssdk.auth.signer.params.Aws4PresignerParams)

Aggregations

SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)178 Test (org.junit.Test)70 Test (org.junit.jupiter.api.Test)50 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)43 URI (java.net.URI)25 SigningTestCase (software.amazon.awssdk.authcrt.signer.SigningTestCase)23 ByteArrayInputStream (java.io.ByteArrayInputStream)18 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)16 List (java.util.List)13 AwsCredentials (software.amazon.awssdk.auth.credentials.AwsCredentials)13 RequestExecutionContext (software.amazon.awssdk.core.internal.http.RequestExecutionContext)12 ByteBuffer (java.nio.ByteBuffer)11 AsyncRequestBody (software.amazon.awssdk.core.async.AsyncRequestBody)11 Map (java.util.Map)10 ContentStreamProvider (software.amazon.awssdk.http.ContentStreamProvider)10 Instant (java.time.Instant)9 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)9 Aws4SignerParams (software.amazon.awssdk.auth.signer.params.Aws4SignerParams)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8