List of usage examples for com.amazonaws.services.s3.model PutObjectRequest setSSEAwsKeyManagementParams
public void setSSEAwsKeyManagementParams(SSEAwsKeyManagementParams params)
From source file:io.konig.camel.aws.s3.DeleteObjectProducer.java
License:Apache License
public void processSingleOp(final Exchange exchange) throws Exception { ObjectMetadata objectMetadata = determineMetadata(exchange); File filePayload = null;/*from w ww.ja v a 2 s.c o m*/ InputStream is = null; ByteArrayOutputStream baos = null; Object obj = exchange.getIn().getMandatoryBody(); PutObjectRequest putObjectRequest = null; // Need to check if the message body is WrappedFile if (obj instanceof WrappedFile) { obj = ((WrappedFile<?>) obj).getFile(); } if (obj instanceof File) { filePayload = (File) obj; is = new FileInputStream(filePayload); } else { is = exchange.getIn().getMandatoryBody(InputStream.class); baos = determineLengthInputStream(is); objectMetadata.setContentLength(baos.size()); is = new ByteArrayInputStream(baos.toByteArray()); } putObjectRequest = new PutObjectRequest(getConfiguration().getBucketName(), determineKey(exchange), is, objectMetadata); String storageClass = determineStorageClass(exchange); if (storageClass != null) { putObjectRequest.setStorageClass(storageClass); } String cannedAcl = exchange.getIn().getHeader(S3Constants.CANNED_ACL, String.class); if (cannedAcl != null) { CannedAccessControlList objectAcl = CannedAccessControlList.valueOf(cannedAcl); putObjectRequest.setCannedAcl(objectAcl); } AccessControlList acl = exchange.getIn().getHeader(S3Constants.ACL, AccessControlList.class); if (acl != null) { // note: if cannedacl and acl are both specified the last one will // be used. refer to // PutObjectRequest#setAccessControlList for more details putObjectRequest.setAccessControlList(acl); } if (getConfiguration().isUseAwsKMS()) { SSEAwsKeyManagementParams keyManagementParams; if (ObjectHelper.isNotEmpty(getConfiguration().getAwsKMSKeyId())) { keyManagementParams = new SSEAwsKeyManagementParams(getConfiguration().getAwsKMSKeyId()); } else { keyManagementParams = new SSEAwsKeyManagementParams(); } putObjectRequest.setSSEAwsKeyManagementParams(keyManagementParams); } LOG.trace("Put object [{}] from exchange [{}]...", putObjectRequest, exchange); PutObjectResult putObjectResult = getEndpoint().getS3Client().putObject(putObjectRequest); LOG.trace("Received result [{}]", putObjectResult); Message message = getMessageForResponse(exchange); message.setHeader(S3Constants.E_TAG, putObjectResult.getETag()); if (putObjectResult.getVersionId() != null) { message.setHeader(S3Constants.VERSION_ID, putObjectResult.getVersionId()); } if (getConfiguration().isDeleteAfterWrite() && filePayload != null) { // close streams IOHelper.close(putObjectRequest.getInputStream()); IOHelper.close(is); FileUtil.deleteFile(filePayload); } }
From source file:org.apache.nifi.processors.aws.s3.encryption.ServerSideKMSEncryptionStrategy.java
License:Apache License
@Override public void configurePutObjectRequest(PutObjectRequest request, ObjectMetadata objectMetadata, String keyValue) {//from www . ja v a 2 s . co m SSEAwsKeyManagementParams keyParams = new SSEAwsKeyManagementParams(keyValue); request.setSSEAwsKeyManagementParams(keyParams); }
From source file:org.apache.nifi.processors.aws.s3.encryption.service.StandardS3ServerSideEncryptionService.java
License:Apache License
public void encrypt(PutObjectRequest putObjectRequest) { if (encryptionMethod == null) return;/* w w w .ja v a2s.com*/ if (encryptionMethod.equals(METHOD_SSE_S3)) { getLogger().info("Encrypting single part object using SSE-S3"); putObjectRequest.getMetadata() .setSSEAlgorithm(algorithm == null ? ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION : algorithm); } if (encryptionMethod.equals(METHOD_SSE_KMS)) { getLogger().info("Encrypting single part object using SSE-KMS"); putObjectRequest.setSSEAwsKeyManagementParams( kmsKeyId == null ? new SSEAwsKeyManagementParams() : new SSEAwsKeyManagementParams(kmsKeyId)); } if (encryptionMethod.equals(METHOD_SSE_C)) { getLogger().info("Encrypting single part object using SSE-C"); if (StringUtils.isNotBlank(customerKey)) { putObjectRequest.setSSECustomerKey(new SSECustomerKey(customerKey)); } String sseCustomerAlgorithm = customerAlgorithm == null ? ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION : customerAlgorithm; putObjectRequest.getMetadata().setSSECustomerAlgorithm(sseCustomerAlgorithm); if (StringUtils.isNotBlank(customerKeyMD5)) { putObjectRequest.getMetadata().setSSECustomerKeyMd5(customerKeyMD5); } } }