List of usage examples for com.amazonaws.services.s3.model CannedAccessControlList Private
CannedAccessControlList Private
To view the source code for com.amazonaws.services.s3.model CannedAccessControlList Private.
Click Source Link
From source file:cloudExplorer.Acl.java
License:Open Source License
void setACLprivate(String object, String access_key, String secret_key, String endpoint, String bucket) { try {/*from ww w. j av a2s . com*/ AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration().withSignerOverride("S3SignerType")); s3Client.setEndpoint(endpoint); s3Client.setObjectAcl(bucket, object, CannedAccessControlList.Private); } catch (Exception setACLprivate) { mainFrame.jTextArea1.append("\nException occurred in setACLprivate"); } }
From source file:com.allogy.build.maven.S3Wagon.java
License:Apache License
@Override protected CannedAccessControlList getAclFromRepository(Repository repository) { return CannedAccessControlList.Private; }
From source file:com.athena.dolly.web.aws.s3.S3Service.java
License:Open Source License
/** * Change object ACL to private/*from w w w .j a va 2 s . c om*/ * @param bucketName * @param key */ public void changeAclToPrivate(String bucketName, String key) { s3.setObjectAcl(bucketName, key, CannedAccessControlList.Private); }
From source file:com.eucalyptus.objectstorage.providers.s3.S3ProviderClient.java
License:Open Source License
@Override public PutObjectResponseType putObject(PutObjectType request, InputStream inputData) throws S3Exception { User requestUser = getRequestUser(request); OsgInternalS3Client internalS3Client = null; try {//from w w w. ja v a2s . c o m internalS3Client = getS3Client(requestUser); AmazonS3Client s3Client = internalS3Client.getS3Client(); PutObjectResult result; ObjectMetadata metadata = getS3ObjectMetadata(request); //Set the acl to private. PutObjectRequest putRequest = new PutObjectRequest(request.getBucket(), request.getKey(), inputData, metadata).withCannedAcl(CannedAccessControlList.Private); result = s3Client.putObject(putRequest); PutObjectResponseType reply = request.getReply(); if (result == null) { throw new InternalErrorException("Null result from backend"); } else { reply.setEtag(result.getETag()); reply.setVersionId(result.getVersionId()); reply.setLastModified(new Date()); } return reply; } catch (AmazonServiceException e) { LOG.debug("Error from backend", e); throw S3ExceptionMapper.fromAWSJavaSDK(e); } }
From source file:com.mindtree.maven.S3Mojo.java
License:Apache License
private void createBucketAndUploadFiles() throws MojoExecutionException { for (int i = 0; i < bucketNames.length; i++) { String path = bucketNames[i]; int index = path.indexOf("/"); logger.debug("Got index of / : " + index); logger.debug("Trying upload for files with path : " + path); // The path to upload can have subdirectories hence only the first // directory (root) is required String rootBucket = path; if (index == 0) { logger.debug("Unique name bucket creation is required"); rootBucket = UNIQUE;/*from ww w. ja v a 2s. co m*/ } else if (index != -1) { logger.debug("Given name bucket creation is required"); rootBucket = rootBucket.substring(0, index); } Bucket bucket = createS3Bucket(rootBucket); if (bucket != null) { List<File> fileList = mapFiles.get(path); logger.debug("Got fileList as null :: " + (fileList == null)); if (fileList != null) { logger.debug("Size of fileList :" + fileList.size()); } CannedAccessControlList cacl = CannedAccessControlList.Private; if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.AuthenticatedRead.toString())) { cacl = CannedAccessControlList.AuthenticatedRead; } else if (accessControls[i] .equalsIgnoreCase(CannedAccessControlList.BucketOwnerFullControl.toString())) { cacl = CannedAccessControlList.BucketOwnerFullControl; } else if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.BucketOwnerRead.toString())) { cacl = CannedAccessControlList.BucketOwnerRead; } else if (accessControls[i] .equalsIgnoreCase(CannedAccessControlList.LogDeliveryWrite.toString())) { cacl = CannedAccessControlList.LogDeliveryWrite; } else if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.Private.toString())) { cacl = CannedAccessControlList.Private; } else if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.PublicRead.toString())) { cacl = CannedAccessControlList.PublicRead; } else if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.PublicReadWrite.toString())) { cacl = CannedAccessControlList.PublicReadWrite; } String bucketName = bucket.getName() + bucketNames[i].substring(bucketNames[i].indexOf("/")); logger.debug("File to upload to :" + bucketName); if (fileList != null && fileList.size() > 0) { if (!retainFolderStructure) { logger.debug("Not retaining folder structure and uploadinf files"); System.out.println(cacl.toString()); List<PutObjectResult> fileUploadResults = S3Helper.uploadFiles(fileList, bucketName, s3, cacl); } else { logger.debug("Uploading with retained dir structure"); List<PutObjectResult> fileUploadResults = S3Helper.uploadFiles(fileList, bucketName, s3, cacl, root); } } } } }
From source file:com.zero_x_baadf00d.play.module.aws.s3.ebean.BaseS3FileModel.java
License:Open Source License
/** * Save the current object. The file will be uploaded to PlayS3 bucket. * * @since 16.03.13//from w ww . j a v a 2s . co m */ @Override public void save() { if (this.id == null) { this.id = Generators.timeBasedGenerator().generate(); } if (!PlayS3.isReady()) { Logger.error("Could not save PlayS3 file because amazonS3 variable is null"); throw new RuntimeException("Could not save"); } else { this.bucket = PlayS3.getBucketName(); if (this.subDirectory == null) { this.subDirectory = ""; } this.subDirectory = this.subDirectory.trim(); // Set cache control and server side encryption final ObjectMetadata objMetaData = new ObjectMetadata(); objMetaData.setContentType(this.contentType); objMetaData.setCacheControl("max-age=315360000, public"); objMetaData.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); try { objMetaData.setContentLength(this.objectData.available()); } catch (final IOException ex) { Logger.warn("Can't retrieve stream available size", ex); } finally { try { if (this.objectData.markSupported()) { this.objectData.reset(); } } catch (final IOException ex) { Logger.error("Can't reset stream position", ex); } } // Upload file to PlayS3 final PutObjectRequest putObjectRequest = new PutObjectRequest(this.bucket, this.getActualFileName(), this.objectData, objMetaData); putObjectRequest.withCannedAcl( this.isPrivate ? CannedAccessControlList.Private : CannedAccessControlList.PublicRead); PlayS3.getAmazonS3().putObject(putObjectRequest); try { if (this.objectData != null) { this.objectData.close(); } } catch (final IOException ignore) { } // Save object on database super.save(); } }
From source file:org.alanwilliamson.amazon.AmazonKey.java
License:Open Source License
/** * private | public-read | public-read-write | authenticated-read | bucket-owner-read | bucket-owner-full-control | log-delivery-write * * @param acl/*from w ww .j a v a 2s. com*/ * @return */ public CannedAccessControlList getAmazonCannedAcl(String acl) { if (acl.equalsIgnoreCase("private")) return CannedAccessControlList.Private; else if (acl.equalsIgnoreCase("public-read") || acl.equalsIgnoreCase("publicread")) return CannedAccessControlList.PublicRead; else if (acl.equalsIgnoreCase("public-read-write") || acl.equalsIgnoreCase("publicreadwrite")) return CannedAccessControlList.PublicReadWrite; else if (acl.equalsIgnoreCase("authenticated-read") || acl.equalsIgnoreCase("authenticatedread")) return CannedAccessControlList.AuthenticatedRead; else if (acl.equalsIgnoreCase("bucket-owner-read") || acl.equalsIgnoreCase("bucketownerread")) return CannedAccessControlList.BucketOwnerRead; else if (acl.equalsIgnoreCase("bucket-owner-full-control") || acl.equalsIgnoreCase("bucketownerfullcontrol")) return CannedAccessControlList.BucketOwnerFullControl; else if (acl.equalsIgnoreCase("log-delivery-write") || acl.equalsIgnoreCase("logdeliverywrite")) return CannedAccessControlList.LogDeliveryWrite; else return CannedAccessControlList.Private; }
From source file:org.duracloud.s3storage.S3StorageProvider.java
License:Apache License
/** * Adds content to a hidden space./*from ww w . j av a 2 s. c o m*/ * * @param spaceId hidden spaceId * @param contentId * @param contentMimeType * @param content * @return */ public String addHiddenContent(String spaceId, String contentId, String contentMimeType, InputStream content) { log.debug("addHiddenContent(" + spaceId + ", " + contentId + ", " + contentMimeType + ")"); // Will throw if bucket does not exist String bucketName = getBucketName(spaceId); // Wrap the content in order to be able to retrieve a checksum if (contentMimeType == null || contentMimeType.equals("")) { contentMimeType = DEFAULT_MIMETYPE; } ObjectMetadata objMetadata = new ObjectMetadata(); objMetadata.setContentType(contentMimeType); PutObjectRequest putRequest = new PutObjectRequest(bucketName, contentId, content, objMetadata); putRequest.setStorageClass(DEFAULT_STORAGE_CLASS); putRequest.setCannedAcl(CannedAccessControlList.Private); try { PutObjectResult putResult = s3Client.putObject(putRequest); return putResult.getETag(); } catch (AmazonClientException e) { String err = "Could not add content " + contentId + " with type " + contentMimeType + " to S3 bucket " + bucketName + " due to error: " + e.getMessage(); throw new StorageException(err, e, NO_RETRY); } }
From source file:org.duracloud.s3storage.S3StorageProvider.java
License:Apache License
/** * {@inheritDoc}//from w ww .j a v a 2 s . com */ public String addContent(String spaceId, String contentId, String contentMimeType, Map<String, String> userProperties, long contentSize, String contentChecksum, InputStream content) { log.debug("addContent(" + spaceId + ", " + contentId + ", " + contentMimeType + ", " + contentSize + ", " + contentChecksum + ")"); // Will throw if bucket does not exist String bucketName = getBucketName(spaceId); // Wrap the content in order to be able to retrieve a checksum ChecksumInputStream wrappedContent = new ChecksumInputStream(content, contentChecksum); String contentEncoding = removeContentEncoding(userProperties); userProperties = removeCalculatedProperties(userProperties); if (contentMimeType == null || contentMimeType.equals("")) { contentMimeType = DEFAULT_MIMETYPE; } ObjectMetadata objMetadata = new ObjectMetadata(); objMetadata.setContentType(contentMimeType); if (contentSize > 0) { objMetadata.setContentLength(contentSize); } if (null != contentChecksum && !contentChecksum.isEmpty()) { String encodedChecksum = ChecksumUtil.convertToBase64Encoding(contentChecksum); objMetadata.setContentMD5(encodedChecksum); } if (contentEncoding != null) { objMetadata.setContentEncoding(contentEncoding); } if (userProperties != null) { for (String key : userProperties.keySet()) { String value = userProperties.get(key); if (log.isDebugEnabled()) { log.debug("[" + key + "|" + value + "]"); } objMetadata.addUserMetadata(getSpaceFree(encodeHeaderKey(key)), encodeHeaderValue(value)); } } PutObjectRequest putRequest = new PutObjectRequest(bucketName, contentId, wrappedContent, objMetadata); putRequest.setStorageClass(DEFAULT_STORAGE_CLASS); putRequest.setCannedAcl(CannedAccessControlList.Private); // Add the object String etag; try { PutObjectResult putResult = s3Client.putObject(putRequest); etag = putResult.getETag(); } catch (AmazonClientException e) { if (e instanceof AmazonS3Exception) { AmazonS3Exception s3Ex = (AmazonS3Exception) e; String errorCode = s3Ex.getErrorCode(); Integer statusCode = s3Ex.getStatusCode(); String message = MessageFormat.format( "exception putting object {0} into {1}: errorCode={2}," + " statusCode={3}, errorMessage={4}", contentId, bucketName, errorCode, statusCode, e.getMessage()); if (errorCode.equals("InvalidDigest") || errorCode.equals("BadDigest")) { log.error(message, e); String err = "Checksum mismatch detected attempting to add " + "content " + contentId + " to S3 bucket " + bucketName + ". Content was not added."; throw new ChecksumMismatchException(err, e, NO_RETRY); } else if (errorCode.equals("IncompleteBody")) { log.error(message, e); throw new StorageException("The content body was incomplete for " + contentId + " to S3 bucket " + bucketName + ". Content was not added.", e, NO_RETRY); } else if (!statusCode.equals(HttpStatus.SC_SERVICE_UNAVAILABLE) && !statusCode.equals(HttpStatus.SC_NOT_FOUND)) { log.error(message, e); } else { log.warn(message, e); } } else { String err = MessageFormat.format("exception putting object {0} into {1}: {2}", contentId, bucketName, e.getMessage()); log.error(err, e); } // Check to see if file landed successfully in S3, despite the exception etag = doesContentExistWithExpectedChecksum(bucketName, contentId, contentChecksum); if (null == etag) { String err = "Could not add content " + contentId + " with type " + contentMimeType + " and size " + contentSize + " to S3 bucket " + bucketName + " due to error: " + e.getMessage(); throw new StorageException(err, e, NO_RETRY); } } // Compare checksum String providerChecksum = getETagValue(etag); String checksum = wrappedContent.getMD5(); StorageProviderUtil.compareChecksum(providerChecksum, spaceId, contentId, checksum); return providerChecksum; }
From source file:org.duracloud.s3storage.S3StorageProvider.java
License:Apache License
@Override public String copyContent(String sourceSpaceId, String sourceContentId, String destSpaceId, String destContentId) {//from ww w . j a v a 2 s. c o m log.debug("copyContent({}, {}, {}, {})", sourceSpaceId, sourceContentId, destSpaceId, destContentId); // Will throw if source bucket does not exist String sourceBucketName = getBucketName(sourceSpaceId); // Will throw if destination bucket does not exist String destBucketName = getBucketName(destSpaceId); throwIfContentNotExist(sourceBucketName, sourceContentId); CopyObjectRequest request = new CopyObjectRequest(sourceBucketName, sourceContentId, destBucketName, destContentId); request.setStorageClass(DEFAULT_STORAGE_CLASS); request.setCannedAccessControlList(CannedAccessControlList.Private); CopyObjectResult result = doCopyObject(request); return StorageProviderUtil.compareChecksum(this, sourceSpaceId, sourceContentId, result.getETag()); }