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.hiveTown.util.AmazonSESUtil.java

License:Open Source License

private AmazonSimpleEmailServiceClient getClient() {

    BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

    // Instantiate an Amazon SES client, which will make the service call with the supplied AWS credentials.
    AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials);
    Region REGION = Region.getRegion(Regions.US_WEST_2);
    client.setRegion(REGION);//from w w w .ja  v  a2s  . co m
    return client;
}

From source file:com.hpe.caf.worker.datastore.s3.S3DataStore.java

License:Apache License

public S3DataStore(final S3DataStoreConfiguration s3DataStoreConfiguration) {
    if (s3DataStoreConfiguration == null) {
        throw new ArgumentException("s3DataStoreConfiguration was null.");
    }/*from  w w w.java2 s  . c o  m*/

    ClientConfiguration clientCfg = new ClientConfiguration();

    if (!StringUtils.isNullOrEmpty(s3DataStoreConfiguration.getProxyHost())) {
        clientCfg.setProtocol(Protocol.valueOf(s3DataStoreConfiguration.getProxyProtocol()));
        clientCfg.setProxyHost(s3DataStoreConfiguration.getProxyHost());
        clientCfg.setProxyPort(s3DataStoreConfiguration.getProxyPort());
    }
    AWSCredentials credentials = new BasicAWSCredentials(s3DataStoreConfiguration.getAccessKey(),
            s3DataStoreConfiguration.getSecretKey());
    bucketName = s3DataStoreConfiguration.getBucketName();
    amazonS3Client = new AmazonS3Client(credentials, clientCfg);
    amazonS3Client.setBucketAccelerateConfiguration(new SetBucketAccelerateConfigurationRequest(bucketName,
            new BucketAccelerateConfiguration(BucketAccelerateStatus.Enabled)));
}

From source file:com.ibm.connectors.AmazonSQS.AmazonSQSInputConnector.java

License:Open Source License

@Override
public void poll(long waitInterval) {
    Properties properties = new Properties();

    String access_key_id = getProperty("AccessKeyId");
    String secret_access_key = getProperty("SecretAccessKey");
    BasicAWSCredentials credentials = new BasicAWSCredentials(access_key_id, secret_access_key);

    AmazonSQS sqs = new AmazonSQSClient(credentials);

    // Region selection
    Region region = Region.getRegion(Regions.fromName(getProperty("region")));
    sqs.setRegion(region);/*  ww  w  .  j a va2  s . c  om*/

    GetQueueUrlResult queueUrl = sqs.getQueueUrl(getProperty("Queue"));

    ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueUrl.getQueueUrl());
    List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();

    String outputMessage = "";
    // if there are messages then do the processing
    if (messages.size() > 0) {

        //append the message properties to the localenv tree
        for (Message message : messages) {
            properties.setProperty("MessageId", message.getMessageId());
            properties.setProperty("ReceiptHandle", message.getReceiptHandle());
            properties.setProperty("MD5OfBody", message.getMD5OfBody());
            // get the message body to a string
            outputMessage = message.getBody();
        }
        properties.setProperty("queueUrl", queueUrl.getQueueUrl());
        // delete the message from the queue
        String messageReceiptHandle = messages.get(0).getReceiptHandle();
        sqs.deleteMessage(new DeleteMessageRequest(queueUrl.getQueueUrl(), messageReceiptHandle));
        ConnectorCallback callback = getCallback();
        callback.processInboundData(outputMessage.getBytes(), properties);
    }
}

From source file:com.ibm.connectors.AmazonSQS.AmazonSQSOutputInteraction.java

License:Open Source License

@Override
public Properties send(Properties properties, Object message) throws ConnectorException {

    String access_key_id = properties.getProperty("AccessKeyId");
    String secret_access_key = properties.getProperty("SecretAccessKey");
    BasicAWSCredentials credentials = new BasicAWSCredentials(access_key_id, secret_access_key);

    AmazonSQS sqs = new AmazonSQSClient(credentials);
    //System.out.println(properties.getProperty("region"));
    // Region selection
    Region region = Region.getRegion(Regions.fromName(properties.getProperty("region")));
    sqs.setRegion(region);//from   w  w w .j  av  a 2  s .  c o  m

    GetQueueUrlResult queueUrl = sqs.getQueueUrl(properties.getProperty("Queue"));
    String messageStr = new String((byte[]) message);

    sqs.sendMessage(new SendMessageRequest(queueUrl.getQueueUrl(), messageStr));

    return properties;
}

From source file:com.ibm.og.s3.v2.AWSV2Auth.java

License:Open Source License

@Override
public AuthenticatedRequest authenticate(final Request request) {
    checkNotNull(request);/* w w  w .j  a v  a2 s  . com*/
    final String accessKeyId = checkNotNull(request.getContext().get(Context.X_OG_USERNAME));
    final String secretAccessKey = checkNotNull(request.getContext().get(Context.X_OG_PASSWORD));
    final AWSCredentials credentials = new BasicAWSCredentials(accessKeyId, secretAccessKey);

    final AuthenticatedHttpRequest authenticatedRequest = new AuthenticatedHttpRequest(request);
    final SignableRequest<Request> signableRequest = new SignableRequestAdapter(authenticatedRequest);

    final S3Signer signer = new S3Signer(signableRequest.getHttpMethod().toString(),
            signableRequest.getResourcePath());

    signer.sign(signableRequest, credentials);

    return authenticatedRequest;
}

From source file:com.ibm.og.s3.v4.AWSV4Auth.java

License:Open Source License

@Override
public AuthenticatedRequest authenticate(final Request request) {
    checkNotNull(request);//from  ww w  .java  2 s. c om
    final String accessKeyId = checkNotNull(request.getContext().get(Context.X_OG_USERNAME));
    final String secretAccessKey = checkNotNull(request.getContext().get(Context.X_OG_PASSWORD));
    final AWSCredentials credentials = new BasicAWSCredentials(accessKeyId, secretAccessKey);

    final AWSS3V4Signer signer = new AWSS3V4Signer(this.chunkedEncoding, this.digestCache);
    signer.setServiceName("s3");

    final AuthenticatedHttpRequest authenticatedRequest = new AuthenticatedHttpRequest(request);
    final SignableRequest<Request> signableRequest = new SignableRequestAdapter(authenticatedRequest);

    signer.sign(signableRequest, credentials);

    return authenticatedRequest;
}

From source file:com.ibm.stocator.fs.cos.COSAPIClient.java

License:Apache License

@Override
public void initiate(String scheme) throws IOException, ConfigurationParseException {
    mCachedSparkOriginated = new HashMap<String, Boolean>();
    mCachedSparkJobsStatus = new HashMap<String, Boolean>();
    schemaProvided = scheme;/*from   w  ww.  j  ava 2s  .  c  o m*/
    Properties props = ConfigurationHandler.initialize(filesystemURI, conf, scheme);
    // Set bucket name property
    int cacheSize = conf.getInt(CACHE_SIZE, GUAVA_CACHE_SIZE_DEFAULT);
    memoryCache = MemoryCache.getInstance(cacheSize);
    mBucket = props.getProperty(COS_BUCKET_PROPERTY);
    workingDir = new Path("/user", System.getProperty("user.name")).makeQualified(filesystemURI,
            getWorkingDirectory());

    fModeAutomaticDelete = "true".equals(props.getProperty(FMODE_AUTOMATIC_DELETE_COS_PROPERTY, "false"));
    mIsV2Signer = "true".equals(props.getProperty(V2_SIGNER_TYPE_COS_PROPERTY, "false"));
    // Define COS client
    String accessKey = props.getProperty(ACCESS_KEY_COS_PROPERTY);
    String secretKey = props.getProperty(SECRET_KEY_COS_PROPERTY);

    if (accessKey == null) {
        throw new ConfigurationParseException("Access KEY is empty. Please provide valid access key");
    }
    if (secretKey == null) {
        throw new ConfigurationParseException("Secret KEY is empty. Please provide valid secret key");
    }

    BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
    ClientConfiguration clientConf = new ClientConfiguration();

    int maxThreads = Utils.getInt(conf, FS_COS, FS_ALT_KEYS, MAX_THREADS, DEFAULT_MAX_THREADS);
    if (maxThreads < 2) {
        LOG.warn(MAX_THREADS + " must be at least 2: forcing to 2.");
        maxThreads = 2;
    }
    int totalTasks = Utils.getInt(conf, FS_COS, FS_ALT_KEYS, MAX_TOTAL_TASKS, DEFAULT_MAX_TOTAL_TASKS);
    long keepAliveTime = Utils.getLong(conf, FS_COS, FS_ALT_KEYS, KEEPALIVE_TIME, DEFAULT_KEEPALIVE_TIME);
    threadPoolExecutor = BlockingThreadPoolExecutorService.newInstance(maxThreads, maxThreads + totalTasks,
            keepAliveTime, TimeUnit.SECONDS, "s3a-transfer-shared");

    unboundedThreadPool = new ThreadPoolExecutor(maxThreads, Integer.MAX_VALUE, keepAliveTime, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(),
            BlockingThreadPoolExecutorService.newDaemonThreadFactory("s3a-transfer-unbounded"));

    boolean secureConnections = Utils.getBoolean(conf, FS_COS, FS_ALT_KEYS, SECURE_CONNECTIONS,
            DEFAULT_SECURE_CONNECTIONS);
    clientConf.setProtocol(secureConnections ? Protocol.HTTPS : Protocol.HTTP);

    String proxyHost = Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, PROXY_HOST, "");
    int proxyPort = Utils.getInt(conf, FS_COS, FS_ALT_KEYS, PROXY_PORT, -1);
    if (!proxyHost.isEmpty()) {
        clientConf.setProxyHost(proxyHost);
        if (proxyPort >= 0) {
            clientConf.setProxyPort(proxyPort);
        } else {
            if (secureConnections) {
                LOG.warn("Proxy host set without port. Using HTTPS default 443");
                clientConf.setProxyPort(443);
            } else {
                LOG.warn("Proxy host set without port. Using HTTP default 80");
                clientConf.setProxyPort(80);
            }
        }
        String proxyUsername = Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, PROXY_USERNAME);
        String proxyPassword = Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, PROXY_PASSWORD);
        if ((proxyUsername == null) != (proxyPassword == null)) {
            String msg = "Proxy error: " + PROXY_USERNAME + " or " + PROXY_PASSWORD + " set without the other.";
            LOG.error(msg);
            throw new IllegalArgumentException(msg);
        }
        clientConf.setProxyUsername(proxyUsername);
        clientConf.setProxyPassword(proxyPassword);
        clientConf.setProxyDomain(Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, PROXY_DOMAIN));
        clientConf.setProxyWorkstation(Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, PROXY_WORKSTATION));
        if (LOG.isDebugEnabled()) {
            LOG.debug(
                    "Using proxy server {}:{} as user {} with password {} on " + "domain {} as workstation {}",
                    clientConf.getProxyHost(), clientConf.getProxyPort(),
                    String.valueOf(clientConf.getProxyUsername()), clientConf.getProxyPassword(),
                    clientConf.getProxyDomain(), clientConf.getProxyWorkstation());
        }
    } else if (proxyPort >= 0) {
        String msg = "Proxy error: " + PROXY_PORT + " set without " + PROXY_HOST;
        LOG.error(msg);
        throw new IllegalArgumentException(msg);
    }

    initConnectionSettings(conf, clientConf);
    if (mIsV2Signer) {
        clientConf.withSignerOverride("S3SignerType");
    }
    mClient = new AmazonS3Client(creds, clientConf);

    final String serviceUrl = props.getProperty(ENDPOINT_URL_COS_PROPERTY);
    if (serviceUrl != null && !serviceUrl.equals(amazonDefaultEndpoint)) {
        mClient.setEndpoint(serviceUrl);
    }
    mClient.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build());

    // Set block size property
    String mBlockSizeString = props.getProperty(BLOCK_SIZE_COS_PROPERTY, "128");
    mBlockSize = Long.valueOf(mBlockSizeString).longValue() * 1024 * 1024L;

    boolean autoCreateBucket = "true"
            .equalsIgnoreCase((props.getProperty(AUTO_BUCKET_CREATE_COS_PROPERTY, "false")));

    partSize = Utils.getLong(conf, FS_COS, FS_ALT_KEYS, MULTIPART_SIZE, DEFAULT_MULTIPART_SIZE);
    multiPartThreshold = Utils.getLong(conf, FS_COS, FS_ALT_KEYS, MIN_MULTIPART_THRESHOLD,
            DEFAULT_MIN_MULTIPART_THRESHOLD);
    readAhead = Utils.getLong(conf, FS_COS, FS_ALT_KEYS, READAHEAD_RANGE, DEFAULT_READAHEAD_RANGE);
    LOG.debug(READAHEAD_RANGE + ":" + readAhead);
    inputPolicy = COSInputPolicy
            .getPolicy(Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, INPUT_FADVISE, INPUT_FADV_NORMAL));

    initTransferManager();
    maxKeys = Utils.getInt(conf, FS_COS, FS_ALT_KEYS, MAX_PAGING_KEYS, DEFAULT_MAX_PAGING_KEYS);
    flatListingFlag = Utils.getBoolean(conf, FS_COS, FS_ALT_KEYS, FLAT_LISTING, DEFAULT_FLAT_LISTING);

    if (autoCreateBucket) {
        try {
            boolean bucketExist = mClient.doesBucketExist(mBucket);
            if (bucketExist) {
                LOG.trace("Bucket {} exists", mBucket);
            } else {
                LOG.trace("Bucket {} doesn`t exists and autocreate", mBucket);
                String mRegion = props.getProperty(REGION_COS_PROPERTY);
                if (mRegion == null) {
                    mClient.createBucket(mBucket);
                } else {
                    LOG.trace("Creating bucket {} in region {}", mBucket, mRegion);
                    mClient.createBucket(mBucket, mRegion);
                }
            }
        } catch (AmazonServiceException ase) {
            /*
            *  we ignore the BucketAlreadyExists exception since multiple processes or threads
            *  might try to create the bucket in parrallel, therefore it is expected that
            *  some will fail to create the bucket
            */
            if (!ase.getErrorCode().equals("BucketAlreadyExists")) {
                LOG.error(ase.getMessage());
                throw (ase);
            }
        } catch (Exception e) {
            LOG.error(e.getMessage());
            throw (e);
        }
    }

    initMultipartUploads(conf);
    enableMultiObjectsDelete = Utils.getBoolean(conf, FS_COS, FS_ALT_KEYS, ENABLE_MULTI_DELETE, true);

    blockUploadEnabled = Utils.getBoolean(conf, FS_COS, FS_ALT_KEYS, FAST_UPLOAD, DEFAULT_FAST_UPLOAD);

    if (blockUploadEnabled) {
        blockOutputBuffer = Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, FAST_UPLOAD_BUFFER,
                DEFAULT_FAST_UPLOAD_BUFFER);
        partSize = COSUtils.ensureOutputParameterInRange(MULTIPART_SIZE, partSize);
        blockFactory = COSDataBlocks.createFactory(this, blockOutputBuffer);
        blockOutputActiveBlocks = Utils.getInt(conf, FS_COS, FS_ALT_KEYS, FAST_UPLOAD_ACTIVE_BLOCKS,
                DEFAULT_FAST_UPLOAD_ACTIVE_BLOCKS);
        LOG.debug("Using COSBlockOutputStream with buffer = {}; block={};" + " queue limit={}",
                blockOutputBuffer, partSize, blockOutputActiveBlocks);
    } else {
        LOG.debug("Using COSOutputStream");
    }
}

From source file:com.igeekinc.indelible.indeliblefs.uniblock.casstore.s3.S3CASStore.java

License:Open Source License

protected void initInternal() {
    credentials = new BasicAWSCredentials(accessKey, secretKey);
    s3Client = new AmazonS3Client(credentials);
    List<Bucket> bucketList = s3Client.listBuckets();

    for (Bucket checkBucket : bucketList) {
        if (checkBucket.getName().equals(storeID.toString())) {
            return; // It already exists
        }/*  w  w w  . j  a va 2s.  com*/
    }
    if (region != null)
        s3Client.createBucket(storeID.toString(), region); // storeID's should be globally unique so we don't worry about bucket name collisions
    else
        s3Client.createBucket(storeID.toString());
}

From source file:com.ikanow.infinit.e.harvest.extraction.document.file.AwsInfiniteFile.java

License:Open Source License

public AwsInfiniteFile(String url, NtlmPasswordAuthentication auth) throws IOException {
    BasicAWSCredentials awsAuth = new BasicAWSCredentials(auth.getUsername(), auth.getPassword());
    AmazonS3Client client = new AmazonS3Client(awsAuth);
    _awsClient = (Object) client;

    getBucketAndObjectName(url, false);//  w w w.java 2  s.c o  m
}

From source file:com.images3.data.impl.AmazonS3ClientPool.java

License:Apache License

private AmazonS3 createAmazonS3Client(String accessKey, String secretKey) {
    return new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));
}