List of usage examples for com.amazonaws ClientConfiguration ClientConfiguration
public ClientConfiguration()
From source file:org.finra.dm.dao.impl.Ec2DaoImpl.java
License:Apache License
/** * Create the EC2 client with the given proxy and access key details This is the main AmazonEC2Client object * * @param awsParamsDto AWS related parameters for access/secret keys and proxy details * * @return the AmazonEC2Client object/*from w w w. j ava 2 s . co m*/ */ @Override public AmazonEC2Client getEc2Client(AwsParamsDto awsParamsDto) { // TODO Building EC2 client every time requested, if this becomes a performance issue, // might need to consider storing a singleton or building the client once per request. AmazonEC2Client ec2Client = null; // Create an EC2 client with HTTP proxy information. if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost()) && awsParamsDto.getHttpProxyPort() != null) { ec2Client = new AmazonEC2Client(new ClientConfiguration().withProxyHost(awsParamsDto.getHttpProxyHost()) .withProxyPort(awsParamsDto.getHttpProxyPort())); } // Create an EC2 client with no proxy information else { ec2Client = new AmazonEC2Client(); } // Return the client. return ec2Client; }
From source file:org.finra.dm.dao.impl.EmrDaoImpl.java
License:Apache License
/** * Create the EMR client with the given proxy and access key details. * * @param awsParamsDto AWS related parameters for access/secret keys and proxy details. * * @return the AmazonElasticMapReduceClient object. *//* w w w .j ava 2s. com*/ @Override public AmazonElasticMapReduceClient getEmrClient(AwsParamsDto awsParamsDto) { // TODO Building EMR client every time requested, if this becomes a performance issue, // might need to consider storing a singleton or building the client once per request. AmazonElasticMapReduceClient emrClient; // Create an EMR client with HTTP proxy information. if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost()) && StringUtils.isNotBlank(awsParamsDto.getHttpProxyPort().toString())) { emrClient = new AmazonElasticMapReduceClient(new ClientConfiguration() .withProxyHost(awsParamsDto.getHttpProxyHost()).withProxyPort(awsParamsDto.getHttpProxyPort())); } // Create an EMR client with no proxy information else { emrClient = new AmazonElasticMapReduceClient(); } // Return the client. return emrClient; }
From source file:org.finra.dm.dao.impl.S3DaoImpl.java
License:Apache License
/** * Gets a new S3 client based on the specified parameters. The HTTP proxy information will be added if the host and port are specified in the parameters. * * @param params the parameters.//from w w w . j a v a 2 s . c o m * * @return the Amazon S3 client. */ private AmazonS3Client getAmazonS3(S3FileTransferRequestParamsDto params) { AmazonS3Client amazonS3Client; AWSCredentialsProvider awsCredentialsProvider = getAWSCredentialsProvider(params); if (StringUtils.isNotBlank(params.getHttpProxyHost()) && StringUtils.isNotBlank(params.getHttpProxyPort().toString())) { // Create an S3 client with HTTP proxy information. amazonS3Client = new AmazonS3Client(awsCredentialsProvider, new ClientConfiguration() .withProxyHost(params.getHttpProxyHost()).withProxyPort(params.getHttpProxyPort())); } else { // Create an S3 client with no proxy information. amazonS3Client = new AmazonS3Client(awsCredentialsProvider); } // Set the optional endpoint if configured. if (StringUtils.isNotBlank(params.getS3Endpoint())) { LOGGER.info("Configured S3 Endpoint: " + params.getS3Endpoint()); amazonS3Client.setEndpoint(params.getS3Endpoint()); } // Return the newly created client. return amazonS3Client; }
From source file:org.finra.dm.dao.impl.SqsDaoImpl.java
License:Apache License
/** * Sends a text message to the specified AWS SQS queue. *///w w w .j a va 2 s . c o m @Override public void sendSqsTextMessage(AwsParamsDto awsParamsDto, String queueName, String messageText) { // Create the connection factory based on the specified proxy configuration. ClientConfiguration clientConfiguration = new ClientConfiguration(); // Only set the proxy hostname and/or port if they're configured. if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost())) { clientConfiguration.setProxyHost(awsParamsDto.getHttpProxyHost()); } if (awsParamsDto.getHttpProxyPort() != null) { clientConfiguration.setProxyPort(awsParamsDto.getHttpProxyPort()); } // Send the message. sqsOperations.sendSqsTextMessage(clientConfiguration, queueName, messageText); }
From source file:org.finra.dm.dao.impl.StsDaoImpl.java
License:Apache License
/** * Returns a set of temporary security credentials (consisting of an access key ID, a secret access key, and a security token) that can be used to access * the specified AWS resource.// ww w .j a v a 2 s .c o m * * @param sessionName the session name that will be associated with the temporary credentials. The session name must be the same for an initial set of * credentials and an extended set of credentials if credentials are to be refreshed. The session name also is used to identify the user in AWS logs so it * should be something unique and useful to identify the caller/use. * @param awsRoleArn the AWS ARN for the role required to provide access to the specified AWS resource * @param awsRoleDurationSeconds the duration, in seconds, of the role session. The value can range from 900 seconds (15 minutes) to 3600 seconds (1 hour). * @param policy the temporary policy to apply to this request * * @return the assumed session credentials */ @Override public Credentials getTemporarySecurityCredentials(AwsParamsDto awsParamsDto, String sessionName, String awsRoleArn, int awsRoleDurationSeconds, Policy policy) { // Construct a new AWS security token service client using the specified client configuration to access Amazon S3. // A credentials provider chain will be used that searches for credentials in this order: // - Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY // - Java System Properties - aws.accessKeyId and aws.secretKey // - Instance Profile Credentials - delivered through the Amazon EC2 metadata service ClientConfiguration clientConfiguration = new ClientConfiguration(); // Only set the proxy hostname and/or port if they're configured. if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost())) { clientConfiguration.setProxyHost(awsParamsDto.getHttpProxyHost()); } if (awsParamsDto.getHttpProxyPort() != null) { clientConfiguration.setProxyPort(awsParamsDto.getHttpProxyPort()); } AWSSecurityTokenServiceClient awsSecurityTokenServiceClient = new AWSSecurityTokenServiceClient( clientConfiguration); // Create the request. AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest(); assumeRoleRequest.setRoleSessionName(sessionName); assumeRoleRequest.setRoleArn(awsRoleArn); assumeRoleRequest.setDurationSeconds(awsRoleDurationSeconds); assumeRoleRequest.setPolicy(policy.toJson()); // Get the temporary security credentials. AssumeRoleResult assumeRoleResult = stsOperations.assumeRole(awsSecurityTokenServiceClient, assumeRoleRequest); return assumeRoleResult.getCredentials(); }
From source file:org.finra.dm.service.config.ServiceSpringModuleConfig.java
License:Apache License
/** * Gets a JMS connection factory./*w ww . ja v a2 s . c o m*/ * * @return the JMS connection factory. */ @Bean public ConnectionFactory jmsConnectionFactory() { AwsParamsDto awsParamsDto = awsHelper.getAwsParamsDto(); ClientConfiguration clientConfiguration = new ClientConfiguration(); // Only set the proxy hostname and/or port if they're configured. if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost())) { clientConfiguration.setProxyHost(awsParamsDto.getHttpProxyHost()); } if (awsParamsDto.getHttpProxyPort() != null) { clientConfiguration.setProxyPort(awsParamsDto.getHttpProxyPort()); } return SQSConnectionFactory.builder().withClientConfiguration(clientConfiguration).build(); }
From source file:org.finra.herd.dao.helper.AwsHelper.java
License:Apache License
/** * Creates a client configuration object that contains client configuration options such as proxy settings and max retry attempts. * * @param awsParamsDto the AWS related parameters that contain optional proxy information * * @return the client configuration object */// w ww. java 2 s. com public ClientConfiguration getClientConfiguration(AwsParamsDto awsParamsDto) { ClientConfiguration clientConfiguration = new ClientConfiguration(); // Set a retry policy. clientConfiguration.withRetryPolicy(retryPolicyFactory.getRetryPolicy()); // If the proxy hostname and port both are configured, set the HTTP proxy information. if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost()) && awsParamsDto.getHttpProxyPort() != null) { clientConfiguration.withProxyHost(awsParamsDto.getHttpProxyHost()) .withProxyPort(awsParamsDto.getHttpProxyPort()); } return clientConfiguration; }
From source file:org.finra.herd.dao.impl.S3DaoImpl.java
License:Apache License
/** * Gets a new S3 client based on the specified parameters. The HTTP proxy information will be added if the host and port are specified in the parameters. * * @param params the parameters.// w w w . j a va2 s . c o m * * @return the Amazon S3 client. */ private AmazonS3Client getAmazonS3(S3FileTransferRequestParamsDto params) { AmazonS3Client amazonS3Client; ClientConfiguration clientConfiguration = new ClientConfiguration() .withRetryPolicy(retryPolicyFactory.getRetryPolicy()); // Set the proxy configuration, if proxy is specified. if (StringUtils.isNotBlank(params.getHttpProxyHost()) && params.getHttpProxyPort() != null) { clientConfiguration.setProxyHost(params.getHttpProxyHost()); clientConfiguration.setProxyPort(params.getHttpProxyPort()); } // Sign all S3 API's with V4 signing. // AmazonS3Client.upgradeToSigV4 already has some scenarios where it will "upgrade" the signing approach to use V4 if not already present (e.g. // GetObjectRequest and KMS PutObjectRequest), but setting it here (especially when KMS is used) will ensure it isn't missed when required (e.g. // copying objects between KMS encrypted buckets). Otherwise, AWS will return a bad request error and retry which isn't desirable. clientConfiguration.setSignerOverride(SIGNER_OVERRIDE_V4); // Set the optional socket timeout, if configured. if (params.getSocketTimeout() != null) { clientConfiguration.setSocketTimeout(params.getSocketTimeout()); } // Create an S3 client using passed in credentials and HTTP proxy information. if (StringUtils.isNotBlank(params.getAwsAccessKeyId()) && StringUtils.isNotBlank(params.getAwsSecretKey()) && StringUtils.isNotBlank(params.getSessionToken())) { // Create an S3 client using basic session credentials. amazonS3Client = new AmazonS3Client(new BasicSessionCredentials(params.getAwsAccessKeyId(), params.getAwsSecretKey(), params.getSessionToken()), clientConfiguration); } else { // Create an S3 client using AWS credentials provider. amazonS3Client = new AmazonS3Client(getAWSCredentialsProvider(params), clientConfiguration); } // Set the optional endpoint, if specified. if (StringUtils.isNotBlank(params.getS3Endpoint())) { LOGGER.info("Configured S3 Endpoint: " + params.getS3Endpoint()); amazonS3Client.setEndpoint(params.getS3Endpoint()); } // Return the newly created client. return amazonS3Client; }
From source file:org.finra.herd.dao.impl.StsDaoImpl.java
License:Apache License
/** * Returns a set of temporary security credentials (consisting of an access key ID, a secret access key, and a security token) that can be used to access * the specified AWS resource.//from w w w . jav a 2 s . c om * * @param sessionName the session name that will be associated with the temporary credentials. The session name must be the same for an initial set of * credentials and an extended set of credentials if credentials are to be refreshed. The session name also is used to identify the user in AWS logs so it * should be something unique and useful to identify the caller/use. * @param awsRoleArn the AWS ARN for the role required to provide access to the specified AWS resource * @param awsRoleDurationSeconds the duration, in seconds, of the role session. The value can range from 900 seconds (15 minutes) to 3600 seconds (1 hour). * @param policy the temporary policy to apply to this request * * @return the assumed session credentials */ @Override public Credentials getTemporarySecurityCredentials(AwsParamsDto awsParamsDto, String sessionName, String awsRoleArn, int awsRoleDurationSeconds, Policy policy) { // Construct a new AWS security token service client using the specified client configuration to access Amazon S3. // A credentials provider chain will be used that searches for credentials in this order: // - Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY // - Java System Properties - aws.accessKeyId and aws.secretKey // - Instance Profile Credentials - delivered through the Amazon EC2 metadata service ClientConfiguration clientConfiguration = new ClientConfiguration() .withRetryPolicy(retryPolicyFactory.getRetryPolicy()); // Only set the proxy hostname and/or port if they're configured. if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost())) { clientConfiguration.setProxyHost(awsParamsDto.getHttpProxyHost()); } if (awsParamsDto.getHttpProxyPort() != null) { clientConfiguration.setProxyPort(awsParamsDto.getHttpProxyPort()); } AWSSecurityTokenServiceClient awsSecurityTokenServiceClient = new AWSSecurityTokenServiceClient( clientConfiguration); // Create the request. AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest(); assumeRoleRequest.setRoleSessionName(sessionName); assumeRoleRequest.setRoleArn(awsRoleArn); assumeRoleRequest.setDurationSeconds(awsRoleDurationSeconds); if (policy != null) { assumeRoleRequest.setPolicy(policy.toJson()); } // Get the temporary security credentials. AssumeRoleResult assumeRoleResult = stsOperations.assumeRole(awsSecurityTokenServiceClient, assumeRoleRequest); return assumeRoleResult.getCredentials(); }
From source file:org.gaul.yass.MainActivity.java
License:Open Source License
static AmazonS3Client getS3Client(YassPreferences preferences) { BasicAWSCredentials awsCreds = new BasicAWSCredentials(preferences.accessKey, preferences.secretKey); AmazonS3Client client = new AmazonS3Client(awsCreds, new ClientConfiguration()); if (preferences.endpoint != null && !preferences.endpoint.isEmpty()) { client.setEndpoint(preferences.endpoint); }// w w w . ja va 2s . co m return client; }