Example usage for com.amazonaws.internal StaticCredentialsProvider StaticCredentialsProvider

List of usage examples for com.amazonaws.internal StaticCredentialsProvider StaticCredentialsProvider

Introduction

In this page you can find the example usage for com.amazonaws.internal StaticCredentialsProvider StaticCredentialsProvider.

Prototype

public StaticCredentialsProvider(AWSCredentials credentials) 

Source Link

Usage

From source file:com.github.sjones4.youcan.youtwo.YouTwoClient.java

License:Open Source License

public YouTwoClient(final AWSCredentials awsCredentials, final ClientConfiguration clientConfiguration) {
    this(new StaticCredentialsProvider(awsCredentials), clientConfiguration);
}

From source file:com.ivona.services.tts.IvonaSpeechCloudClient.java

License:Open Source License

/**
 * Constructor which allows custom ClientConfiguration and AWSCredentials to be passed.
 *
 * @param awsCredentials/* w ww  .ja  va2  s .c o  m*/
 * @param clientConfiguration
 */
public IvonaSpeechCloudClient(AWSCredentials awsCredentials, ClientConfiguration clientConfiguration) {
    super(clientConfiguration);
    this.awsCredentialsProvider = new StaticCredentialsProvider(awsCredentials);
    init();
}

From source file:com.liferay.portal.store.s3.S3Store.java

License:Open Source License

protected AWSCredentialsProvider getAWSCredentialsProvider() {
    if (Validator.isNotNull(_s3StoreConfiguration.accessKey())
            && Validator.isNotNull(_s3StoreConfiguration.secretKey())) {

        AWSCredentials awsCredentials = new BasicAWSCredentials(_s3StoreConfiguration.accessKey(),
                _s3StoreConfiguration.secretKey());

        return new StaticCredentialsProvider(awsCredentials);
    }/*from www.j  av a  2s . com*/

    return new DefaultAWSCredentialsProviderChain();
}

From source file:com.noctarius.hazelcast.aws.HazelcastAwsDiscoveryStrategy.java

License:Open Source License

private AWSCredentialsProvider buildCredentialsProvider() {
    String accessKey = getOrNull(AwsProperties.ACCESS_KEY);
    String secretKey = getOrNull(AwsProperties.SECRET_KEY);

    if (accessKey == null && secretKey == null) {
        return new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(),
                new SystemPropertiesCredentialsProvider(), new InstanceProfileCredentialsProvider());
    }//from   w  w  w. java 2 s  .  com

    return new AWSCredentialsProviderChain(
            new StaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)));
}

From source file:com.numenta.taurus.service.TaurusClient.java

License:Open Source License

/**
 * Construct Taurus API client.//from   w w w.  j  a  v a  2 s  .  co  m
 *
 * @param provider  The AWS credential provider to use.
 *                  Usually {@link TaurusApplication#getAWSCredentialProvider()}
 * @param serverUrl DynamoDB Server. Use "http://10.0.2.2:8300" for local server or
 *                  null for AWS
 */
public TaurusClient(AWSCredentialsProvider provider, String serverUrl) {
    _server = serverUrl;
    AWSCredentialsProvider credentialsProvider = provider;
    if (credentialsProvider == null) {
        // Use Dummy credentials for local server
        credentialsProvider = new StaticCredentialsProvider(new AWSCredentials() {
            public String getAWSAccessKeyId() {
                // Returns dummy value
                return "taurus";
            }

            @Override
            public String getAWSSecretKey() {
                // Returns dummy value
                return "taurus";
            }
        });
    }
    _awsClient = new AmazonDynamoDBClient(credentialsProvider);
    if (BuildConfig.REGION != null) {
        // Override default region
        _awsClient.setRegion(Region.getRegion(Regions.fromName(BuildConfig.REGION)));
    }
    if (_server != null) {
        // Override server endpoint, Usually the local DynamoDB server
        _awsClient.setEndpoint(_server);
    }
}

From source file:com.rapid7.diskstorage.dynamodb.Client.java

License:Open Source License

public Client(com.thinkaurelius.titan.diskstorage.configuration.Configuration config) {
    String credentialsClassName = config.get(Constants.DYNAMODB_CREDENTIALS_CLASS_NAME);
    Class<?> clazz;/*w  w w .j a v  a 2  s.  c  o m*/
    try {
        clazz = Class.forName(credentialsClassName);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(VALIDATE_CREDENTIALS_CLASS_NAME, e);
    }

    String[] credentialsConstructorArgsValues = config.get(Constants.DYNAMODB_CREDENTIALS_CONSTRUCTOR_ARGS);
    final List<String> filteredArgList = new ArrayList<String>();
    for (Object obj : credentialsConstructorArgsValues) {
        final String str = obj.toString();
        if (!str.isEmpty()) {
            filteredArgList.add(str);
        }
    }

    AWSCredentialsProvider credentialsProvider;
    if (AWSCredentials.class.isAssignableFrom(clazz)) {
        AWSCredentials credentials = createCredentials(clazz,
                filteredArgList.toArray(new String[filteredArgList.size()]));
        credentialsProvider = new StaticCredentialsProvider(credentials);
    } else if (AWSCredentialsProvider.class.isAssignableFrom(clazz)) {
        credentialsProvider = createCredentialsProvider(clazz, credentialsConstructorArgsValues);
    } else {
        throw new IllegalArgumentException(VALIDATE_CREDENTIALS_CLASS_NAME);
    }
    //begin adaptation of constructor at
    //https://github.com/buka/titan/blob/master/src/main/java/com/thinkaurelius/titan/diskstorage/dynamodb/DynamoDBClient.java#L77
    ClientConfiguration clientConfig = new ClientConfiguration();
    clientConfig.withConnectionTimeout(config.get(Constants.DYNAMODB_CLIENT_CONN_TIMEOUT)) //
            .withConnectionTTL(config.get(Constants.DYNAMODB_CLIENT_CONN_TTL)) //
            .withMaxConnections(config.get(Constants.DYNAMODB_CLIENT_MAX_CONN)) //
            .withMaxErrorRetry(config.get(Constants.DYNAMODB_CLIENT_MAX_ERROR_RETRY)) //
            .withGzip(config.get(Constants.DYNAMODB_CLIENT_USE_GZIP)) //
            .withReaper(config.get(Constants.DYNAMODB_CLIENT_USE_REAPER)) //
            .withUserAgent(config.get(Constants.DYNAMODB_CLIENT_USER_AGENT)) //
            .withSocketTimeout(config.get(Constants.DYNAMODB_CLIENT_SOCKET_TIMEOUT)) //
            .withSocketBufferSizeHints( //
                    config.get(Constants.DYNAMODB_CLIENT_SOCKET_BUFFER_SEND_HINT), //
                    config.get(Constants.DYNAMODB_CLIENT_SOCKET_BUFFER_RECV_HINT)) //
            .withProxyDomain(config.get(Constants.DYNAMODB_CLIENT_PROXY_DOMAIN)) //
            .withProxyWorkstation(config.get(Constants.DYNAMODB_CLIENT_PROXY_WORKSTATION)) //
            .withProxyHost(config.get(Constants.DYNAMODB_CLIENT_PROXY_HOST)) //
            .withProxyPort(config.get(Constants.DYNAMODB_CLIENT_PROXY_PORT)) //
            .withProxyUsername(config.get(Constants.DYNAMODB_CLIENT_PROXY_USERNAME)) //
            .withProxyPassword(config.get(Constants.DYNAMODB_CLIENT_PROXY_PASSWORD)); //

    forceConsistentRead = config.get(Constants.DYNAMODB_FORCE_CONSISTENT_READ);
    //end adaptation of constructor at
    //https://github.com/buka/titan/blob/master/src/main/java/com/thinkaurelius/titan/diskstorage/dynamodb/DynamoDBClient.java#L77
    enableParallelScan = config.get(Constants.DYNAMODB_ENABLE_PARALLEL_SCAN);
    prefix = config.get(Constants.DYNAMODB_TABLE_PREFIX);
    final String metricsPrefix = config.get(Constants.DYNAMODB_METRICS_PREFIX);

    final long maxRetries = config.get(Constants.DYNAMODB_MAX_SELF_THROTTLED_RETRIES);
    if (maxRetries < 0) {
        throw new IllegalArgumentException(
                Constants.DYNAMODB_MAX_SELF_THROTTLED_RETRIES.getName() + " must be at least 0");
    }
    final long retryMillis = config.get(Constants.DYNAMODB_INITIAL_RETRY_MILLIS);
    if (retryMillis <= 0) {
        throw new IllegalArgumentException(
                Constants.DYNAMODB_INITIAL_RETRY_MILLIS.getName() + " must be at least 1");
    }
    final double controlPlaneRate = config.get(Constants.DYNAMODB_CONTROL_PLANE_RATE);
    if (controlPlaneRate < 0) {
        throw new IllegalArgumentException("must have a positive control plane rate");
    }
    final RateLimiter controlPlaneRateLimiter = RateLimiter.create(controlPlaneRate);

    final Map<String, RateLimiter> readRateLimit = new HashMap<>();
    final Map<String, RateLimiter> writeRateLimit = new HashMap<>();

    Set<String> storeNames = new HashSet<String>(Constants.REQUIRED_BACKEND_STORES);
    storeNames.addAll(config.getContainedNamespaces(Constants.DYNAMODB_STORES_NAMESPACE));
    for (String storeName : storeNames) {
        setupStore(config, prefix, readRateLimit, writeRateLimit, storeName);
    }

    endpoint = TitanConfigUtil.getNullableConfigValue(config, Constants.DYNAMODB_CLIENT_ENDPOINT);
    delegate = new DynamoDBDelegate(endpoint, credentialsProvider, clientConfig, config, readRateLimit,
            writeRateLimit, maxRetries, retryMillis, prefix, metricsPrefix, controlPlaneRateLimiter);
}

From source file:com.rapid7.diskstorage.dynamodb.Client.java

License:Open Source License

public static final AWSCredentialsProvider createAWSCredentialsProvider(String credentialsClassName,
        String[] credentialsConstructorArgsValues) {
    Class<?> clazz;/*from   w  w  w  . jav a 2s  .  c o m*/
    try {
        clazz = Class.forName(credentialsClassName);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(VALIDATE_CREDENTIALS_CLASS_NAME, e);
    }
    AWSCredentialsProvider credentialsProvider;
    if (AWSCredentials.class.isAssignableFrom(clazz)) {
        AWSCredentials credentials = createCredentials(clazz, credentialsConstructorArgsValues);
        credentialsProvider = new StaticCredentialsProvider(credentials);
    } else if (AWSCredentialsProvider.class.isAssignableFrom(clazz)) {
        credentialsProvider = createCredentialsProvider(clazz, credentialsConstructorArgsValues);
    } else {
        throw new IllegalArgumentException(VALIDATE_CREDENTIALS_CLASS_NAME);
    }

    return credentialsProvider;
}

From source file:com.streamsets.datacollector.bundles.SupportBundleManager.java

License:Apache License

/**
 * Instead of providing support bundle directly to user, upload it to StreamSets backend services.
 *///w  ww.  ja  v  a 2  s.  co  m
public void uploadNewBundleFromInstances(List<BundleContentGenerator> generators, BundleType bundleType)
        throws IOException {
    // Generate bundle
    SupportBundle bundle = generateNewBundleFromInstances(generators, bundleType);

    boolean enabled = configuration.get(Constants.UPLOAD_ENABLED, Constants.DEFAULT_UPLOAD_ENABLED);
    String accessKey = configuration.get(Constants.UPLOAD_ACCESS, Constants.DEFAULT_UPLOAD_ACCESS);
    String secretKey = configuration.get(Constants.UPLOAD_SECRET, Constants.DEFAULT_UPLOAD_SECRET);
    String bucket = configuration.get(Constants.UPLOAD_BUCKET, Constants.DEFAULT_UPLOAD_BUCKET);
    int bufferSize = configuration.get(Constants.UPLOAD_BUFFER_SIZE, Constants.DEFAULT_UPLOAD_BUFFER_SIZE);

    if (!enabled) {
        throw new IOException("Uploading support bundles was disabled by administrator.");
    }

    AWSCredentialsProvider credentialsProvider = new StaticCredentialsProvider(
            new BasicAWSCredentials(accessKey, secretKey));
    AmazonS3Client s3Client = new AmazonS3Client(credentialsProvider, new ClientConfiguration());
    s3Client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true));
    s3Client.setRegion(Region.getRegion(Regions.US_WEST_2));

    // Object Metadata
    ObjectMetadata s3Metadata = new ObjectMetadata();
    for (Map.Entry<Object, Object> entry : getMetadata(bundleType).entrySet()) {
        s3Metadata.addUserMetadata((String) entry.getKey(), (String) entry.getValue());
    }

    List<PartETag> partETags;
    InitiateMultipartUploadResult initResponse = null;
    try {
        // Uploading part by part
        LOG.info("Initiating multi-part support bundle upload");
        partETags = new ArrayList<>();
        InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(bucket,
                bundle.getBundleKey());
        initRequest.setObjectMetadata(s3Metadata);
        initResponse = s3Client.initiateMultipartUpload(initRequest);
    } catch (AmazonClientException e) {
        LOG.error("Support bundle upload failed: ", e);
        throw new IOException("Support bundle upload failed", e);
    }

    try {
        byte[] buffer = new byte[bufferSize];
        int partId = 1;
        int size = -1;
        while ((size = readFully(bundle.getInputStream(), buffer)) != -1) {
            LOG.debug("Uploading part {} of size {}", partId, size);
            UploadPartRequest uploadRequest = new UploadPartRequest().withBucketName(bucket)
                    .withKey(bundle.getBundleKey()).withUploadId(initResponse.getUploadId())
                    .withPartNumber(partId++).withInputStream(new ByteArrayInputStream(buffer))
                    .withPartSize(size);

            partETags.add(s3Client.uploadPart(uploadRequest).getPartETag());
        }

        CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest(bucket,
                bundle.getBundleKey(), initResponse.getUploadId(), partETags);

        s3Client.completeMultipartUpload(compRequest);
        LOG.info("Support bundle upload finished");
    } catch (Exception e) {
        LOG.error("Support bundle upload failed", e);
        s3Client.abortMultipartUpload(
                new AbortMultipartUploadRequest(bucket, bundle.getBundleKey(), initResponse.getUploadId()));

        throw new IOException("Can't upload support bundle", e);
    } finally {
        // Close the client
        s3Client.shutdown();
    }
}

From source file:com.streamsets.pipeline.stage.lib.aws.AWSUtil.java

License:Apache License

public static AWSCredentialsProvider getCredentialsProvider(AWSConfig config) {
    AWSCredentialsProvider credentialsProvider;
    if (!config.awsAccessKeyId.isEmpty() && !config.awsSecretAccessKey.isEmpty()) {
        credentialsProvider = new StaticCredentialsProvider(
                new BasicAWSCredentials(config.awsAccessKeyId, config.awsSecretAccessKey));
    } else {//from w  w w. ja  v a 2  s  .c  om
        credentialsProvider = new DefaultAWSCredentialsProviderChain();
    }
    return credentialsProvider;
}

From source file:com.tremolosecurity.provisioning.jms.providers.AwsSqsConnectionFactory.java

License:Apache License

@Override
public Connection createConnection() throws JMSException {
    Builder builder = null;//from  w  w w. j  ava 2s . c  o m

    if (this.accessKey == null || this.accessKey.isEmpty()) {
        builder = SQSConnectionFactory.builder();
    } else {
        builder = SQSConnectionFactory.builder().withAWSCredentialsProvider(
                new StaticCredentialsProvider(new BasicAWSCredentials(this.accessKey, this.secretKey)));
    }

    if (this.regionName != null && !this.regionName.isEmpty()) {
        builder = builder.withRegionName(regionName);
    }

    this.factory = builder.build();

    return factory.createConnection();
}