List of usage examples for com.amazonaws.internal StaticCredentialsProvider StaticCredentialsProvider
public StaticCredentialsProvider(AWSCredentials credentials)
From source file:org.elasticsearch.cloud.aws.AwsS3Service.java
License:Apache License
private synchronized AmazonS3 getClient(String endpoint, String account, String key) { Tuple<String, String> clientDescriptor = new Tuple<String, String>(endpoint, account); AmazonS3Client client = clients.get(clientDescriptor); if (client != null) { return client; }//w w w . j a v a 2 s . c om ClientConfiguration clientConfiguration = new ClientConfiguration(); String protocol = componentSettings.get("protocol", "http").toLowerCase(); if ("http".equals(protocol)) { clientConfiguration.setProtocol(Protocol.HTTP); } else if ("https".equals(protocol)) { clientConfiguration.setProtocol(Protocol.HTTPS); } else { throw new ElasticsearchIllegalArgumentException( "No protocol supported [" + protocol + "], can either be [http] or [https]"); } String proxyHost = componentSettings.get("proxy_host"); if (proxyHost != null) { String portString = componentSettings.get("proxy_port", "80"); Integer proxyPort; try { proxyPort = Integer.parseInt(portString, 10); } catch (NumberFormatException ex) { throw new ElasticsearchIllegalArgumentException( "The configured proxy port value [" + portString + "] is invalid", ex); } clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort); } AWSCredentialsProvider credentials; if (account == null && key == null) { credentials = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new InstanceProfileCredentialsProvider()); } else { credentials = new AWSCredentialsProviderChain( new StaticCredentialsProvider(new BasicAWSCredentials(account, key))); } client = new AmazonS3Client(credentials, clientConfiguration); if (endpoint != null) { client.setEndpoint(endpoint); } clients.put(clientDescriptor, client); return client; }
From source file:org.elasticsearch.cloud.aws.InternalAwsS3Service.java
License:Apache License
private synchronized AmazonS3 getClient(String endpoint, String protocol, String account, String key, Integer maxRetries) {//from w ww .j ava 2s .co m Tuple<String, String> clientDescriptor = new Tuple<String, String>(endpoint, account); AmazonS3Client client = clients.get(clientDescriptor); if (client != null) { return client; } ClientConfiguration clientConfiguration = new ClientConfiguration(); // the response metadata cache is only there for diagnostics purposes, // but can force objects from every response to the old generation. clientConfiguration.setResponseMetadataCacheSize(0); if (protocol == null) { protocol = settings.get("cloud.aws.protocol", "https").toLowerCase(); protocol = settings.get("cloud.aws.s3.protocol", protocol).toLowerCase(); } if ("http".equals(protocol)) { clientConfiguration.setProtocol(Protocol.HTTP); } else if ("https".equals(protocol)) { clientConfiguration.setProtocol(Protocol.HTTPS); } else { throw new IllegalArgumentException( "No protocol supported [" + protocol + "], can either be [http] or [https]"); } String proxyHost = settings.get("cloud.aws.proxy_host"); proxyHost = settings.get("cloud.aws.s3.proxy_host", proxyHost); if (proxyHost != null) { String portString = settings.get("cloud.aws.proxy_port", "80"); portString = settings.get("cloud.aws.s3.proxy_port", portString); Integer proxyPort; try { proxyPort = Integer.parseInt(portString, 10); } catch (NumberFormatException ex) { throw new IllegalArgumentException( "The configured proxy port value [" + portString + "] is invalid", ex); } clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort); } if (maxRetries != null) { // If not explicitly set, default to 3 with exponential backoff policy clientConfiguration.setMaxErrorRetry(maxRetries); } // #155: we might have 3rd party users using older S3 API version String awsSigner = settings.get("cloud.aws.s3.signer", settings.get("cloud.aws.signer")); if (awsSigner != null) { logger.debug("using AWS API signer [{}]", awsSigner); try { AwsSigner.configureSigner(awsSigner, clientConfiguration); } catch (IllegalArgumentException e) { logger.warn("wrong signer set for [cloud.aws.s3.signer] or [cloud.aws.signer]: [{}]", awsSigner); } } AWSCredentialsProvider credentials; if (account == null && key == null) { credentials = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new InstanceProfileCredentialsProvider()); } else { credentials = new AWSCredentialsProviderChain( new StaticCredentialsProvider(new BasicAWSCredentials(account, key))); } client = new AmazonS3Client(credentials, clientConfiguration); if (endpoint != null) { client.setEndpoint(endpoint); } clients.put(clientDescriptor, client); return client; }
From source file:org.elasticsearch.discovery.ec2.AwsEc2ServiceImpl.java
License:Apache License
protected static AWSCredentialsProvider buildCredentials(Logger logger, Settings settings) { AWSCredentialsProvider credentials;//from www. ja v a2s . c om try (SecureString key = ACCESS_KEY_SETTING.get(settings); SecureString secret = SECRET_KEY_SETTING.get(settings)) { if (key.length() == 0 && secret.length() == 0) { logger.debug( "Using either environment variables, system properties or instance profile credentials"); credentials = new DefaultAWSCredentialsProviderChain(); } else { logger.debug("Using basic key/secret credentials"); credentials = new StaticCredentialsProvider( new BasicAWSCredentials(key.toString(), secret.toString())); } } return credentials; }
From source file:org.elasticsearch.repositories.s3.InternalAwsS3Service.java
License:Apache License
static AWSCredentialsProvider buildCredentials(Logger logger, DeprecationLogger deprecationLogger, S3ClientSettings clientSettings, Settings repositorySettings) { BasicAWSCredentials credentials = clientSettings.credentials; if (S3Repository.ACCESS_KEY_SETTING.exists(repositorySettings)) { if (S3Repository.SECRET_KEY_SETTING.exists(repositorySettings) == false) { throw new IllegalArgumentException("Repository setting [" + S3Repository.ACCESS_KEY_SETTING.getKey() + " must be accompanied by setting [" + S3Repository.SECRET_KEY_SETTING.getKey() + "]"); }//from www. j a va2s. c o m try (SecureString key = S3Repository.ACCESS_KEY_SETTING.get(repositorySettings); SecureString secret = S3Repository.SECRET_KEY_SETTING.get(repositorySettings)) { credentials = new BasicAWSCredentials(key.toString(), secret.toString()); } // backcompat for reading keys out of repository settings deprecationLogger.deprecated("Using s3 access/secret key from repository settings. Instead " + "store these in named clients and the elasticsearch keystore for secure settings."); } else if (S3Repository.SECRET_KEY_SETTING.exists(repositorySettings)) { throw new IllegalArgumentException("Repository setting [" + S3Repository.SECRET_KEY_SETTING.getKey() + " must be accompanied by setting [" + S3Repository.ACCESS_KEY_SETTING.getKey() + "]"); } if (credentials == null) { logger.debug("Using instance profile credentials"); return new PrivilegedInstanceProfileCredentialsProvider(); } else { logger.debug("Using basic key/secret credentials"); return new StaticCredentialsProvider(credentials); } }
From source file:org.elasticsearch.repositories.s3.S3Service.java
License:Apache License
static AWSCredentialsProvider buildCredentials(Logger logger, S3ClientSettings clientSettings) { final AWSCredentials credentials = clientSettings.credentials; if (credentials == null) { logger.debug("Using instance profile credentials"); return new PrivilegedInstanceProfileCredentialsProvider(); } else {//from w ww. j a v a 2s. c o m logger.debug("Using basic key/secret credentials"); return new StaticCredentialsProvider(credentials); } }
From source file:org.eluder.logback.ext.aws.core.AwsSupport.java
License:Open Source License
public AWSCredentialsProvider getCredentials(AWSCredentials credentials) { return new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new StaticCredentialsProvider(credentials == null ? new NullCredentials() : credentials), new ProfileCredentialsProvider(), new InstanceProfileCredentialsProvider()); }
From source file:org.finra.dm.dao.impl.S3DaoImpl.java
License:Apache License
/** * <p> Gets the {@link AWSCredentialsProvider} based on the credentials in the given parameters. </p> <p> Returns {@link DefaultAWSCredentialsProviderChain} * if either access or secret key is {@code null}. Otherwise returns a {@link StaticCredentialsProvider} with the credentials. </p> * * @param params - Access parameters/*from w w w. java 2 s . c om*/ * * @return AWS credentials provider implementation */ private AWSCredentialsProvider getAWSCredentialsProvider(S3FileTransferRequestParamsDto params) { AWSCredentialsProvider awsCredentialsProvider = new DefaultAWSCredentialsProviderChain(); String accessKey = params.getS3AccessKey(); String secretKey = params.getS3SecretKey(); if (accessKey != null && secretKey != null) { awsCredentialsProvider = new StaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)); } return awsCredentialsProvider; }
From source file:org.finra.herd.dao.impl.S3DaoImpl.java
License:Apache License
/** * <p> Gets the {@link AWSCredentialsProvider} based on the credentials in the given parameters. </p> <p> Returns {@link DefaultAWSCredentialsProviderChain} * if either access or secret key is {@code null}. Otherwise returns a {@link StaticCredentialsProvider} with the credentials. </p> * * @param params - Access parameters//from www . java 2 s .c o m * * @return AWS credentials provider implementation */ private AWSCredentialsProvider getAWSCredentialsProvider(S3FileTransferRequestParamsDto params) { List<AWSCredentialsProvider> providers = new ArrayList<>(); String accessKey = params.getAwsAccessKeyId(); String secretKey = params.getAwsSecretKey(); if (accessKey != null && secretKey != null) { providers.add(new StaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey))); } for (HerdAWSCredentialsProvider herdAWSCredentialsProvider : params .getAdditionalAwsCredentialsProviders()) { providers.add(new HerdAwsCredentialsProviderWrapper(herdAWSCredentialsProvider)); } providers.add(new DefaultAWSCredentialsProviderChain()); return new AWSCredentialsProviderChain(providers.toArray(new AWSCredentialsProvider[providers.size()])); }
From source file:org.talend.components.s3.runtime.S3Connection.java
License:Open Source License
public static AmazonS3 createClient(S3OutputProperties properties) { S3DatasetProperties data_set = properties.getDatasetProperties(); S3DatastoreProperties data_store = properties.getDatasetProperties().getDatastoreProperties(); com.amazonaws.auth.AWSCredentials credentials = new com.amazonaws.auth.BasicAWSCredentials( data_store.accessKey.getValue(), data_store.secretKey.getValue()); Region region = RegionUtils.getRegion(data_set.region.getValue().getValue()); Boolean clientSideEnc = data_set.encryptDataInMotion.getValue(); AmazonS3 conn = null;/*from www .j a v a 2 s . co m*/ if (clientSideEnc != null && clientSideEnc) { String kms_cmk = data_set.kmsForDataInMotion.getValue(); KMSEncryptionMaterialsProvider encryptionMaterialsProvider = new KMSEncryptionMaterialsProvider( kms_cmk); conn = new AmazonS3EncryptionClient(credentials, encryptionMaterialsProvider, new CryptoConfiguration().withAwsKmsRegion(region)); } else { AWSCredentialsProvider basicCredentialsProvider = new StaticCredentialsProvider(credentials); conn = new AmazonS3Client(basicCredentialsProvider); } conn.setRegion(region); return conn; }