List of usage examples for com.amazonaws.auth AWSCredentialsProvider getCredentials
public AWSCredentials getCredentials();
From source file:io.druid.storage.s3.S3StorageDruidModule.java
License:Apache License
@Provides @LazySingleton/*from ww w. ja v a2s .c om*/ public RestS3Service getRestS3Service(AWSCredentialsProvider provider) { if (provider.getCredentials() instanceof com.amazonaws.auth.AWSSessionCredentials) { return new RestS3Service(new AWSSessionCredentialsAdapter(provider)); } else { return new RestS3Service(new AWSCredentials(provider.getCredentials().getAWSAccessKeyId(), provider.getCredentials().getAWSSecretKey())); } }
From source file:ohnosequences.ivy.S3Repository.java
License:Apache License
public S3Repository(String accessKey, String secretKey, boolean overwrite, Region region, CannedAccessControlList acl, boolean serverSideEncryption) { AWSCredentialsProvider provider = new InstanceProfileCredentialsProvider(); try {//from w w w.ja v a 2s . c o m provider.getCredentials(); } catch (AmazonClientException e1) { provider = new StaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)); } s3Client = new AmazonS3Client(provider); this.overwrite = overwrite; this.region = region; this.acl = acl; this.serverSideEncryption = serverSideEncryption; }
From source file:org.apache.hadoop.fs.s3a.AWSCredentialProviderList.java
License:Apache License
/** * Iterate through the list of providers, to find one with credentials. * If {@link #reuseLastProvider} is true, then it is re-used. * @return a set of credentials (possibly anonymous), for authenticating. *///from www . j a v a2 s . co m @Override public AWSCredentials getCredentials() { checkNotEmpty(); if (reuseLastProvider && lastProvider != null) { return lastProvider.getCredentials(); } AmazonClientException lastException = null; for (AWSCredentialsProvider provider : providers) { try { AWSCredentials credentials = provider.getCredentials(); if ((credentials.getAWSAccessKeyId() != null && credentials.getAWSSecretKey() != null) || (credentials instanceof AnonymousAWSCredentials)) { lastProvider = provider; LOG.debug("Using credentials from {}", provider); return credentials; } } catch (AmazonClientException e) { lastException = e; LOG.debug("No credentials provided by {}: {}", provider, e.toString(), e); } } // no providers had any credentials. Rethrow the last exception // or create a new one. String message = "No AWS Credentials provided by " + listProviderNames(); if (lastException != null) { message += ": " + lastException; } throw new AmazonClientException(message, lastException); }
From source file:org.apache.storm.s3.output.UploaderFactory.java
License:Apache License
public static Uploader buildUploader(Map conf) { Protocol protocol = Protocol.HTTPS;/*from ww w .ja va 2 s .co m*/ String proxy = null; int proxyPort = 0; if (conf.containsKey(S3_PROTOCOL)) { protocol = Protocol.valueOf((String) conf.get(S3_PROTOCOL)); } if (conf.containsKey(S3_PROXY)) { proxy = (String) conf.get(S3_PROXY); } if (conf.containsKey(S3_PROXY_PORT)) { proxyPort = ((Long) conf.get(S3_PROXY_PORT)).intValue(); } AWSCredentialsProvider provider = new DefaultAWSCredentialsProviderChain(); AWSCredentials credentials = provider.getCredentials(); ClientConfiguration config = new ClientConfiguration().withProtocol(protocol); if (proxy != null) { config.withProxyHost(proxy); } if (proxyPort != 0) { config.withProxyPort(proxyPort); } AmazonS3 client = new AmazonS3Client(credentials, config); if (conf.containsKey(S3_ENDPOINT)) { client.setEndpoint((String) conf.get(S3_ENDPOINT)); } return getUploader(conf, client); }
From source file:org.selman.tweetamo.TweetamoServer.java
License:Apache License
private static void configure(String propertiesFile) throws IOException { if (propertiesFile != null) { loadProperties(propertiesFile);//from w ww . j a v a 2 s .com } // ensure the JVM will refresh the cached IP values of AWS resources (e.g. service endpoints). java.security.Security.setProperty("networkaddress.cache.ttl", "60"); String workerId = InetAddress.getLocalHost().getCanonicalHostName() + ":" + UUID.randomUUID(); LOG.info("Using workerId: " + workerId); // Get credentials from IMDS. If unsuccessful, get them from the classpath. AWSCredentialsProvider credentialsProvider = null; try { credentialsProvider = new InstanceProfileCredentialsProvider(); // Verify we can fetch credentials from the provider credentialsProvider.getCredentials(); LOG.info("Obtained credentials from the IMDS."); } catch (AmazonClientException e) { LOG.info("Unable to obtain credentials from the IMDS, trying classpath properties", e); credentialsProvider = new ClasspathPropertiesFileCredentialsProvider(); // Verify we can fetch credentials from the provider credentialsProvider.getCredentials(); LOG.info("Obtained credentials from the properties file."); } LOG.info("Using credentials with access key id: " + credentialsProvider.getCredentials().getAWSAccessKeyId()); kinesisClientLibConfiguration = new KinesisClientLibConfiguration(applicationName, streamName, credentialsProvider, workerId); }