Java 类com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper 实例源码

项目:spring-cloud-aws    文件:ContextCredentialsAutoConfigurationTest.java   
@Test
public void credentialsProvider_noExplicitCredentialsProviderConfigured_configuresDefaultAwsCredentialsProviderChainWithInstanceProfile() throws Exception {
    // Arrange
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(ContextCredentialsAutoConfiguration.class);

    // Act
    this.context.refresh();

    // Assert
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, AWSCredentialsProvider.class);
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(2, credentialsProviders.size());
    assertTrue(EC2ContainerCredentialsProviderWrapper.class.isInstance(credentialsProviders.get(0)));
    assertTrue(ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1)));
}
项目:spring-cloud-aws    文件:ContextCredentialsAutoConfigurationTest.java   
@Test
public void credentialsProvider_instanceProfileConfigured_configuresInstanceProfileCredentialsProvider() {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(ContextCredentialsAutoConfiguration.class);
    TestPropertyValues.of(
            "cloud.aws.credentials.instanceProfile").applyTo(this.context);
    this.context.refresh();
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, AWSCredentialsProvider.class);
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(2, credentialsProviders.size());
    assertTrue(EC2ContainerCredentialsProviderWrapper.class.isInstance(credentialsProviders.get(0)));
    assertTrue(ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1)));
}
项目:spring-cloud-aws    文件:ContextCredentialsAutoConfigurationTest.java   
@Test
public void credentialsProvider_profileNameConfigured_configuresProfileCredentialsProvider() {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(ContextCredentialsAutoConfiguration.class);
    TestPropertyValues.of(
            "cloud.aws.credentials.profileName:test").applyTo(this.context);
    this.context.refresh();
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, AWSCredentialsProvider.class);
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(2, credentialsProviders.size());
    assertTrue(EC2ContainerCredentialsProviderWrapper.class.isInstance(credentialsProviders.get(0)));
    assertTrue(ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1)));

    assertEquals("test", ReflectionTestUtils.getField(credentialsProviders.get(1), "profileName"));
}
项目:spring-cloud-aws    文件:ContextCredentialsAutoConfigurationTest.java   
@Test
public void credentialsProvider_profileNameAndPathConfigured_configuresProfileCredentialsProvider() throws IOException {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(ContextCredentialsAutoConfiguration.class);
    TestPropertyValues.of(
            "cloud.aws.credentials.profileName:customProfile",
            "cloud.aws.credentials.profilePath:" + new ClassPathResource(getClass().getSimpleName() + "-profile", getClass()).getFile().getAbsolutePath()).applyTo(this.context);
    this.context.refresh();
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, AWSCredentialsProvider.class);
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(2, credentialsProviders.size());
    assertTrue(EC2ContainerCredentialsProviderWrapper.class.isInstance(credentialsProviders.get(0)));
    assertTrue(ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1)));

    ProfileCredentialsProvider provider = (ProfileCredentialsProvider) credentialsProviders.get(1);
    assertEquals("testAccessKey", provider.getCredentials().getAWSAccessKeyId());
    assertEquals("testSecretKey", provider.getCredentials().getAWSSecretKey());
}
项目:spring-cloud-aws    文件:ContextCredentialsConfigurationRegistrarTest.java   
@Test
public void credentialsProvider_configWithAccessAndSecretKeyAndInstanceProfile_staticAwsCredentialsProviderConfiguredWithInstanceProfile() throws Exception {
    //Arrange
    this.context = new AnnotationConfigApplicationContext(ApplicationConfigurationWithAccessKeyAndSecretKeyAndInstanceProfile.class);

    //Act
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AWSCredentialsProvider.class);

    //Assert
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(2, credentialsProviders.size());
    assertTrue(AWSStaticCredentialsProvider.class.isInstance(credentialsProviders.get(0)));
    assertTrue(EC2ContainerCredentialsProviderWrapper.class.isInstance(credentialsProviders.get(1)));
}
项目:spring-cloud-aws    文件:ContextCredentialsConfigurationRegistrarTest.java   
@Test
public void credentialsProvider_configWithInstanceProfile_instanceProfileCredentialsProviderConfigured() throws Exception {
    //Arrange
    this.context = new AnnotationConfigApplicationContext(ApplicationConfigurationWithInstanceProfileOnly.class);

    //Act
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AWSCredentialsProvider.class);

    //Assert
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(1, credentialsProviders.size());
    assertTrue(EC2ContainerCredentialsProviderWrapper.class.isInstance(credentialsProviders.get(0)));
}
项目:spring-cloud-aws    文件:ContextCredentialsConfigurationRegistrarTest.java   
@Test
public void credentialsProvider_configWithAllProviders_allCredentialsProvidersConfigured() throws Exception {
    //Arrange
    this.context = new AnnotationConfigApplicationContext(ApplicationConfigurationWithAllProviders.class);

    //Act
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AWSCredentialsProvider.class);

    //Assert
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(3, credentialsProviders.size());
    assertTrue(AWSStaticCredentialsProvider.class.isInstance(credentialsProviders.get(0)));
    assertTrue(EC2ContainerCredentialsProviderWrapper.class.isInstance(credentialsProviders.get(1)));
    assertTrue(ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(2)));
}
项目:spring-cloud-aws    文件:ContextConfigurationUtils.java   
public static void registerCredentialsProvider(BeanDefinitionRegistry registry, String accessKey, String secretKey, boolean instanceProfile, String profileName, String profilePath) {
    BeanDefinitionBuilder factoryBeanBuilder = BeanDefinitionBuilder.genericBeanDefinition(CredentialsProviderFactoryBean.class);

    ManagedList<BeanDefinition> awsCredentialsProviders = new ManagedList<>();

    if (StringUtils.hasText(accessKey)) {
        BeanDefinitionBuilder credentials = BeanDefinitionBuilder.rootBeanDefinition(BasicAWSCredentials.class);
        credentials.addConstructorArgValue(accessKey);
        credentials.addConstructorArgValue(secretKey);

        BeanDefinitionBuilder provider = BeanDefinitionBuilder.rootBeanDefinition(AWSStaticCredentialsProvider.class);
        provider.addConstructorArgValue(credentials.getBeanDefinition());

        awsCredentialsProviders.add(provider.getBeanDefinition());
    }

    if (instanceProfile) {
        awsCredentialsProviders.add(BeanDefinitionBuilder.rootBeanDefinition(EC2ContainerCredentialsProviderWrapper.class).getBeanDefinition());
    }

    if (StringUtils.hasText(profileName)) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ProfileCredentialsProvider.class);
        if (StringUtils.hasText(profilePath)) {
            builder.addConstructorArgValue(profilePath);
        }

        builder.addConstructorArgValue(profileName);
        awsCredentialsProviders.add(builder.getBeanDefinition());
    }

    factoryBeanBuilder.addConstructorArgValue(awsCredentialsProviders);

    registry.registerBeanDefinition(CredentialsProviderFactoryBean.CREDENTIALS_PROVIDER_BEAN_NAME, factoryBeanBuilder.getBeanDefinition());

    AmazonWebserviceClientConfigurationUtils.replaceDefaultCredentialsProvider(registry, CredentialsProviderFactoryBean.CREDENTIALS_PROVIDER_BEAN_NAME);
}
项目:strongbox    文件:CustomCredentialsProviderChain.java   
public CustomCredentialsProviderChain(ClientConfiguration clientConfiguration, ProfileIdentifier profile, Supplier<MFAToken> mfaTokenSupplier) {
    super(new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(),
            new ProfileCredentialProvider(clientConfiguration, profile, mfaTokenSupplier),
            new EC2ContainerCredentialsProviderWrapper());
}
项目:daikon    文件:S3ContentServiceConfiguration.java   
private static AmazonS3ClientBuilder configureEC2Authentication(AmazonS3ClientBuilder builder) {
    LOGGER.info("Using EC2 authentication");
    return builder.withCredentials(new EC2ContainerCredentialsProviderWrapper());
}