use of software.amazon.awssdk.http.SdkHttpFullRequest in project engine by Lumeer.
the class LumeerS3Client method presign.
private static URI presign(final PresignUrlRequest request) {
String encodedBucket, encodedKey;
try {
encodedBucket = URLEncoder.encode(request.bucket(), "UTF-8");
encodedKey = URLEncoder.encode(request.key(), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new UncheckedIOException(e);
}
SdkHttpFullRequest httpRequest = SdkHttpFullRequest.builder().method(request.httpMethod()).protocol("https").host(encodedBucket + "." + request.region().id() + "." + request.endpoint()).encodedPath(request.key()).build();
Instant expirationTime = request.signatureDuration() == null ? null : Instant.now().plus(request.signatureDuration());
Aws4PresignerParams presignRequest = Aws4PresignerParams.builder().expirationTime(expirationTime).awsCredentials(request.credentialsProvider().resolveCredentials()).signingName(software.amazon.awssdk.services.s3.S3Client.SERVICE_NAME).signingRegion(request.region()).build();
return AwsS3V4Signer.create().presign(httpRequest, presignRequest).getUri();
}
use of software.amazon.awssdk.http.SdkHttpFullRequest in project hibernate-search by hibernate.
the class AwsSigningRequestInterceptor method sign.
private void sign(HttpRequest request, HttpContext context, HttpEntityContentStreamProvider contentStreamProvider) {
SdkHttpFullRequest awsRequest = toAwsRequest(request, context, contentStreamProvider);
if (log.isTraceEnabled()) {
log.tracef("HTTP request (before signing): %s", request);
log.tracef("AWS request (before signing): %s", awsRequest);
}
AwsCredentials credentials = credentialsProvider.resolveCredentials();
log.tracef("AWS credentials: %s", credentials);
Aws4SignerParams signerParams = Aws4SignerParams.builder().awsCredentials(credentials).signingRegion(region).signingName(ELASTICSEARCH_SERVICE_NAME).build();
awsRequest = signer.sign(awsRequest, signerParams);
// We don't expect signing to affect anything else (path, query, content, ...).
for (Map.Entry<String, List<String>> header : awsRequest.headers().entrySet()) {
String name = header.getKey();
boolean first = true;
for (String value : header.getValue()) {
if (first) {
request.setHeader(name, value);
first = false;
} else {
request.addHeader(name, value);
}
}
}
if (log.isTraceEnabled()) {
log.tracef("AWS request (after signing): %s", awsRequest);
log.tracef("HTTP request (after signing): %s", request);
}
}
use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.
the class AwsCrtV4aSignerTest method testQuerySigning.
@Test
public void testQuerySigning() {
SigningTestCase testCase = SignerTestUtils.createBasicQuerySigningTestCase();
ExecutionAttributes executionAttributes = SignerTestUtils.buildBasicExecutionAttributes(testCase);
SdkHttpFullRequest request = testCase.requestBuilder.build();
SdkHttpFullRequest signed = v4aSigner.presign(request, executionAttributes);
List<String> signatureValues = signed.rawQueryParameters().get("X-Amz-Signature");
String signatureValue = signatureValues.get(0);
List<String> regionHeader = signed.rawQueryParameters().get("X-Amz-Region-Set");
assertThat(regionHeader.get(0)).isEqualTo(Region.AWS_GLOBAL.id());
AwsSigningConfig signingConfig = configProvider.createCrtPresigningConfig(executionAttributes);
assertTrue(SignerTestUtils.verifyEcdsaSignature(request, testCase.expectedCanonicalRequest, signingConfig, signatureValue));
}
use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.
the class AwsCrt4aSigningAdapterTest method sign_forHeader_works.
@Test
void sign_forHeader_works() {
SigningTestCase testCase = SignerTestUtils.createBasicHeaderSigningTestCase();
ExecutionAttributes executionAttributes = SignerTestUtils.buildBasicExecutionAttributes(testCase);
SdkHttpFullRequest request = testCase.requestBuilder.build();
AwsSigningConfig signingConfig = configProvider.createCrtSigningConfig(executionAttributes);
SdkSigningResult signed = crtSigningAdapter.sign(request, signingConfig);
SdkHttpFullRequest signedRequest = signed.getSignedRequest();
String signatureValue = extractSignatureFromAuthHeader(signedRequest);
assertTrue(SignerTestUtils.verifyEcdsaSignature(request, testCase.expectedCanonicalRequest, signingConfig, signatureValue));
}
use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.
the class AwsCrt4aSigningAdapterTest method signRequest_forHeader_works.
@Test
public void signRequest_forHeader_works() {
SigningTestCase testCase = SignerTestUtils.createBasicHeaderSigningTestCase();
ExecutionAttributes executionAttributes = SignerTestUtils.buildBasicExecutionAttributes(testCase);
SdkHttpFullRequest request = testCase.requestBuilder.build();
AwsSigningConfig signingConfig = configProvider.createCrtSigningConfig(executionAttributes);
SdkHttpFullRequest signed = crtSigningAdapter.signRequest(request, signingConfig);
String signatureValue = extractSignatureFromAuthHeader(signed);
assertTrue(SignerTestUtils.verifyEcdsaSignature(request, testCase.expectedCanonicalRequest, signingConfig, signatureValue));
}
Aggregations