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:org.geowebcache.s3.S3BlobStoreInfo.java

License:Open Source License

private AWSCredentialsProvider getCredentialsProvider() {
    if (null != awsSecretKey && null != awsAccessKey) {
        return new AWSCredentialsProvider() {

            @Override/* w  w w  . j a v  a  2  s  .  c om*/
            public AWSCredentials getCredentials() {
                if ("".equals(awsAccessKey) && "".equals(awsSecretKey)) {
                    return new AnonymousAWSCredentials();
                }
                return new BasicAWSCredentials(awsAccessKey, awsSecretKey);
            }

            @Override
            public void refresh() {
            }
        };
    }
    return new DefaultAWSCredentialsProviderChain();
}

From source file:org.lambadaframework.wagon.SimpleStorageServiceWagon.java

License:Apache License

@Override
protected void connectToRepository(Repository repository, AuthenticationInfo authenticationInfo,
        ProxyInfoProvider proxyInfoProvider) throws AuthenticationException {
    if (this.amazonS3 == null) {

        ClientConfiguration clientConfiguration = S3Utils.getClientConfiguration(proxyInfoProvider);

        this.bucketName = S3Utils.getBucketName(repository);
        this.baseDirectory = S3Utils.getBaseDirectory(repository);

        this.amazonS3 = new AmazonS3Client(new DefaultAWSCredentialsProviderChain(), clientConfiguration);
        Region region = Region.fromLocationConstraint(this.amazonS3.getBucketLocation(this.bucketName));
        this.amazonS3.setEndpoint(region.getEndpoint());
    }//from  w  ww  .jav a  2s . com
}

From source file:org.lendingclub.mercator.aws.AWSScannerBuilder.java

License:Apache License

AWSCredentialsProvider getCredentialsProvider() {
    if (credentialsProvide == null) {
        return new DefaultAWSCredentialsProviderChain();
    }/*  ww  w  .  ja  v  a2  s.  co m*/
    return credentialsProvide;
}

From source file:org.nickelproject.applications.S3Module.java

License:Apache License

@Provides
@Singleton//  w  w w .j  av a2  s  .  c  o  m
AmazonS3 provideS3Client() {
    return new AmazonS3Client(new AWSCredentialsProviderChain(new DefaultAWSCredentialsProviderChain(),
            new ClasspathPropertiesFileCredentialsProvider()));
}

From source file:org.springframework.cloud.aws.core.credentials.CredentialsProviderFactoryBean.java

License:Apache License

@Override
protected AWSCredentialsProvider createInstance() throws Exception {
    AWSCredentialsProviderChain awsCredentialsProviderChain;
    if (this.delegates.isEmpty()) {
        awsCredentialsProviderChain = new DefaultAWSCredentialsProviderChain();
    } else {/*from  w w w .  j  ava2  s  .com*/
        awsCredentialsProviderChain = new AWSCredentialsProviderChain(
                this.delegates.toArray(new AWSCredentialsProvider[this.delegates.size()]));
    }

    awsCredentialsProviderChain.setReuseLastProvider(false);
    return awsCredentialsProviderChain;
}

From source file:org.springframework.cloud.config.server.support.AwsCodeCommitCredentialProvider.java

License:Apache License

/**
 * Get the AWSCredentials. If an AWSCredentialProvider was specified, use that, otherwise,
 * create a new AWSCredentialsProvider. If the username and password are provided, then
 * use those directly as AWSCredentials. Otherwise us the {@link DefaultAWSCredentialsProviderChain}
 * as is standard with AWS applications. 
 * @return the AWS credentials./*from   www  .j a v  a  2 s. co m*/
 */
private AWSCredentials retrieveAwsCredentials() {
    if (awsCredentialProvider == null) {
        if (username != null && password != null) {
            logger.debug("Creating a static AWSCredentialsProvider");
            awsCredentialProvider = new AWSStaticCredentialsProvider(
                    new BasicAWSCredentials(username, password));
        } else {
            logger.debug("Creating a default AWSCredentialsProvider");
            awsCredentialProvider = new DefaultAWSCredentialsProviderChain();
        }
    }
    return awsCredentialProvider.getCredentials();
}

From source file:org.transitime.maintenance.AwsGlacier.java

License:Open Source License

/********************** Member Functions **************************/

public AwsGlacier(String region) {
    // Get credentials from credentials file, environment variable, or 
    // Java property. 
    // See http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html
    AWSCredentialsProviderChain credentialsProvider = new DefaultAWSCredentialsProviderChain();
    credentials = credentialsProvider.getCredentials();
    logger.debug("Read in credentials AWSAccessKeyId={} AWSSecretKey={}...", credentials.getAWSAccessKeyId(),
            credentials.getAWSSecretKey().substring(0, 4));

    // Create the glacier client and set to specified region.
    glacierClient = new AmazonGlacierClient(credentials);
    glacierClient.setEndpoint("https://glacier." + region + ".amazonaws.com");

    // Set up params needed for retrieving vault inventory
    sqsClient = new AmazonSQSClient(credentials);
    sqsClient.setEndpoint("https://sqs." + region + ".amazonaws.com");
    snsClient = new AmazonSNSClient(credentials);
    snsClient.setEndpoint("https://sns." + region + ".amazonaws.com");

    // Create the ArchiveTransferManager used for uploading and 
    // downloading files. Need to use ArchiveTransferManager constructor 
    // that allows one to specify sqsClient & snsClient so that they have
    // the proper region. If use ArchiveTransferManager without specifying
    // sqs and sns clients then default ones are constructed, but these
    // use the default Virginia region, which is wrong.
    atm = new ArchiveTransferManager(glacierClient, sqsClient, snsClient);
}

From source file:org.transitime.maintenance.AwsGlacierInventoryRetriever.java

License:Open Source License

/********************** Member Functions **************************/

public AwsGlacierInventoryRetriever(String region) {
    // Get credentials from credentials file, environment variable, or 
    // Java property. 
    // See http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html
    AWSCredentialsProviderChain credentialsProvider = new DefaultAWSCredentialsProviderChain();
    AWSCredentials credentials = credentialsProvider.getCredentials();
    logger.debug("Read in credentials AWSAccessKeyId={} AWSSecretKey={}...", credentials.getAWSAccessKeyId(),
            credentials.getAWSSecretKey().substring(0, 4));

    // Create the glacier client and set to specified region.
    glacierClient = new AmazonGlacierClient(credentials);
    glacierClient.setEndpoint("https://glacier." + region + ".amazonaws.com");

    // Set up params needed for retrieving vault inventory
    sqsClient = new AmazonSQSClient(credentials);
    sqsClient.setEndpoint("https://sqs." + region + ".amazonaws.com");
    snsClient = new AmazonSNSClient(credentials);
    snsClient.setEndpoint("https://sns." + region + ".amazonaws.com");
    setupSQS();/* w  ww.j a v a2 s . c  om*/
    setupSNS();
}

From source file:org.zalando.stups.fullstop.ExtPropertiesFileConfiguration.java

License:Apache License

public ExtPropertiesFileConfiguration(final Properties prop) {
    this(prop, new DefaultAWSCredentialsProviderChain());
}

From source file:producer.SensorReadingProducer.java

License:Open Source License

private void run(final int events, final OutputFormat format, final String streamName, final String region)
        throws Exception {
    AmazonKinesis kinesisClient = new AmazonKinesisClient(new DefaultAWSCredentialsProviderChain());
    kinesisClient.setRegion(Region.getRegion(Regions.fromName(region)));
    int count = 0;
    SensorReading r = null;//w  w w. j av a  2s .  c  om
    do {
        r = nextSensorReading(format);

        try {
            PutRecordRequest req = new PutRecordRequest().withPartitionKey("" + rand.nextLong())
                    .withStreamName(streamName).withData(ByteBuffer.wrap(r.toString().getBytes()));
            kinesisClient.putRecord(req);
        } catch (ProvisionedThroughputExceededException e) {
            Thread.sleep(BACKOFF);
        }

        System.out.println(r);
        count++;
    } while (count < events);
}