List of usage examples for com.amazonaws.services.s3.model ObjectMetadata AES_256_SERVER_SIDE_ENCRYPTION
String AES_256_SERVER_SIDE_ENCRYPTION
To view the source code for com.amazonaws.services.s3.model ObjectMetadata AES_256_SERVER_SIDE_ENCRYPTION.
Click Source Link
From source file:com.pinterest.secor.uploader.S3UploadManager.java
License:Apache License
private void enableS3Encryption(PutObjectRequest uploadRequest) { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); uploadRequest.setMetadata(objectMetadata); }
From source file:com.universal.storage.UniversalS3Storage.java
License:Open Source License
/** * This method uploads a file with a length greater than PART_SIZE (5Mb). * /* w ww . j a va2 s. c om*/ * @param file to be stored within the storage. * @param path is the path for this new file within the root. * @throws UniversalIOException when a specific IO error occurs. */ private void uploadFile(File file, String path) throws UniversalIOException { // Create a list of UploadPartResponse objects. You get one of these // for each part upload. List<PartETag> partETags = new ArrayList<PartETag>(); // Step 1: Initialize. InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(this.settings.getRoot(), file.getName()); InitiateMultipartUploadResult initResponse = this.s3client.initiateMultipartUpload(initRequest); long contentLength = file.length(); long partSize = PART_SIZE; // Set part size to 5 MB. ObjectMetadata objectMetadata = new ObjectMetadata(); if (this.settings.getEncryption()) { objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); } List<Tag> tags = new ArrayList<Tag>(); for (String key : this.settings.getTags().keySet()) { tags.add(new Tag(key, this.settings.getTags().get(key))); } try { this.triggerOnStoreFileListeners(); // Step 2: Upload parts. long filePosition = 0; for (int i = 1; filePosition < contentLength; i++) { // Last part can be less than 5 MB. Adjust part size. partSize = Math.min(partSize, (contentLength - filePosition)); // Create request to upload a part. UploadPartRequest uploadRequest = new UploadPartRequest() .withBucketName(this.settings.getRoot() + ("".equals(path) ? "" : ("/" + path))) .withKey(file.getName()).withUploadId(initResponse.getUploadId()).withPartNumber(i) .withFileOffset(filePosition).withFile(file).withObjectMetadata(objectMetadata) .withPartSize(partSize); // Upload part and add response to our list. partETags.add(this.s3client.uploadPart(uploadRequest).getPartETag()); filePosition += partSize; } // Step 3: Complete. CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest( this.settings.getRoot() + ("".equals(path) ? "" : ("/" + path)), file.getName(), initResponse.getUploadId(), partETags); CompleteMultipartUploadResult result = this.s3client.completeMultipartUpload(compRequest); StorageClass storageClass = getStorageClass(); if (storageClass != StorageClass.Standard) { CopyObjectRequest copyObjectRequest = new CopyObjectRequest(this.settings.getRoot(), file.getName(), this.settings.getRoot(), file.getName()).withStorageClass(storageClass); this.s3client.copyObject(copyObjectRequest); } if (!tags.isEmpty()) { this.s3client.setObjectTagging(new SetObjectTaggingRequest(this.settings.getRoot(), file.getName(), new ObjectTagging(tags))); } this.triggerOnFileStoredListeners(new UniversalStorageData(file.getName(), PREFIX_S3_URL + (this.settings.getRoot() + ("".equals(path) ? "" : ("/" + path))) + "/" + file.getName(), result.getVersionId(), this.settings.getRoot() + ("".equals(path) ? "" : ("/" + path)))); } catch (Exception e) { this.s3client.abortMultipartUpload(new AbortMultipartUploadRequest(this.settings.getRoot(), file.getName(), initResponse.getUploadId())); UniversalIOException error = new UniversalIOException(e.getMessage()); this.triggerOnErrorListeners(error); throw error; } }
From source file:com.universal.storage.UniversalS3Storage.java
License:Open Source License
/** * This method uploads a file with a length lesser than PART_SIZE (5Mb). * /*from www. j a va 2 s. co m*/ * @param file to be stored within the storage. * @param path is the path for this new file within the root. * @throws UniversalIOException when a specific IO error occurs. */ private void uploadTinyFile(File file, String path) throws UniversalIOException { try { ObjectMetadata objectMetadata = new ObjectMetadata(); if (this.settings.getEncryption()) { objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); } List<Tag> tags = new ArrayList<Tag>(); for (String key : this.settings.getTags().keySet()) { tags.add(new Tag(key, this.settings.getTags().get(key))); } PutObjectRequest request = new PutObjectRequest( this.settings.getRoot() + ("".equals(path) ? "" : ("/" + path)), file.getName(), file); request.setMetadata(objectMetadata); request.setTagging(new ObjectTagging(tags)); request.setStorageClass(getStorageClass()); this.triggerOnStoreFileListeners(); PutObjectResult result = this.s3client.putObject(request); this.triggerOnFileStoredListeners(new UniversalStorageData(file.getName(), PREFIX_S3_URL + (this.settings.getRoot() + ("".equals(path) ? "" : ("/" + path))) + "/" + file.getName(), result.getVersionId(), this.settings.getRoot() + ("".equals(path) ? "" : ("/" + path)))); } catch (Exception e) { UniversalIOException error = new UniversalIOException(e.getMessage()); this.triggerOnErrorListeners(error); throw error; } }
From source file:com.upplication.s3fs.util.S3UploadRequest.java
License:Open Source License
public S3UploadRequest setStorageEncryption(String storageEncryption) { if (storageEncryption == null) { return this; } else if (!"AES256".equals(storageEncryption)) { log.warn("Not a valid S3 server-side encryption type: `{}` -- Currently only AES256 is supported", storageEncryption);//w w w .j av a2 s. c om } else { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); this.setMetadata(objectMetadata); } return this; }
From source file:com.yahoo.ycsb.db.S3Client.java
License:Open Source License
/** * Upload a new object to S3 or update an object on S3. * * @param bucket/*from w w w . ja va2s . co m*/ * The name of the bucket * @param key * The file key of the object to upload/update. * @param values * The data to be written on the object * @param updateMarker * A boolean value. If true a new object will be uploaded * to S3. If false an existing object will be re-uploaded * */ protected Status writeToStorage(String bucket, String key, HashMap<String, ByteIterator> values, Boolean updateMarker, String sseLocal, SSECustomerKey ssecLocal) { int totalSize = 0; int fieldCount = values.size(); //number of fields to concatenate // getting the first field in the values Object keyToSearch = values.keySet().toArray()[0]; // getting the content of just one field byte[] sourceArray = values.get(keyToSearch).toArray(); int sizeArray = sourceArray.length; //size of each array if (updateMarker) { totalSize = sizeArray * fieldCount; } else { try { Map.Entry<S3Object, ObjectMetadata> objectAndMetadata = getS3ObjectAndMetadata(bucket, key, ssecLocal); int sizeOfFile = (int) objectAndMetadata.getValue().getContentLength(); fieldCount = sizeOfFile / sizeArray; totalSize = sizeOfFile; objectAndMetadata.getKey().close(); } catch (Exception e) { System.err.println("Not possible to get the object :" + key); e.printStackTrace(); return Status.ERROR; } } byte[] destinationArray = new byte[totalSize]; int offset = 0; for (int i = 0; i < fieldCount; i++) { System.arraycopy(sourceArray, 0, destinationArray, offset, sizeArray); offset += sizeArray; } try (InputStream input = new ByteArrayInputStream(destinationArray)) { ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(totalSize); PutObjectRequest putObjectRequest = null; if (sseLocal.equals("true")) { metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); putObjectRequest = new PutObjectRequest(bucket, key, input, metadata); } else if (ssecLocal != null) { putObjectRequest = new PutObjectRequest(bucket, key, input, metadata).withSSECustomerKey(ssecLocal); } else { putObjectRequest = new PutObjectRequest(bucket, key, input, metadata); } try { PutObjectResult res = s3Client.putObject(putObjectRequest); if (res.getETag() == null) { return Status.ERROR; } else { if (sseLocal.equals("true")) { System.out.println("Uploaded object encryption status is " + res.getSSEAlgorithm()); } else if (ssecLocal != null) { System.out.println("Uploaded object encryption status is " + res.getSSEAlgorithm()); } } } catch (Exception e) { System.err.println("Not possible to write object :" + key); e.printStackTrace(); return Status.ERROR; } } catch (Exception e) { System.err.println("Error in the creation of the stream :" + e.toString()); e.printStackTrace(); return Status.ERROR; } return Status.OK; }
From source file:com.yahoo.ycsb.utils.connection.S3Connection.java
License:Open Source License
public Status insert(String key, byte[] bytes) { try (InputStream input = new ByteArrayInputStream(bytes)) { ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(bytes.length); PutObjectRequest putObjectRequest = null; if (ssecKey != null) { if (ssecKey.equals("true")) { metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); putObjectRequest = new PutObjectRequest(bucket, key, input, metadata); } else { putObjectRequest = new PutObjectRequest(bucket, key, input, metadata) .withSSECustomerKey(ssecKey); }//from www.j av a 2 s. c om } else { putObjectRequest = new PutObjectRequest(bucket, key, input, metadata); } try { PutObjectResult res = awsClient.putObject(putObjectRequest); if (res.getETag() == null) { return Status.ERROR; } else { if (ssecKey != null) { if (ssecKey.equals("true")) { logger.debug("Uploaded object encryption status is " + res.getSSEAlgorithm()); } else { logger.debug("Uploaded object encryption status is " + res.getSSEAlgorithm()); } } } } catch (Exception e) { logger.error("Not possible to write object :" + key); System.err.println("Retrying " + key); insert(key, bytes); } } catch (Exception e) { logger.error("Error in the creation of the stream :" + e.toString()); System.err.println("Retrying " + key); insert(key, bytes); //e.printStackTrace(); //return Status.ERROR; } return Status.OK; }
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 . jav a2 s.c om */ @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:io.druid.storage.s3.S3ServerSideEncryption.java
License:Apache License
@Override public PutObjectRequest decorate(PutObjectRequest request) { final ObjectMetadata objectMetadata = request.getMetadata() == null ? new ObjectMetadata() : request.getMetadata().clone(); objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); return request.withMetadata(objectMetadata); }
From source file:io.druid.storage.s3.S3ServerSideEncryption.java
License:Apache License
@Override public CopyObjectRequest decorate(CopyObjectRequest request) { final ObjectMetadata objectMetadata = request.getNewObjectMetadata() == null ? new ObjectMetadata() : request.getNewObjectMetadata().clone(); objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); return request.withNewObjectMetadata(objectMetadata); }
From source file:jenkins.plugins.itemstorage.s3.S3BaseUploadCallable.java
License:Open Source License
protected ObjectMetadata buildMetadata(File file) throws IOException { final ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType(Mimetypes.getInstance().getMimetype(file.getName())); metadata.setContentLength(file.length()); metadata.setLastModified(new Date(file.lastModified())); if (storageClass != null && !storageClass.isEmpty()) { metadata.setHeader("x-amz-storage-class", storageClass); }//from ww w . ja v a 2 s . co m if (useServerSideEncryption) { metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); } for (Map.Entry<String, String> entry : userMetadata.entrySet()) { final String key = entry.getKey().toLowerCase(); switch (key) { case "cache-control": metadata.setCacheControl(entry.getValue()); break; case "expires": try { final Date expires = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z") .parse(entry.getValue()); metadata.setHttpExpiresDate(expires); } catch (ParseException e) { metadata.addUserMetadata(entry.getKey(), entry.getValue()); } break; case "content-encoding": metadata.setContentEncoding(entry.getValue()); break; case "content-type": metadata.setContentType(entry.getValue()); default: metadata.addUserMetadata(entry.getKey(), entry.getValue()); break; } } return metadata; }