List of usage examples for com.amazonaws.services.s3.internal ServiceUtils formatRfc822Date
public static String formatRfc822Date(Date date)
From source file:com.emc.vipr.services.s3.ViPRS3Signer.java
License:Open Source License
@Override public void sign(Request<?> request, AWSCredentials credentials) throws AmazonClientException { if (credentials == null || credentials.getAWSSecretKey() == null) { log.debug("Canonical string will not be signed, as no AWS Secret Key was provided"); return;//from w ww . ja v a2 s.c om } AWSCredentials sanitizedCredentials = sanitizeCredentials(credentials); if (sanitizedCredentials instanceof AWSSessionCredentials) { addSessionCredentials(request, (AWSSessionCredentials) sanitizedCredentials); } /* * In s3 sigv2, the way slash characters are encoded should be * consistent in both the request url and the encoded resource path. * Since we have to encode "//" to "/%2F" in the request url to make * httpclient works, we need to do the same encoding here for the * resource path. */ String encodedResourcePath = HttpUtils.appendUri(request.getEndpoint().getPath(), resourcePath, true); Date date = getSignatureDate(request.getTimeOffset()); request.addHeader(Headers.DATE, ServiceUtils.formatRfc822Date(date)); String canonicalString = makeS3CanonicalString(httpVerb, encodedResourcePath, request, null); log.debug("Calculated string to sign:\n\"" + canonicalString + "\""); String signature = super.signAndBase64Encode(canonicalString, sanitizedCredentials.getAWSSecretKey(), SigningAlgorithm.HmacSHA1); request.addHeader("Authorization", "AWS " + sanitizedCredentials.getAWSAccessKeyId() + ":" + signature); }