Example usage for com.amazonaws.services.cloudfront CloudFrontUrlSigner getSignedURLWithCannedPolicy

List of usage examples for com.amazonaws.services.cloudfront CloudFrontUrlSigner getSignedURLWithCannedPolicy

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudfront CloudFrontUrlSigner getSignedURLWithCannedPolicy.

Prototype

public static String getSignedURLWithCannedPolicy(String resourceUrlOrPath, String keyPairId,
        PrivateKey privateKey, Date dateLessThan) 

Source Link

Document

Generate a signed URL that allows access to a specific distribution and S3 object by applying a access restrictions from a "canned" (simplified) policy document.

Usage

From source file:org.nuxeo.ecm.core.storage.sql.CloudFrontBinaryManager.java

License:Apache License

@Override
protected URI getRemoteUri(String digest, ManagedBlob blob, HttpServletRequest servletRequest)
        throws IOException {
    try {//from   w  ww.ja  v a2  s.  c o  m
        URIBuilder uriBuilder = new URIBuilder(buildResourcePath(bucketNamePrefix + digest));
        if (blob != null) {
            uriBuilder.addParameter("response-content-type", getContentTypeHeader(blob));
            uriBuilder.addParameter("response-content-disposition",
                    getContentDispositionHeader(blob, servletRequest));
        }

        if (isBooleanPropertyTrue(ENABLE_CF_ENCODING_FIX)) {
            String trimmedChars = " ";
            uriBuilder.getQueryParams().stream().filter(s -> s.getValue().contains(trimmedChars))
                    .forEach(s -> uriBuilder.setParameter(s.getName(), s.getValue().replace(trimmedChars, "")));
        }

        URI uri = uriBuilder.build();
        if (privKey == null) {
            return uri;
        }

        Date expiration = new Date();
        expiration.setTime(expiration.getTime() + directDownloadExpire * 1000);

        String signedURL = CloudFrontUrlSigner.getSignedURLWithCannedPolicy(uri.toString(), privKeyId, privKey,
                expiration);
        return new URI(signedURL);
    } catch (URISyntaxException e) {
        throw new IOException(e);
    }
}