【问题标题】:Integrating STS with AWSS3TransferManagerUploadRequest and AWSS3TransferManagerDownloadRequest将 STS 与 AWSS3TransferManagerUploadRequest 和 AWSS3TransferManagerDownloadRequest 集成
【发布时间】:2014-11-24 23:31:24
【问题描述】:

我们正在尝试在我们的 android 和 iOS 应用程序中实施 AWS Security Token Service。在后端,我们使用以下代码生成令牌:

public class CloudManagementImpl implements CloudManagement{

    private static final Logger Log = LoggerFactory.getLogger(CloudManagementImpl.class);

    @Override
    public CloudConfiguration getCloudProperties() {

        CloudConfiguration CloudConfiguration = new CloudConfiguration();

        AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest();
        assumeRoleRequest.setRoleArn(JiveGlobals.getProperty(XYZConstant.AWS_ARN_EC2_ROLE_MAP));
        assumeRoleRequest.setRoleSessionName(XYZConstant.AWS_ROLE_SESSIONNAME);
        assumeRoleRequest.setDurationSeconds(JiveGlobals.getIntProperty(XYZConstant.AWS_CREDENTIALS_LIFETIME, 1800));

        AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient();
        AssumeRoleResult assumeRoleResult = stsClient.assumeRole(assumeRoleRequest);
        if (assumeRoleResult != null) {
            Credentials sessionCredentials = assumeRoleResult.getCredentials();
            CloudConfiguration.setAwsAccessId(sessionCredentials.getAccessKeyId());
            CloudConfiguration.setAwsAccessKey(sessionCredentials.getSecretAccessKey());
            CloudConfiguration.setToken(sessionCredentials.getSessionToken());
            CloudConfiguration.setAwsMainBucket(JiveGlobals.getProperty(XYZConstant.AWS_MAIN_BUCKET));
        } else {
            Log.error("Cloud Management :: Propery values not configured ");
        }

        return CloudConfiguration;
    }

}

然后通过单独的 Web 服务调用在 iOS 和 android 应用程序中获取生成的令牌。

在 android 中,我们使用以下代码来使用检索到的令牌:

public S3Client(String accessKey, String secretKey, String token, String bucketName) {
        super();
        this.accessKey = accessKey;
        this.secretKey = secretKey;
        this.bucketName = bucketName;
        BasicSessionCredentials basicSessionCredentials = new BasicSessionCredentials(accessKey, secretKey, token);
        amazonS3Client = new AmazonS3Client(basicSessionCredentials);

    }

问题是——

我们在适用于 iOS 的 AWS 移动 SDK 版本 2 中没有类似 android 的 API, 使用它我们可以使用检索到的令牌,也许是最好的方法 在 iOS 中实现这个东西是通过 AWSCognitoCredentialsProvider, 但我们不确定。

请建议 - 在 iOS 中集成 AWS Security Token Service 的最佳方式是什么。

【问题讨论】:

    标签: ios7 amazon-web-services amazon-s3 amazon-cognito


    【解决方案1】:

    您需要通过符合AWSCredentialsProvider 来实现自己的凭据提供程序。听起来您已经有一个代码 sn-p 可以从您的服务器检索临时凭据。该逻辑应该进入您的自定义凭据提供程序。您可以查看AWSWebIdentityCredentialsProviderAWSCognitoCredentialsProvider 的实现,了解如何实现您自己的凭据提供程序。

    【讨论】:

    • 目前我们只从服务器检索“令牌”,不确定它是否等同于您提到的“临时凭据”。如果我们通过符合“AWSCredentialsProvider”来实现自己的凭证提供程序,在这种情况下,我们是否需要从服务器检索“令牌”?
    • 我想我得到了答案,感谢您引导我走向正确的方向 :) 据我所知 - 我不需要从服务器检索令牌,我需要使用类似的代码 sn-我在我的自定义凭据提供程序类中为服务器发布的 p,一旦实现了凭据提供程序类,我只需要使用凭据提供程序创建 serviceConfiguration 对象,然后将其设置为默认服务配置。如果我错了,请纠正我。
    猜你喜欢
    • 2011-11-13
    • 2011-05-28
    • 2013-08-24
    • 2016-06-15
    • 2012-02-03
    • 1970-01-01
    • 2018-04-19
    • 2011-12-04
    • 2013-12-14
    相关资源
    最近更新 更多