通过jclouds使用AWS(S3) - 如何承担角色 [英] Using AWS (S3) via jclouds - how to assume role
本文介绍了通过jclouds使用AWS(S3) - 如何承担角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用普通的身份验证凭据,我可以做的:
When using plain auth credentials I can do:
ContextBuilder.newBuilder("aws-s3").credentials(keyId, key).buildView(BlobStoreContext.class);
...访问BlobStoreContext为S3。
... to access BlobStoreContext for S3.
在本机亚马逊的Java API,我可以使用安全令牌服务(STS)承担的角色,并使用临时凭据访问S3或任何其他AWS服务。
In native Amazon java api I can use Security Token Service (STS) to assume role and use temporary credentials to access S3 or any other AWS service.
我如何做到这一点的jclouds?
How do I do this in jclouds?
推荐答案
我想它了。
这code段允许承担的角色和使用温度凭据访问S3:
This code snippet allows to assume role and use temp credentials to access S3:
STSApi api = ContextBuilder.newBuilder("sts").credentials(keyId,
key).buildApi(STSApi.class);
AssumeRoleOptions assumeRoleOptions = new AssumeRoleOptions().durationSeconds(3600).externalId(externalId);
final UserAndSessionCredentials credentials = api.assumeRole(roleArn, sessionName, assumeRoleOptions);
Supplier<Credentials> credentialsSupplier = new Supplier<Credentials>() {
@Override
public Credentials get() {
return credentials.getCredentials();
}
};
BlobStoreContext context = ContextBuilder.newBuilder("aws-s3").credentialsSupplier(credentialsSupplier).buildView(BlobStoreContext.class);
这篇关于通过jclouds使用AWS(S3) - 如何承担角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文