use of com.amazonaws.services.s3.internal.S3Signer in project aws-sdk-android by aws-amplify.
the class S3SignerTest method testSign.
@Ignore
@Test
public void testSign() throws URISyntaxException {
final GetObjectRequest gr = new GetObjectRequest("test-bucket123456", "TestFile.txt");
final Request<?> req = new DefaultRequest(gr, Constants.S3_SERVICE_DISPLAY_NAME);
req.setHttpMethod(HttpMethodName.GET);
req.setResourcePath("/test-bucket123456/TestFile.txt");
req.setEndpoint(new URI("https://test-bucket123456.s3-us-west-2.amazonaws.com"));
req.addHeader(Headers.CONTENT_TYPE, "application/x-www-form-urlencoded; charset=utf-8");
final S3Signer signer = new S3Signer("GET", "/test-bucket123456/TestFile.txt");
// These are fake bogus credentials just for tesitng
signer.sign(req, new BasicAWSCredentials("AKI11BOGUS11ACCESS11KEYOZQ", "LYd/ZD611BOGUS11SECRET11KEYSiD6"), new Date(1431374979760L));
assertEquals(getSignature(req), "kD6n4rzH5+82Nw5wFIhaD1pKXNM=");
}
use of com.amazonaws.services.s3.internal.S3Signer in project aws-sdk-android by aws-amplify.
the class AmazonS3Client method createSigner.
/**
* Returns a "complete" S3 specific signer, taking into the S3 bucket, key,
* and the current S3 client configuration into account.
*
* Signer = get a Signer based on the bucket endpoint // InternalConfig in CoreRuntime makes this decision
* [If the region is not specified, uses SigV2 signer,
* Else If the region is specified, and If the region only supports SigV4, then uses SigV4]
* If Signer is not Overriden {
* If Signer is a V4 Signer and Region is null
* Get the region from AmazonS3Client or BucketRegionCache
* If available
* Use SigV4
* Else If PresignedUrl
* Use SigV2
* If Signer Region is overriden
* Use SigV4
* If BucketRegionCache has a region
* Use SigV4
* }
*
* If Signer is SigV2 signer
* Use SigV2
*/
protected Signer createSigner(final Request<?> request, final String bucketName, final String key) {
// Instead of using request.getEndpoint() for this parameter, we use
// endpoint which is because
// in accelerate mode, the endpoint in request is regionless. We need
// the client-wide endpoint
// to fetch the region information and pick the correct signer.
final URI uri = clientOptions.isAccelerateModeEnabled() ? endpoint : request.getEndpoint();
// This method retrieves the signer based on the URI. Currently
// S3's default signer is a SigV2 signer implemented in S3Signer
final Signer signer = getSignerByURI(uri);
if (!isSignerOverridden()) {
if ((signer instanceof AWSS3V4Signer) && noExplicitRegionProvided(request)) {
final String region = clientRegion == null ? bucketRegionCache.get(bucketName) : clientRegion;
if (region != null) {
// If cache contains the region for the bucket, create an endpoint for the region and
// update the request with that endpoint.
resolveRequestEndpoint(request, bucketName, key, RuntimeHttpUtils.toUri(RegionUtils.getRegion(region).getServiceEndpoint(S3_SERVICE_NAME), clientConfiguration));
AWSS3V4Signer sigV4Signer = (AWSS3V4Signer) signer;
setAWSS3V4SignerWithServiceNameAndRegion((AWSS3V4Signer) signer, region);
return sigV4Signer;
} else if (request.getOriginalRequest() instanceof GeneratePresignedUrlRequest) {
return createSigV2Signer(request, bucketName, key);
}
}
// use the signer override if provided, else see if you can get the
// signer from bucketreqion cache.
final String regionOverride = getSignerRegionOverride() == null ? (clientRegion == null ? bucketRegionCache.get(bucketName) : clientRegion) : getSignerRegionOverride();
if (regionOverride != null) {
AWSS3V4Signer sigV4Signer = new AWSS3V4Signer();
setAWSS3V4SignerWithServiceNameAndRegion(sigV4Signer, regionOverride);
return sigV4Signer;
}
}
if (signer instanceof S3Signer) {
// new one with the appropriate values for this request.
return createSigV2Signer(request, bucketName, key);
}
return signer;
}
Aggregations