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.aegeus.aws.SimpleStorageService.java

License:Apache License

public SimpleStorageService(S3ConfigObject config) {
    this.config = config;

    s3 = new AmazonS3Client(new BasicAWSCredentials(config.getAccessKey(), config.getSecretKey()));
    s3.setRegion(Region.getRegion(Regions.fromName(config.getRegion())));
}

From source file:com.agilegroups.aws.services.AmazonEC2ServicesImpl.java

License:Apache License

@PostConstruct
public void init() {

    this.credentials = new BasicAWSCredentials(accessKey, secretKey);
    client = new AmazonEC2Client(this.credentials);

    //System.out.println("Here are the instanceIds: " + getInstanceIds());
    //LOG.info("Initialized [{}] [{}] [{}] [{}] [{}]", username, remoteAddress, path, instanceIds, foo);      

    LOG.info("Here are the properties: ");
    LOG.info("  accessKey: " + accessKey);
    if (secretKey == null) {
        LOG.warn("  secretKey was null");
    }//from   ww w  .  ja va  2s.c o  m

}

From source file:com.ajah.email.data.AmazonSESTransport.java

License:Apache License

/**
 * Sends a message through Amazon's SES service.
 * // www .jav  a 2  s  . c  om
 * @param message
 *            The message to send. Subject, from and to are required.
 * @throws AddressException
 *             If there is a problem with one of the email addresses.
 * @throws MessagingException
 *             If there is a problem with the transport of the message.
 */
@Override
public void send(final EmailMessage message) throws AddressException, MessagingException {
    AjahUtils.requireParam(message, "message");
    AjahUtils.requireParam(message.getSubject(), "message.subject");
    AjahUtils.requireParam(message.getFrom(), "message.from");
    AjahUtils.requireParam(message.getRecipients(), "message.recipients");

    final AWSCredentials credentials = new BasicAWSCredentials(Config.i.get("aws.accessKey", null),
            Config.i.get("aws.secretKey", null));
    if (Config.i.getBoolean("aws.ses.verify", false)) {
        // Verification is active so we'll need to check that first
        final AmazonSimpleEmailService email = new AmazonSimpleEmailServiceClient(credentials);
        final ListVerifiedEmailAddressesResult verifiedEmails = email.listVerifiedEmailAddresses();
        boolean verified = true;
        if (!isVerified(message.getFrom(), email, verifiedEmails)) {
            log.warning("Sender " + message.getFrom() + " is not verified");
            verified = false;
        }
        for (final EmailRecipient emailRecipient : message.getRecipients()) {
            if (!isVerified(emailRecipient.getAddress(), email, verifiedEmails)) {
                log.warning("Recipient " + emailRecipient.getAddress() + " is not verified");
                verified = false;
            }
        }
        if (!verified) {
            throw new MessagingException("Message not sent because one or more addresses need to be verified");
        }
    }
    final Properties props = new Properties();
    props.setProperty("mail.transport.protocol", "aws");
    props.setProperty("mail.aws.user", credentials.getAWSAccessKeyId());
    props.setProperty("mail.aws.password", credentials.getAWSSecretKey());

    final Session session = Session.getInstance(props);

    final MimeMessage mimeMessage = new MimeMessage(session);
    mimeMessage.setFrom(new InternetAddress(message.getFrom().toString()));
    for (final EmailRecipient emailRecipient : message.getRecipients()) {
        switch (emailRecipient.getType()) {
        case BCC:
            mimeMessage.addRecipient(Message.RecipientType.BCC, new InternetAddress(emailRecipient.toString()));
            break;
        case CC:
            mimeMessage.addRecipient(Message.RecipientType.CC, new InternetAddress(emailRecipient.toString()));
            break;
        case TO:
            mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(emailRecipient.toString()));
            break;
        default:
            mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(emailRecipient.toString()));
            break;
        }
    }
    mimeMessage.setSubject(message.getSubject());
    final String htmlContent = message.getHtml();
    if (StringUtils.isBlank(htmlContent)) {
        // No HTML so we'll just send a plaintext message.
        mimeMessage.setText(message.getText());
    } else {
        final Multipart multiPart = new MimeMultipart("alternative");

        final BodyPart text = new MimeBodyPart();
        text.setText(message.getText());
        multiPart.addBodyPart(text);

        final BodyPart html = new MimeBodyPart();
        html.setContent(message.getHtml(), "text/html");
        multiPart.addBodyPart(html);

        mimeMessage.setContent(multiPart);
    }
    mimeMessage.saveChanges();

    final Transport transport = new AWSJavaMailTransport(session, null);
    transport.connect();
    transport.sendMessage(mimeMessage, null);
    transport.close();

}

From source file:com.ajah.email.data.EmailMessageManager.java

License:Apache License

/**
 * Sends a message through Amazon's SES service.
 * /*from  ww w .  j a va 2  s  .com*/
 * @param message
 *            The message to send. Subject, from and to are required.
 * @throws AddressException
 *             If there is a problem with one of the email addresses.
 * @throws MessagingException
 *             If there is a problem with the transport of the message.
 */
public static void send(final EmailMessage message) throws AddressException, MessagingException {
    AjahUtils.requireParam(message, "message");
    AjahUtils.requireParam(message.getSubject(), "message.subject");
    AjahUtils.requireParam(message.getFrom(), "message.from");
    AjahUtils.requireParam(message.getTo(), "message.to");

    final AWSCredentials credentials = new BasicAWSCredentials(Config.i.get("aws.accessKey", null),
            Config.i.get("aws.secretKey", null));
    if (Config.i.getBoolean("aws.ses.verify", false)) {
        // Verification is active so we'll need to check that first
        final AmazonSimpleEmailService email = new AmazonSimpleEmailServiceClient(credentials);
        final ListVerifiedEmailAddressesResult verifiedEmails = email.listVerifiedEmailAddresses();
        boolean verified = true;
        if (!isVerified(message.getFrom(), email, verifiedEmails)) {
            log.warning("Sender " + message.getFrom() + " is not verified");
            verified = false;
        }
        for (final EmailAddress emailAddress : message.getTo()) {
            if (!isVerified(emailAddress, email, verifiedEmails)) {
                log.warning("Recipient " + emailAddress + " is not verified");
                verified = false;
            }
        }
        if (!verified) {
            throw new MessagingException("Message not sent because one or more addresses need to be verified");
        }
    }
    final Properties props = new Properties();
    props.setProperty("mail.transport.protocol", "aws");
    props.setProperty("mail.aws.user", credentials.getAWSAccessKeyId());
    props.setProperty("mail.aws.password", credentials.getAWSSecretKey());

    final Session session = Session.getInstance(props);

    final MimeMessage mimeMessage = new MimeMessage(session);
    mimeMessage.setFrom(new InternetAddress(message.getFrom().toString()));
    for (final EmailAddress to : message.getTo()) {
        mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(to.toString()));
    }
    mimeMessage.setSubject(message.getSubject());
    final String htmlContent = message.getHtml();
    if (StringUtils.isBlank(htmlContent)) {
        // No HTML so we'll just send a plaintext message.
        mimeMessage.setText(message.getText());
    } else {
        final Multipart multiPart = new MimeMultipart("alternative");

        final BodyPart text = new MimeBodyPart();
        text.setText(message.getText());
        multiPart.addBodyPart(text);

        final BodyPart html = new MimeBodyPart();
        html.setContent(message.getHtml(), "text/html");
        multiPart.addBodyPart(html);

        mimeMessage.setContent(multiPart);
    }
    mimeMessage.saveChanges();

    final Transport transport = new AWSJavaMailTransport(session, null);
    transport.connect();
    transport.sendMessage(mimeMessage, null);
    transport.close();

}

From source file:com.ALC.SC2BOAserver.aws.S3StorageManager.java

License:Open Source License

/**
 * Returns a new AmazonS3 client using the default endpoint and current
 * credentials.//from   w  ww  .j a v a2s  .  c  om
 */
public static AmazonS3Client createClient() {
    AWSCredentials creds = new BasicAWSCredentials(getKey(), getSecret());
    return new AmazonS3Client(creds);
}

From source file:com.allogy.amazonaws.elasticbeanstalk.worker.simulator.application.Config.java

License:Apache License

@Bean
public BasicAWSCredentials awsCredentials() {
    return new BasicAWSCredentials(accessKey, secretKey);
}

From source file:com.amazon.AmazonClientManager.java

License:Apache License

public void validateCredentials() {
    if (sdbClient == null) {
        Log.i(LOG_TAG, "Creating New Clients.");

        Region region = Region.getRegion(Regions.AP_SOUTHEAST_1);

        AWSCredentials credentials = new BasicAWSCredentials(PropertyLoader.getInstance().getAccessKey(),
                PropertyLoader.getInstance().getSecretKey());

        sdbClient = new AmazonSimpleDBClient(credentials);
        sdbClient.setRegion(region);//from  w w  w  . j  av a2s.c  o  m
    }
}

From source file:com.amazon.aws.demo.AmazonClientManager.java

License:Open Source License

public void validateCredentials() {
    if (sesClient == null) {
        Log.i(LOG_TAG, "Creating New Clients.");

        AWSCredentials credentials = new BasicAWSCredentials(PropertyLoader.getInstance().getAccessKey(),
                PropertyLoader.getInstance().getSecretKey());
        sesClient = new AmazonSimpleEmailServiceClient(credentials);
    }/*from  ww  w  . ja va 2s  .  com*/
}

From source file:com.amazon.kinesis.streaming.agent.AgentAWSCredentialsProvider.java

License:Open Source License

public AWSCredentials getCredentials() {
    String accessKeyId = config.accessKeyId();
    String secretKey = config.secretKey();

    if (!Strings.isNullOrEmpty(accessKeyId) && !Strings.isNullOrEmpty(secretKey)) {
        LOGGER.debug("Loading credentials from agent config");
        return new BasicAWSCredentials(accessKeyId, secretKey);
    }// ww w  .j  av a  2  s .co  m

    throw new AmazonClientException("Unable to load credentials from agent config. Missing entries: "
            + (Strings.isNullOrEmpty(accessKeyId) ? AgentConfiguration.CONFIG_ACCESS_KEY : "") + " "
            + (Strings.isNullOrEmpty(secretKey) ? AgentConfiguration.CONFIG_SECRET_KEY : ""));
}

From source file:com.amazon.sqs.javamessaging.SQSConnectionFactory.java

License:Open Source License

@Override
public SQSConnection createConnection(String awsAccessKeyId, String awsSecretKey) throws JMSException {
    BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(awsAccessKeyId, awsSecretKey);
    return createConnection(basicAWSCredentials);
}