Example usage for com.amazonaws.auth AWSStaticCredentialsProvider AWSStaticCredentialsProvider

List of usage examples for com.amazonaws.auth AWSStaticCredentialsProvider AWSStaticCredentialsProvider

Introduction

In this page you can find the example usage for com.amazonaws.auth AWSStaticCredentialsProvider AWSStaticCredentialsProvider.

Prototype

public AWSStaticCredentialsProvider(AWSCredentials credentials) 

Source Link

Usage

From source file:ca.paullalonde.gocd.sns_plugin.executors.StageStatusRequestExecutor.java

License:Apache License

private AmazonSNS makeSns(PluginSettings pluginSettings) throws Exception {
    String region = pluginSettings.getRegion();
    String awsAccessId = pluginSettings.getAwsAccessId();
    String awsSecretId = pluginSettings.getAwsSecretAccessId();
    AmazonSNSClientBuilder builder = AmazonSNSClientBuilder.standard();

    if ((region != null) && !region.isEmpty()) {
        builder = builder.withRegion(region);
    }//from  ww  w.  j  ava 2  s .  c o  m

    if ((awsAccessId != null) && !awsAccessId.isEmpty() && (awsSecretId != null) && !awsSecretId.isEmpty()) {
        BasicAWSCredentials awsCreds = new BasicAWSCredentials(awsAccessId, awsSecretId);
        builder = builder.withCredentials(new AWSStaticCredentialsProvider(awsCreds));
    }

    return builder.build();
}

From source file:ch.cyberduck.core.cloudfront.CloudFrontDistributionConfiguration.java

License:Open Source License

private AmazonCloudFront client(final Path container) throws BackgroundException {
    return AmazonCloudFrontClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(new com.amazonaws.auth.AWSCredentials() {
                @Override/* w w  w.  j a  v a 2 s.co m*/
                public String getAWSAccessKeyId() {
                    return bookmark.getCredentials().getUsername();
                }

                @Override
                public String getAWSSecretKey() {
                    return bookmark.getCredentials().getPassword();
                }
            })).withClientConfiguration(configuration)
            .withRegion(locationFeature.getLocation(container).getIdentifier()).build();
}

From source file:ch.myniva.gradle.caching.s3.internal.AwsS3BuildCacheServiceFactory.java

License:Apache License

private AmazonS3 createS3Client(AwsS3BuildCache config) {
    AmazonS3 s3;/*from ww  w . j a v  a2 s . com*/
    try {
        AmazonS3ClientBuilder s3Builder = AmazonS3ClientBuilder.standard();
        if (!isNullOrEmpty(config.getAwsAccessKeyId()) && !isNullOrEmpty(config.getAwsSecretKey())) {
            s3Builder.withCredentials(new AWSStaticCredentialsProvider(
                    new BasicAWSCredentials(config.getAwsAccessKeyId(), config.getAwsSecretKey())));
        }
        if (isNullOrEmpty(config.getEndpoint())) {
            s3Builder.withRegion(config.getRegion());
        } else {
            s3Builder.withEndpointConfiguration(
                    new AwsClientBuilder.EndpointConfiguration(config.getEndpoint(), config.getRegion()));
        }
        s3 = s3Builder.build();
    } catch (SdkClientException e) {
        logger.debug("Error while building AWS S3 client: {}", e.getMessage());
        throw new GradleException("Creation of S3 build cache failed; cannot create S3 client", e);
    }
    return s3;
}

From source file:com.adeptj.modules.aws.core.AwsUtil.java

License:Apache License

public static AWSCredentialsProvider getCredentialsProvider(String accessKey, String secretKey) {
    return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey));
}

From source file:com.amazon.janusgraph.diskstorage.dynamodb.Client.java

License:Open Source License

public Client(final Configuration config) {
    final String credentialsClassName = config.get(Constants.DYNAMODB_CREDENTIALS_CLASS_NAME);
    final Class<?> clazz;
    try {//from   w  w  w.j  a va2  s.  c o  m
        clazz = Class.forName(credentialsClassName);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(VALIDATE_CREDENTIALS_CLASS_NAME, e);
    }

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

    final AWSCredentialsProvider credentialsProvider;
    if (AWSCredentials.class.isAssignableFrom(clazz)) {
        final AWSCredentials credentials = createCredentials(clazz,
                filteredArgList.toArray(new String[filteredArgList.size()]));
        credentialsProvider = new AWSStaticCredentialsProvider(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
    final 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))
            .withUserAgentSuffix(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);
    Preconditions.checkArgument(maxRetries >= 0,
            Constants.DYNAMODB_MAX_SELF_THROTTLED_RETRIES.getName() + " must be at least 0");

    final long retryMillis = config.get(Constants.DYNAMODB_INITIAL_RETRY_MILLIS);
    Preconditions.checkArgument(retryMillis > 0,
            Constants.DYNAMODB_INITIAL_RETRY_MILLIS.getName() + " must be at least 1");

    final double controlPlaneRate = config.get(Constants.DYNAMODB_CONTROL_PLANE_RATE);
    Preconditions.checkArgument(controlPlaneRate >= 0, "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<>();

    final Set<String> storeNames = new HashSet<>(Constants.REQUIRED_BACKEND_STORES);
    storeNames.add(config.get(GraphDatabaseConfiguration.IDS_STORE_NAME));
    storeNames.addAll(config.getContainedNamespaces(Constants.DYNAMODB_STORES_NAMESPACE));
    storeNames.forEach(storeName -> setupStore(config, readRateLimit, writeRateLimit, storeName));

    delegate = new DynamoDbDelegate(
            JanusGraphConfigUtil.getNullableConfigValue(config, Constants.DYNAMODB_CLIENT_ENDPOINT),
            JanusGraphConfigUtil.getNullableConfigValue(config, Constants.DYNAMODB_CLIENT_SIGNING_REGION),
            credentialsProvider, clientConfig, config, readRateLimit, writeRateLimit, maxRetries, retryMillis,
            prefix, metricsPrefix, controlPlaneRateLimiter);
}

From source file:com.att.aro.core.cloud.aws.AwsRepository.java

License:Apache License

private void constructRepo(String accessId, String secretKey, String region, String bucketName,
        ClientConfiguration config) {//  w ww .j  a v a 2 s . co m
    System.setProperty("java.net.useSystemProxies", "true");
    if (isNotBlank(accessId) && isNotBlank(secretKey) && isNotBlank(region) && isNotBlank(bucketName)) {
        try {
            AWSCredentials creds = new BasicAWSCredentials(accessId, secretKey);
            Regions regions = Regions.fromName(region);
            this.bucketName = bucketName;
            s3Client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds))
                    .withRegion(regions).withClientConfiguration(config).build();
            transferMgr = TransferManagerBuilder.standard().withS3Client(s3Client).build();
        } catch (IllegalArgumentException ille) {
            LOGGER.error(ille.getMessage(), ille);
        } catch (Exception exp) {
            LOGGER.error(exp.getMessage(), exp);
        }
    }
}

From source file:com.cloudbees.jenkins.plugins.awscredentials.AWSCredentialsImpl.java

License:Open Source License

public AWSCredentials getCredentials() {
    AWSCredentials initialCredentials = new BasicAWSCredentials(accessKey, secretKey.getPlainText());

    if (StringUtils.isBlank(iamRoleArn)) {
        return initialCredentials;
    } else {//from w  w  w.j a  v a  2  s .co  m
        // Check for available region from the SDK, otherwise specify default
        String clientRegion = null;
        DefaultAwsRegionProviderChain sdkRegionLookup = new DefaultAwsRegionProviderChain();
        try {
            clientRegion = sdkRegionLookup.getRegion();
        } catch (com.amazonaws.SdkClientException e) {
            LOGGER.log(Level.WARNING, "Could not find default region using SDK lookup.", e);
        }
        if (clientRegion == null) {
            clientRegion = Regions.DEFAULT_REGION.getName();
        }

        AWSSecurityTokenService client;
        // Handle the case of delegation to instance profile
        if (StringUtils.isBlank(accessKey) && StringUtils.isBlank(secretKey.getPlainText())) {
            client = AWSSecurityTokenServiceClientBuilder.standard().withRegion(clientRegion).build();
        } else {
            client = AWSSecurityTokenServiceClientBuilder.standard()
                    .withCredentials(new AWSStaticCredentialsProvider(initialCredentials))
                    .withRegion(clientRegion).build();
        }

        AssumeRoleRequest assumeRequest = createAssumeRoleRequest(iamRoleArn)
                .withDurationSeconds(this.getStsTokenDuration());

        AssumeRoleResult assumeResult = client.assumeRole(assumeRequest);

        return new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(),
                assumeResult.getCredentials().getSecretAccessKey(),
                assumeResult.getCredentials().getSessionToken());
    }
}

From source file:com.emc.vipr.s3.sample.AWSS3Factory.java

License:Open Source License

public static AmazonS3 getS3Client() {
    BasicAWSCredentials creds = new BasicAWSCredentials(S3_ACCESS_KEY_ID, S3_SECRET_KEY);

    ClientConfiguration cc = new ClientConfiguration();
    //cc.setProxyHost("localhost");
    //cc.setProxyPort(8888);

    // Force use of v2 Signer.
    cc.setSignerOverride("S3SignerType");

    AmazonS3 client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds))
            .withClientConfiguration(cc).withPathStyleAccessEnabled(true) // Path-style bucket naming is highly recommended
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(S3_ENDPOINT, null)).build();

    return client;
}

From source file:com.facebook.presto.hive.s3.PrestoS3ClientFactory.java

License:Apache License

private AWSCredentialsProvider getAwsCredentialsProvider(Configuration conf, HiveS3Config defaults) {
    Optional<AWSCredentials> credentials = getAwsCredentials(conf);
    if (credentials.isPresent()) {
        return new AWSStaticCredentialsProvider(credentials.get());
    }/*  w  w  w .j av  a  2s . co m*/

    boolean useInstanceCredentials = conf.getBoolean(S3_USE_INSTANCE_CREDENTIALS,
            defaults.isS3UseInstanceCredentials());
    if (useInstanceCredentials) {
        return InstanceProfileCredentialsProvider.getInstance();
    }

    String providerClass = conf.get(S3_CREDENTIALS_PROVIDER);
    if (!isNullOrEmpty(providerClass)) {
        return getCustomAWSCredentialsProvider(conf, providerClass);
    }

    throw new RuntimeException("S3 credentials not configured");
}

From source file:com.facebook.presto.hive.s3.PrestoS3FileSystem.java

License:Apache License

private AWSCredentialsProvider getAwsCredentialsProvider(URI uri, Configuration conf) {
    Optional<AWSCredentials> credentials = getAwsCredentials(uri, conf);
    if (credentials.isPresent()) {
        return new AWSStaticCredentialsProvider(credentials.get());
    }/*ww  w . j a va  2 s  .  co m*/

    if (useInstanceCredentials) {
        return new InstanceProfileCredentialsProvider();
    }

    String providerClass = conf.get(S3_CREDENTIALS_PROVIDER);
    if (!isNullOrEmpty(providerClass)) {
        return getCustomAWSCredentialsProvider(uri, conf, providerClass);
    }

    throw new RuntimeException("S3 credentials not configured");
}