Example usage for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials

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

Introduction

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

Prototype

public BasicAWSCredentials(String accessKey, String secretKey) 

Source Link

Document

Constructs a new BasicAWSCredentials object, with the specified AWS access key and AWS secret key.

Usage

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

License:Open Source License

public static ViPRS3Client getS3Client() {
    BasicAWSCredentials creds = new BasicAWSCredentials(S3_ACCESS_KEY_ID, S3_SECRET_KEY);
    ViPRS3Client client = new ViPRS3Client(S3_ENDPOINT, creds);

    if (S3_ViPR_NAMESPACE != null) {
        client.setNamespace(S3_ViPR_NAMESPACE);
    }/*from  ww  w.  j  a v  a2  s .  c  o m*/

    return client;
}

From source file:com.emc.vipr.services.s3.S3ClientFactory.java

License:Open Source License

private static ViPRS3Client getS3Client(boolean smart, boolean setNamespace) {
    try {//from w  w  w . j a v a 2s. c  o  m
        Properties props = ViprConfig.getProperties();

        String accessKey = ViprConfig.getPropertyNotEmpty(props, ViprConfig.PROP_S3_ACCESS_KEY_ID);
        String secretKey = ViprConfig.getPropertyNotEmpty(props, ViprConfig.PROP_S3_SECRET_KEY);
        String endpoint = ViprConfig.getPropertyNotEmpty(props, ViprConfig.PROP_S3_ENDPOINT);
        String endpoints = props.getProperty(ViprConfig.PROP_S3_ENDPOINTS);

        BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);

        ViPRS3Config viprConfig = new ViPRS3Config()
                .withCredentialsProvider(new StaticCredentialsProvider(creds));
        if (endpoints != null)
            viprConfig.withS3Endpoints(endpoints);
        else
            viprConfig.withS3Endpoints(endpoint);

        ViPRS3Client client = smart ? new ViPRS3Client(viprConfig) : new ViPRS3Client(endpoint, creds);

        String namespace = props.getProperty(ViprConfig.PROP_NAMESPACE);
        if (namespace != null && setNamespace) {
            client.setNamespace(namespace);
        }
        checkProxyConfig(client, props);

        return client;
    } catch (IOException e) {
        log.info("Failed to load properties: " + e);
        return null;
    }
}

From source file:com.emc.vipr.services.s3.S3ClientFactory.java

License:Open Source License

/**
 * Creates an EncryptionClient for testing.  Loads the public and private keys from
 * the properties file (not suitable for production).
 *
 * @return/*from www .  ja  v  a  2 s .c o m*/
 * @throws IOException
 */
public static AmazonS3EncryptionClient getEncryptionClient() throws IOException {
    try {
        Properties props = ViprConfig.getProperties();

        String accessKey = ViprConfig.getPropertyNotEmpty(props, ViprConfig.PROP_S3_ACCESS_KEY_ID);
        String secretKey = ViprConfig.getPropertyNotEmpty(props, ViprConfig.PROP_S3_SECRET_KEY);
        String endpoint = ViprConfig.getPropertyNotEmpty(props, ViprConfig.PROP_S3_ENDPOINT);
        String publicKey = ViprConfig.getPropertyNotEmpty(props, ViprConfig.PROP_PUBLIC_KEY);
        String privateKey = ViprConfig.getPropertyNotEmpty(props, ViprConfig.PROP_PRIVATE_KEY);

        byte[] pubKeyBytes = Base64.decodeBase64(publicKey.getBytes("US-ASCII"));
        byte[] privKeyBytes = Base64.decodeBase64(privateKey.getBytes("US-ASCII"));

        X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(pubKeyBytes);
        PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(privKeyBytes);

        PublicKey pubKey;
        PrivateKey privKey;
        try {
            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
            pubKey = keyFactory.generatePublic(pubKeySpec);
            privKey = keyFactory.generatePrivate(privKeySpec);
        } catch (GeneralSecurityException e) {
            throw new RuntimeException("Could not load key pair: " + e, e);
        }

        EncryptionMaterials keys = new EncryptionMaterials(new KeyPair(pubKey, privKey));

        BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
        AmazonS3EncryptionClient client = new AmazonS3EncryptionClient(creds, keys);
        client.setEndpoint(endpoint);

        checkProxyConfig(client, props);

        return client;
    } catch (Exception e) {
        log.info("Could not load configuration: " + e);
        return null;
    }
}

From source file:com.emc.vipr.sync.source.S3Source.java

License:Open Source License

@Override
public void configure(SyncSource source, Iterator<SyncFilter> filters, SyncTarget target) {
    Assert.hasText(accessKey, "accessKey is required");
    Assert.hasText(secretKey, "secretKey is required");
    Assert.hasText(bucketName, "bucketName is required");

    AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
    ClientConfiguration config = new ClientConfiguration();

    if (protocol != null)
        config.setProtocol(Protocol.valueOf(protocol.toUpperCase()));

    s3 = new AmazonS3Client(creds, config);

    if (endpoint != null)
        s3.setEndpoint(endpoint);//  w  w w.  j a  v  a  2 s. c o m

    if (disableVHosts) {
        l4j.info(
                "The use of virtual hosted buckets on the s3 source has been DISABLED.  Path style buckets will be used.");
        S3ClientOptions opts = new S3ClientOptions();
        opts.setPathStyleAccess(true);
        s3.setS3ClientOptions(opts);
    }

    if (!s3.doesBucketExist(bucketName)) {
        throw new ConfigurationException("The bucket " + bucketName + " does not exist.");
    }

    if (rootKey == null)
        rootKey = ""; // make sure rootKey isn't null
    if (rootKey.startsWith("/"))
        rootKey = rootKey.substring(1); // " " does not start with slash
}

From source file:com.epam.catgenome.manager.bam.BamHelper.java

License:Open Source License

private SamInputResource getS3Index(SamInputResource samInputResource, BiologicalDataItem indexFile) {
    Assert.notNull(indexFile.getBucketId(), getMessage(MessagesConstants.ERROR_S3_BUCKET));
    final Bucket bucket = bucketManager.loadBucket(indexFile.getBucketId());
    Assert.notNull(bucket, getMessage(MessagesConstants.ERROR_S3_BUCKET));
    final AmazonS3 s3Client = new AmazonS3Client(
            new BasicAWSCredentials(bucket.getAccessKeyId(), bucket.getSecretAccessKey()));
    return samInputResource.index(s3Client.generatePresignedUrl(bucket.getBucketName(), indexFile.getPath(),
            Utils.getTimeForS3URL()));
}

From source file:com.epam.catgenome.manager.bam.BamHelper.java

License:Open Source License

@NotNull
private SamInputResource getS3SamInputResource(BamFile bamFile) {
    final Bucket bucket = bucketManager.loadBucket(bamFile.getBucketId());
    Assert.notNull(bucket, getMessage(MessagesConstants.ERROR_S3_BUCKET));
    final AmazonS3 s3Client = new AmazonS3Client(
            new BasicAWSCredentials(bucket.getAccessKeyId(), bucket.getSecretAccessKey()));
    return SamInputResource.of(
            s3Client.generatePresignedUrl(bucket.getBucketName(), bamFile.getPath(), Utils.getTimeForS3URL()));
}

From source file:com.epam.dlab.automation.cloud.aws.AmazonHelper.java

License:Apache License

private static AWSCredentials getCredentials() {
    return new BasicAWSCredentials(ConfigPropertyValue.getAwsAccessKeyId(),
            ConfigPropertyValue.getAwsSecretAccessKey());
}

From source file:com.epam.dlab.module.aws.AdapterS3File.java

License:Apache License

/**
 * Creates and returns the Amazon client, as well as checks bucket existence.
 *
 * @throws AdapterException/*from  ww  w .  j  a  va 2  s  .  c om*/
 */
private AmazonS3 getAmazonClient() throws AdapterException {
    AmazonS3 s3 = (accessKeyId == null ? new AmazonS3Client()
            : new AmazonS3Client(new BasicAWSCredentials(accessKeyId, secretAccessKey)));

    if (!s3.doesBucketExist(bucket)) {
        throw new AdapterException("Bucket \"" + bucket + "\" does not exist.");
    }

    return s3;
}

From source file:com.er.sylvite.CustomEnvironmentVariableCredentialsProvider.java

License:Open Source License

@Override
public AWSCredentials getCredentials() {

    String prefix = System.getProperty(PREFIX_ENV_VAR, DEFAULT_PREFIX);

    String accessKeyEnvVar = prefix + "_" + ACCESS_KEY_ENV_VAR;
    String secretKeyEnvVar = prefix + "_" + SECRET_KEY_ENV_VAR;

    String accessKey = System.getenv(accessKeyEnvVar);
    String secretKey = System.getenv(secretKeyEnvVar);

    accessKey = StringUtils.trim(accessKey);
    secretKey = StringUtils.trim(secretKey);

    if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) {

        throw new AmazonClientException("Unable to load AWS credentials from environment variables " + "("
                + accessKeyEnvVar + " and " + secretKeyEnvVar + ")");
    }/*from   www .ja  v a2  s  . c o m*/

    return new BasicAWSCredentials(accessKey, secretKey);
}

From source file:com.erudika.para.email.AWSEmailer.java

License:Apache License

/**
 * No-args constructor.//from w  w w  . ja va2 s  .  c  o m
 */
public AWSEmailer() {
    sesclient = new AmazonSimpleEmailServiceClient(
            new BasicAWSCredentials(Config.AWS_ACCESSKEY, Config.AWS_SECRETKEY));
}