本文整理汇总了Java中com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider类的典型用法代码示例。如果您正苦于以下问题:Java STSAssumeRoleSessionCredentialsProvider类的具体用法?Java STSAssumeRoleSessionCredentialsProvider怎么用?Java STSAssumeRoleSessionCredentialsProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
STSAssumeRoleSessionCredentialsProvider类属于com.amazonaws.auth包,在下文中一共展示了STSAssumeRoleSessionCredentialsProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAWSCredentialsProviderChain
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
public static AWSCredentialsProviderChain getAWSCredentialsProviderChain() {
String cerberusRoleToAssume = System.getenv(CERBERUS_ASSUME_ROLE_ARN) != null ?
System.getenv(CERBERUS_ASSUME_ROLE_ARN) : "";
String cerberusRoleToAssumeExternalId = System.getenv(CERBERUS_ASSUME_ROLE_EXTERNAL_ID) != null ?
System.getenv(CERBERUS_ASSUME_ROLE_EXTERNAL_ID) : "";
STSAssumeRoleSessionCredentialsProvider sTSAssumeRoleSessionCredentialsProvider =
new STSAssumeRoleSessionCredentialsProvider
.Builder(cerberusRoleToAssume, UUID.randomUUID().toString())
.withExternalId(cerberusRoleToAssumeExternalId)
.build();
AWSCredentialsProviderChain chain = new AWSCredentialsProviderChain(
new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(),
new ProfileCredentialsProvider(),
sTSAssumeRoleSessionCredentialsProvider,
new InstanceProfileCredentialsProvider());
return chain;
}
示例2: provideSecurityTokenService_whenAwsStsRoleArnIsSet
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
@Test
public void provideSecurityTokenService_whenAwsStsRoleArnIsSet() {
context = new AnnotationConfigApplicationContext();
addEnvironment(context, "zipkin.collector.sqs.queue-url:" + sqsRule.queueUrl());
addEnvironment(context, "zipkin.collector.sqs.wait-time-seconds:1");
addEnvironment(context, "zipkin.collector.sqs.aws-access-key-id: x");
addEnvironment(context, "zipkin.collector.sqs.aws-secret-access-key: x");
addEnvironment(context, "zipkin.collector.sqs.aws-sts-role-arn: test");
context.register(PropertyPlaceholderAutoConfiguration.class, Region.class,
ZipkinSQSCollectorAutoConfiguration.class, ZipkinSQSCredentialsAutoConfiguration.class, InMemoryConfiguration.class);
context.refresh();
assertThat(context.getBean(SQSCollector.class)).isNotNull();
assertThat(context.getBean(AWSSecurityTokenService.class)).isNotNull();
assertThat(context.getBean(AWSCredentialsProvider.class)).isInstanceOf(STSAssumeRoleSessionCredentialsProvider.class);
}
示例3: kinesisCollectorConfiguredForAWSWithGivenCredentials
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
@Test
public void kinesisCollectorConfiguredForAWSWithGivenCredentials() {
addEnvironment(context, "zipkin.collector.kinesis.stream-name: zipkin-test");
addEnvironment(context, "zipkin.collector.kinesis.app-name: zipkin");
addEnvironment(context, "zipkin.collector.kinesis.aws-access-key-id: x");
addEnvironment(context, "zipkin.collector.kinesis.aws-secret-access-key: x");
addEnvironment(context, "zipkin.collector.kinesis.aws-sts-role-arn: test");
context.register(PropertyPlaceholderAutoConfiguration.class,
ZipkinKinesisCollectorAutoConfiguration.class,
ZipkinKinesisCredentialsAutoConfiguration.class,
InMemoryConfiguration.class);
context.refresh();
assertThat(context.getBean(KinesisCollector.class)).isNotNull();
assertThat(context.getBean(AWSSecurityTokenService.class)).isNotNull();
assertThat(context.getBean(AWSCredentialsProvider.class)).isInstanceOf(STSAssumeRoleSessionCredentialsProvider.class);
}
示例4: buildCredentialsProvider
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
private AWSCredentialsProvider buildCredentialsProvider(final AWSCredentials credentials, final String region, final String assumeRole) {
AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
if (isNullOrEmpty(assumeRole)) {
return credentialsProvider;
}
else {
// STS requires a region; fall back on the SDK default if not set
String stsRegion;
if (isNullOrEmpty(region)) {
stsRegion = defaultRegion();
}
else {
stsRegion = region;
}
AWSSecurityTokenService securityTokenService = AWSSecurityTokenServiceClientBuilder.standard()
.withRegion(stsRegion)
.withCredentials(credentialsProvider).build();
return new STSAssumeRoleSessionCredentialsProvider.Builder(assumeRole, "nexus-s3-session")
.withStsClient(securityTokenService)
.build();
}
}
示例5: initializeApiClient
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
public AWSDeviceFarmClient initializeApiClient(final DeviceFarmExtension extension) {
final String roleArn = extension.getAuthentication().getRoleArn();
AWSCredentials credentials = extension.getAuthentication();
if (roleArn != null) {
final STSAssumeRoleSessionCredentialsProvider sts = new STSAssumeRoleSessionCredentialsProvider
.Builder(roleArn, RandomStringUtils.randomAlphanumeric(8))
.build();
credentials = sts.getCredentials();
}
final ClientConfiguration clientConfiguration = new ClientConfiguration()
.withUserAgent(String.format(extension.getUserAgent(), pluginVersion));
AWSDeviceFarmClient apiClient = new AWSDeviceFarmClient(credentials, clientConfiguration);
apiClient.setServiceNameIntern("devicefarm");
if (extension.getEndpointOverride() != null) {
apiClient.setEndpoint(extension.getEndpointOverride());
}
return apiClient;
}
示例6: init
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
@PostConstruct
public void init() {
// TODO
// this parameters have to be configurable
cache = CacheBuilder.newBuilder()
.maximumSize(500)
.expireAfterAccess(50, TimeUnit.MINUTES)
.removalListener((RemovalNotification<Key<?>, AmazonWebServiceClient> notification) -> {
logger.debug("Shutting down expired client for key: {}", notification.getKey());
notification.getValue().shutdown();
}).build(new CacheLoader<Key<?>, AmazonWebServiceClient>() {
@Override
public AmazonWebServiceClient load(@Nonnull final Key<?> key) throws Exception {
logger.debug("CacheLoader active for Key : {}", key);
return key.region.createClient(
key.type,
new STSAssumeRoleSessionCredentialsProvider(
buildRoleArn(key.accountId),
ROLE_SESSION_NAME),
new ClientConfiguration().withMaxErrorRetry(MAX_ERROR_RETRY));
}
});
}
示例7: getCredentialsProvider
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
public AWSCredentialsProvider getCredentialsProvider() {
AWSCredentialsProvider credentialsProviderChain = new DefaultAWSCredentialsProviderChain(this.config);
if (config.hasPath(GobblinAWSConfigurationKeys.CLIENT_ASSUME_ROLE_KEY) &&
config.getBoolean(GobblinAWSConfigurationKeys.CLIENT_ASSUME_ROLE_KEY)) {
String roleArn = config.getString(GobblinAWSConfigurationKeys.CLIENT_ROLE_ARN_KEY);
String sessionId = config.getString(GobblinAWSConfigurationKeys.CLIENT_SESSION_ID_KEY);
STSAssumeRoleSessionCredentialsProvider.Builder builder =
new STSAssumeRoleSessionCredentialsProvider.Builder(roleArn, sessionId)
.withLongLivedCredentialsProvider(credentialsProviderChain);
if (config.hasPath(GobblinAWSConfigurationKeys.CLIENT_EXTERNAL_ID_KEY)) {
builder.withExternalId(config.getString(GobblinAWSConfigurationKeys.CLIENT_EXTERNAL_ID_KEY));
}
if (config.hasPath(GobblinAWSConfigurationKeys.CREDENTIALS_REFRESH_INTERVAL)) {
builder.withRoleSessionDurationSeconds(
(int) TimeUnit.MINUTES.toSeconds(config.getLong(GobblinAWSConfigurationKeys.CREDENTIALS_REFRESH_INTERVAL)));
}
credentialsProviderChain = builder.build();
}
return credentialsProviderChain;
}
示例8: AssumedRoleTestContext
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
public AssumedRoleTestContext(AWSCredentialsProvider awsCredentials, Region testRegion, String roleSuffix) {
iamHelper = new IAMHelper(awsCredentials, testRegion);
roleName = ROLE_PREFIX + roleSuffix;
roleArn = iamHelper.createOrGetRole(roleName);
principal = new Principal(PrincipalType.ROLE, roleName);
STSAssumeRoleSessionCredentialsProvider.Builder builder = new STSAssumeRoleSessionCredentialsProvider.Builder(roleArn, "mysession");
assumedAWSCredentials = builder.build();
secretGroupManager = new DefaultSecretsGroupManager(assumedAWSCredentials);
}
示例9: assumeRole
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
private AWSCredentialsProvider assumeRole(AWSCredentialsProvider longLivedAWSCredentials, ClientConfiguration clientConfiguration, String assumeRoleArn) {
AWSSecurityTokenService client = AWSSecurityTokenServiceClientBuilder.standard()
.withCredentials(longLivedAWSCredentials)
.withClientConfiguration(transformAndVerifyOrThrow(clientConfiguration))
.withRegion(RegionResolver.getRegion())
.build();
STSAssumeRoleSessionCredentialsProvider.Builder builder =
new STSAssumeRoleSessionCredentialsProvider.Builder(assumeRoleArn, "strongbox-cli");
builder.withStsClient(client);
return builder.build();
}
示例10: credentialsProvider
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
/** By default, get credentials from the {@link DefaultAWSCredentialsProviderChain */
@Bean
@ConditionalOnMissingBean
AWSCredentialsProvider credentialsProvider(ZipkinSQSCollectorProperties properties) {
if (securityTokenService != null) {
return new STSAssumeRoleSessionCredentialsProvider.Builder(properties.awsStsRoleArn, "zipkin-server")
.withStsClient(securityTokenService)
.build();
} else {
return getDefaultCredentialsProvider(properties);
}
}
示例11: credentialsProvider
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
/** By default, get credentials from the {@link DefaultAWSCredentialsProviderChain */
@Bean
@ConditionalOnMissingBean
AWSCredentialsProvider credentialsProvider(ZipkinKinesisCollectorProperties properties) {
if (securityTokenService != null) {
return new STSAssumeRoleSessionCredentialsProvider.Builder(properties.awsStsRoleArn,
"zipkin-server")
.withStsClient(securityTokenService)
.build();
} else {
return getDefaultCredentialsProvider(properties);
}
}
示例12: setRoleToAssumeArn
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
public void setRoleToAssumeArn(String roleToAssumeArn) {
this.roleToAssumeArn = roleToAssumeArn;
if(!Validator.isBlank(roleToAssumeArn)) {
String sessionId = "session" + Math.random();
STSAssumeRoleSessionCredentialsProvider remoteAccountCredentials = new STSAssumeRoleSessionCredentialsProvider(credentials,
roleToAssumeArn,
sessionId);
credentials = remoteAccountCredentials;
}
}
示例13: AWSDeviceFarm
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
/**
* Private AWSDeviceFarm constructor. Uses the roleArn to generate STS creds if the roleArn isn't null; otherwise
* just uses the AWSCredentials creds.
*
* @param creds AWSCredentials creds to use for authentication.
* @param roleArn Role ARN to use for authentication.
*/
private AWSDeviceFarm(AWSCredentials creds, String roleArn) {
if (roleArn != null) {
STSAssumeRoleSessionCredentialsProvider sts = new STSAssumeRoleSessionCredentialsProvider
.Builder(roleArn, RandomStringUtils.randomAlphanumeric(8))
.build();
creds = sts.getCredentials();
}
ClientConfiguration clientConfiguration = new ClientConfiguration().withUserAgent("AWS Device Farm - Jenkins v1.0");
api = new AWSDeviceFarmClient(creds, clientConfiguration);
api.setServiceNameIntern("devicefarm");
}
示例14: getSTSCredentialsProvider
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
private AWSCredentialsProvider getSTSCredentialsProvider(AWSCredentialsProvider awsCredentials, String region, String assumeRoleArn) {
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard()
.withRegion(region)
.withCredentials(awsCredentials)
.build();
String roleSessionName = String.format("API_KEY_%[email protected]_%s",
awsCredentials.getCredentials().getAWSAccessKeyId(),
stsClient.getCallerIdentity(new GetCallerIdentityRequest()).getAccount());
LOG.debug("Cross account role session name: " + roleSessionName);
return new STSAssumeRoleSessionCredentialsProvider.Builder(assumeRoleArn, roleSessionName)
.withStsClient(stsClient)
.build();
}
示例15: DefaultSimpleSecretsGroup
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; //导入依赖的package包/类
public DefaultSimpleSecretsGroup(final SecretsGroupIdentifier groupIdentifier, final RoleARN role) {
AWSCredentialsProvider assumedAWSCredentials = new STSAssumeRoleSessionCredentialsProvider.Builder(role.toArn(), SessionName.getSessionName("StrongboxSDK")).build();
DefaultSecretsGroupManager secretsGroupManager = new DefaultSecretsGroupManager(assumedAWSCredentials);
secretsGroup = secretsGroupManager.get(groupIdentifier);
}