Example usage for com.amazonaws.auth DefaultAWSCredentialsProviderChain DefaultAWSCredentialsProviderChain

List of usage examples for com.amazonaws.auth DefaultAWSCredentialsProviderChain DefaultAWSCredentialsProviderChain

Introduction

In this page you can find the example usage for com.amazonaws.auth DefaultAWSCredentialsProviderChain DefaultAWSCredentialsProviderChain.

Prototype

public DefaultAWSCredentialsProviderChain() 

Source Link

Usage

From source file:io.kodokojo.config.module.AwsModule.java

License:Open Source License

@Provides
@Singleton/*w  w  w  . j a v a 2 s .co  m*/
EmailSender provideEmailSender(AwsConfig awsConfig, EmailConfig emailConfig) {
    if (StringUtils.isBlank(emailConfig.smtpHost())) {
        AWSCredentials credentials = null;
        try {
            DefaultAWSCredentialsProviderChain defaultAWSCredentialsProviderChain = new DefaultAWSCredentialsProviderChain();
            credentials = defaultAWSCredentialsProviderChain.getCredentials();
        } catch (RuntimeException e) {
            LOGGER.warn("Unable to retrieve AWS credentials.");
        }
        if (credentials == null) {
            return new NoopEmailSender();
        } else {
            return new SesEmailSender(emailConfig.smtpFrom(),
                    Region.getRegion(Regions.fromName(awsConfig.region())));
        }
    } else {
        return new SmtpEmailSender(emailConfig.smtpHost(), emailConfig.smtpPort(), emailConfig.smtpUsername(),
                emailConfig.smtpPassword(), emailConfig.smtpFrom());
    }
}

From source file:io.kodokojo.service.aws.Route53DnsManager.java

License:Open Source License

public Route53DnsManager(String domainName, Region region) {
    if (isBlank(domainName)) {
        throw new IllegalArgumentException("domainName must be defined.");
    }/*from ww w .  ja v a 2s  .  co  m*/
    this.domainName = domainName.endsWith(".") ? domainName : domainName + ".";

    AWSCredentials credentials = new DefaultAWSCredentialsProviderChain().getCredentials();
    client = new AmazonRoute53Client(credentials);
    client.setRegion(region == null ? Region.getRegion(Regions.EU_WEST_1) : region);
}

From source file:io.macgyver.plugin.cloud.aws.AWSServiceFactory.java

License:Apache License

private AWSCredentialsProvider getCredentialsProvider(ServiceDefinition def) {

    String accessKey = def.getProperty("accessKey");
    String secretKey = def.getProperty("secretKey");

    if (!StringUtils.isNullOrEmpty(accessKey) && !StringUtils.isNullOrEmpty(secretKey)) {
        logger.info("using static credentials " + accessKey + " for AWS service " + def.getName());
        return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey));
    }//from ww w.ja  v a 2 s  .  c  o m

    String sourceService = def.getProperty("sourceService");
    String assumeRoleName = def.getProperty("assumeRoleName");
    if (!StringUtils.isNullOrEmpty(sourceService) && !StringUtils.isNullOrEmpty(assumeRoleName)) {
        String roleArn = "arn:aws:iam::" + def.getProperty("accountId") + ":role/" + assumeRoleName;
        logger.info("using assume-role credentials for " + roleArn + " from " + sourceService
                + " for AWS service " + def.getName());
        return new AWSServiceClientAssumeRoleCredentialsProvider(registry, sourceService, roleArn);
    }

    logger.info("using default credentials provider for AWS service " + def.getName());
    return new DefaultAWSCredentialsProviderChain();

}

From source file:io.macgyver.plugin.cloud.aws.DefaultAWSScannerTestRunner.java

License:Apache License

public static void main(String[] args) {

    NeoRxClient neo4j = new NeoRxClientBuilder().build();

    AWSServiceClientImpl aws = new AWSServiceClientImpl(new DefaultAWSCredentialsProviderChain());
    aws.setAccountId("000000000000"); // 12-digit

    DefaultAWSScannerGroup sg = new DefaultAWSScannerGroup(aws, neo4j);

    sg.scan("us-west-2");
    //      sg.scanAllRegions();

}

From source file:io.macgyver.plugin.cloud.aws.scanner.DefaultAWSScannerGroup.java

License:Apache License

public static void main(String[] args) throws Exception {

    AWSServiceClientImpl c = new AWSServiceClientImpl(new DefaultAWSCredentialsProviderChain(), "000000000000");

    NeoRxClient neo4j = new NeoRxClientBuilder().build();

    AWSScannerGroup g = new DefaultAWSScannerGroup(c, neo4j);

    g.scan(Region.getRegion(Regions.US_WEST_2));
}

From source file:io.vgs.tools.aws.maven.AuthenticationInfoAWSCredentialsProviderChain.java

License:Apache License

AuthenticationInfoAWSCredentialsProviderChain(AuthenticationInfo authenticationInfo) {
    super(new DefaultAWSCredentialsProviderChain(),
            new AuthenticationInfoAWSCredentialsProvider(authenticationInfo));
}

From source file:lumbermill.internal.aws.AWSV4SignerFactory.java

License:Apache License

public static RequestSigner createAndAddSignerToConfig(MapWrap parameters) {

    AWSCredentialsProvider longLived = new DefaultAWSCredentialsProviderChain();
    AWSCredentialsProvider credentialsProvider;
    if (parameters.exists("role")) {
        LOG.info("Using IAM role {} to access Elasticsearch", parameters.asString("role"));
        credentialsProvider = new STSAssumeRoleSessionCredentialsProvider(longLived,
                parameters.asString("role"), "lumbermill");
    } else {//  ww  w.j av  a2s. co m
        credentialsProvider = longLived;
    }

    return new AWSV4SignerImpl(credentialsProvider, parameters.asString("region"), "es");

}

From source file:lumbermill.internal.aws.KinesisClientFactory.java

License:Apache License

private AWSCredentialsProvider getAwsCredentialsProvider(MapWrap configuration, ClientConfiguration awsConfig) {
    AWSCredentialsProvider credentials = new DefaultAWSCredentialsProviderChain();
    Optional<String> roleArn = configuration.exists("role_arn")
            ? Optional.of(configuration.asString("role_arn"))
            : Optional.empty();/*from   ww  w  .  java2s .  c  om*/
    if (roleArn.isPresent()) {
        credentials = new STSAssumeRoleSessionCredentialsProvider(credentials, roleArn.get(), "lumbermill",
                awsConfig);
    }
    return credentials;
}

From source file:lumbermill.internal.aws.S3ClientImpl.java

License:Apache License

public void init() {
    ClientConfiguration awsConfig = new ClientConfiguration();
    if (System.getenv("https_proxy") != null) {
        URI proxy = URI.create(System.getenv("https_proxy"));
        awsConfig.setProxyHost(proxy.getHost());
        awsConfig.setProxyPort(proxy.getPort());
    }/*from  ww  w.  j a  v  a2s .c om*/

    //awsConfig.setConnectionTimeout(2000);
    //awsConfig.setRequestTimeout(2000);
    //awsConfig.setSocketTimeout(2000);
    //awsConfig.setClientExecutionTimeout(2000);

    AWSCredentialsProvider credentials = new DefaultAWSCredentialsProviderChain();
    if (roleArn.isPresent()) {
        credentials = new STSAssumeRoleSessionCredentialsProvider(credentials, roleArn.get(), "lumbermills3",
                awsConfig);
    }
    s3Client = new AmazonS3Client(credentials, awsConfig);

}

From source file:org.alfresco.provision.AWSService.java

License:Open Source License

private static AWSCredentialsProvider getCredentials() {
    AWSCredentialsProvider credentials = null;
    try {//from  ww w  . j ava 2 s.co m
        credentials = new DefaultAWSCredentialsProviderChain();
    } catch (Exception e) {
        throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
                + "Please make sure that your credentials file is at the correct "
                + "location (~/.aws/credentials), and is in valid format.", e);
    }

    return credentials;
}