2016-03-09 14 views
5

Per copiare file in S3, sto usando VFS-s3-2.2.1.jar ho trovato S3FileObject classe sotto com.intridea. io.vfs.provider.s3 pacchetto. In cui sto usando il metodo public void copyFrom(final FileObject file, final FileSelector selector) per il file di copia. In questo metodo ho trovato il codice seguente:java: utilizzare la crittografia lato server di Amazon S3 utilizzando VFS S3 plug

try { 
    if (srcFile.getType().hasChildren()) { 
     destFile.createFolder(); 
     // do server side copy if both source and dest are in S3 and using same credentials 
    } else if (srcFile instanceof S3FileObject) { 
     S3FileObject s3SrcFile = (S3FileObject)srcFile; 
     String srcBucketName = s3SrcFile.getBucket().getName(); 
     String srcFileName = s3SrcFile.getS3Key(); 
     String destBucketName = destFile.getBucket().getName(); 
     String destFileName = destFile.getS3Key(); 
     CopyObjectRequest copy = new CopyObjectRequest(
       srcBucketName, srcFileName, destBucketName, destFileName); 
     if (srcFile.getType() == FileType.FILE && getServerSideEncryption()) { 
      ObjectMetadata meta = s3SrcFile.getObjectMetadata(); 
      meta.setSSEAlgorithm(AES_256_SERVER_SIDE_ENCRYPTION); 
      copy.setNewObjectMetadata(meta); 
     } 
     getService().copyObject(copy); 
    } else if (srcFile.getType().hasContent() && srcFile.getURL().getProtocol().equals("file")) { 
     // do direct upload from file to avoid overhead of making a copy of the file 
     try { 
      File localFile = new File(srcFile.getURL().toURI()); 
      destFile.upload(localFile); 
     } catch (URISyntaxException e) { 
      // couldn't convert URL to URI, but should still be able to do the slower way 
      super.copyFrom(file, selector); 
     } 
    } else { 
     super.copyFrom(file, selector); 
    } 
} catch (IOException e) { 
    throw new FileSystemException("vfs.provider/copy-file.error", new Object[]{srcFile, destFile}, e); 
} catch (AmazonClientException e) { 
    throw new FileSystemException("vfs.provider/copy-file.error", new Object[]{srcFile, destFile}, e); 
} finally { 
    destFile.close(); 
} 

In official reference it uses these method

withSourceSSECustomerKey(sseKey) 
withDestinationSSECustomerKey(newSseKey); 

In CopyFrom metodo VFS-s3-2.2.1.jarS3FileObject non riesco a trovare qualsiasi metodo per impostare SSECustomerKey Come posso ottenere lo stesso. Grazie per aver guardato qui.

risposta

3

non ho la prova, ma guardo il lib/code rapidamente - in https://github.com/abashev/vfs-s3/blob/branch-2.3.x/src/main/java/com/intridea/io/vfs/provider/s3/S3FileSystemConfigBuilder.java c'è un metodo per impostare la crittografia lato server

/** 
* use server-side encryption. 
* 
* @param opts The FileSystemOptions. 
* @param serverSideEncryption true if server-side encryption should be used. 
*/ 
public void setServerSideEncryption(FileSystemOptions opts, boolean serverSideEncryption) 
{ 
    setParam(opts, SERVER_SIDE_ENCRYPTION, serverSideEncryption); 
} 

quindi prima si sta chiamando il copyFrom si può fare

S3FileSystemConfigBuilder.getInstance().setServerSideEncryption(
     S3FileSystemConfigBuilder.getInstance().getFileSystem().getFileSystemOptions(), 
     true);