java:使用vfs s3插件在Amazon S3中使用服务器端加密 [英] java : Use Server-Side Encryption in Amazon S3 using vfs s3 plugin

查看:135
本文介绍了java:使用vfs s3插件在Amazon S3中使用服务器端加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在S3中复制文件,我使用 vfs-s3-2.2.1.jar
我在 com.intridea下找到 S3FileObject 类.io.vfs.provider.s3 包。
我在其中使用 public void copyFrom(最终FileObject文件,最终FileSelector选择器)复制文件的方法。
在这个方法中,我找到了以下代码:

For copying file in S3, I am using vfs-s3-2.2.1.jar I found S3FileObject class under com.intridea.io.vfs.provider.s3 package. In which I am using public void copyFrom(final FileObject file, final FileSelector selector) method for copy file. In this method I found following code :

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();
}

在官方参考中它使用这些方法

withSourceSSECustomerKey(sseKey)
withDestinationSSECustomerKey(newSseKey);

vfs-s3-2.2.1的 copyFrom 方法.jar S3FileObject
我找不到任何方法来设置 SSECustomerKey
如何实现相同的目标。
感谢您查看此处。

In copyFrom method of vfs-s3-2.2.1.jar S3FileObject I can't find any method to set SSECustomerKey How can I achieve the same. Thanks for looking here.

推荐答案

我没有测试,但我快速查看了lib /代码 - 在< a href =https://github.com/abashev/vfs-s3/blob/branch-2.3.x/src/main/java/com/intridea/io/vfs/provider/s3/S3FileSystemConfigBuilder.java = nofollow的> https://github.com/abashev/vfs-s3/blob/branch-2.3.x/src/main/java/com/intridea/io/vfs/provider/s3/S3FileSystemConfigBuilder.java 有一种设置服务器端加密的方法

I did not test but I look at the lib/code quickly - in https://github.com/abashev/vfs-s3/blob/branch-2.3.x/src/main/java/com/intridea/io/vfs/provider/s3/S3FileSystemConfigBuilder.java there is a method to set the server-side encryption

/**
 * 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);
}

所以在你调用 copyFrom之前你可以做什么

so before you're calling the copyFrom you can do

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

这篇关于java:使用vfs s3插件在Amazon S3中使用服务器端加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆