Example usage for com.amazonaws.auth PropertiesCredentials PropertiesCredentials

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

Introduction

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

Prototype

public PropertiesCredentials(InputStream inputStream) throws IOException 

Source Link

Document

Reads the specified input stream as a stream of Java properties file content and extracts the AWS access key ID and secret access key from the properties.

Usage

From source file:agentcoordinator.AgentCoordinator.java

protected void setup() {
    /** Registration with the DF */
    DFAgentDescription dfd = new DFAgentDescription();
    ServiceDescription sd = new ServiceDescription();
    sd.setType("AgentCoordinator");
    sd.setName(getName());/*from ww w .j av a  2 s. c o  m*/
    sd.setOwnership("JADE");
    sd.addOntologies("JADEAgent");
    dfd.setName(getAID());

    dfd.addServices(sd);
    try {
        DFService.register(this, dfd);
    } catch (FIPAException e) {
        System.err.println(getLocalName() + " registration with DF unsucceeded. Reason: " + e.getMessage());
        //doDelete();
    }
    /*
    AID aDF = new AID("df@Platform2",AID.ISGUID);
    aDF.addAddresses("http://sakuragi:54960/acc");
    */
    agentUI = new AgentCoordinatorUI();
    agentUI.setAgent(this);
    agentUI.setTitle("Coordinator Agent " + this.getName());
    //try {
    //RefetchAgentsList();
    //RA1.populateAgentsListOnGUI();
    //} catch (FIPAException ex) {
    //Logger.getLogger(AgentCommGUI.class.getName()).log(Level.SEVERE, null, ex);
    //}
    ReceiveMessage rm = new ReceiveMessage();
    addBehaviour(rm);

    //keep list of the SCs
    listOfSubCoordinators = new ArrayList<>();

    //instance IDs list
    instanceIDList = new ArrayList<>();

    //AWS SDK stuffs
    try {
        AWSCredentials credentials = new PropertiesCredentials(
                AgentCoordinator.class.getResourceAsStream("AwsCredentials.properties"));
        amazonEC2Client = new AmazonEC2Client(credentials);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    amazonEC2Client.setEndpoint("ec2.eu-west-1.amazonaws.com");

}

From source file:assign1.simpledb.java

License:Open Source License

public static void main(String[] args) throws InterruptedException {
    ArrayList<record> result = new ArrayList<record>();
    AWSCredentials credentials = null;// ww  w  .j  a  v a  2s .  co  m
    try {
        credentials = new PropertiesCredentials(
                simpledb.class.getResourceAsStream("AwsCredentials.properties"));
    } catch (Exception e) {
        throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
                + "Please make sure that your credentials file is at the correct "
                + "location (/Users/huanglin/.aws/credentials), and is in valid format.", e);
    }

    AmazonSimpleDB sdb = new AmazonSimpleDBClient(credentials);

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon SimpleDB");
    System.out.println("===========================================\n");

    try {
        String myDomain = "MyStore";

        String selectExpression = "select count(*) from " + myDomain + " where content like '%news%'";
        System.out.println("Selecting: " + selectExpression + "\n");
        SelectRequest selectRequest = new SelectRequest(selectExpression);
        for (Item item : sdb.select(selectRequest).getItems()) {
            System.out.println("    itemIndex: " + item.getName());
            for (Attribute attribute : item.getAttributes()) {
                System.out.println("      Attribute");
                System.out.println("        Name:  " + attribute.getName());
                System.out.println("        Value: " + attribute.getValue());
            }
        }

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SimpleDB, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with SimpleDB, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:assign1.simpledb.java

License:Open Source License

public List<record> query(String word) throws Exception {
    /*/*ww w .  j  a  v a 2s . c om*/
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials*/

    ArrayList<record> result = new ArrayList<record>();
    AWSCredentials credentials = null;
    try {
        credentials = new PropertiesCredentials(
                simpledb.class.getResourceAsStream("AwsCredentials.properties"));
    } catch (Exception e) {
        throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
                + "Please make sure that your credentials file is at the correct "
                + "location (/Users/huanglin/.aws/credentials), and is in valid format.", e);
    }

    AmazonSimpleDB sdb = new AmazonSimpleDBClient(credentials);

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon SimpleDB");
    System.out.println("===========================================\n");

    String myDomain = "MyStore";

    String filter = word;
    String nextToken = null;
    SelectResult selectResult = null;
    do {
        String selectExpression = "";
        if (word.equals("all"))
            selectExpression = "select * from MyStore LIMIT 2500";
        else
            selectExpression = "select * from " + myDomain + " where content like '%" + filter
                    + "%' LIMIT 2500";
        System.out.println("Selecting: " + selectExpression + "\n");
        SelectRequest selectRequest = new SelectRequest(selectExpression);
        selectRequest.setNextToken(nextToken);
        selectResult = sdb.select(selectRequest);
        nextToken = selectResult.getNextToken();
        List<Item> list = selectResult.getItems();
        for (Item item : list) {
            System.out.println("    itemIndex: " + item.getName());
            List<Attribute> attributeTmp = new ArrayList<Attribute>();
            attributeTmp = item.getAttributes();
            record tmp = new record();
            for (int i = 0; i < 5; i++) {
                if (attributeTmp.get(i).getName().equals("content"))
                    tmp.content = attributeTmp.get(i).getValue();
                else if (attributeTmp.get(i).getName().equals("geoLat"))
                    tmp.x = Double.parseDouble(attributeTmp.get(i).getValue());
                else if (attributeTmp.get(i).getName().equals("Username"))
                    tmp.username = attributeTmp.get(i).getValue();
                else if (attributeTmp.get(i).getName().equals("Location"))
                    tmp.location = attributeTmp.get(i).getValue();
                else
                    tmp.y = Double.parseDouble(attributeTmp.get(i).getValue());
            }
            result.add(tmp);
        }
    } while (nextToken != null);

    return result;
}

From source file:assign1.simpledb1.java

License:Open Source License

public static void main(String[] args) throws InterruptedException {
    ArrayList<record> result = new ArrayList<record>();
    AWSCredentials credentials = null;//from  w  ww .j  a  v a2  s. c  o  m
    try {
        credentials = new PropertiesCredentials(
                simpledb.class.getResourceAsStream("AwsCredentials.properties"));
    } catch (Exception e) {
        throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
                + "Please make sure that your credentials file is at the correct "
                + "location (/Users/huanglin/.aws/credentials), and is in valid format.", e);
    }

    AmazonSimpleDB sdb = new AmazonSimpleDBClient(credentials);

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon SimpleDB");
    System.out.println("===========================================\n");

    try {
        String myDomain = "Twitter";

        String selectExpression = "select count(*) from " + myDomain + " where content like '%news%'";
        System.out.println("Selecting: " + selectExpression + "\n");
        SelectRequest selectRequest = new SelectRequest(selectExpression);
        for (Item item : sdb.select(selectRequest).getItems()) {
            System.out.println("    itemIndex: " + item.getName());
            for (Attribute attribute : item.getAttributes()) {
                System.out.println("      Attribute");
                System.out.println("        Name:  " + attribute.getName());
                System.out.println("        Value: " + attribute.getValue());
            }
        }

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SimpleDB, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with SimpleDB, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:assign1.simpledb1.java

License:Open Source License

public List<record> query(String word) throws Exception {
    /*// w w  w  .j  a v  a2s  .  c  om
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials*/

    ArrayList<record> result = new ArrayList<record>();
    AWSCredentials credentials = null;
    try {
        credentials = new PropertiesCredentials(
                simpledb.class.getResourceAsStream("AwsCredentials.properties"));
    } catch (Exception e) {
        throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
                + "Please make sure that your credentials file is at the correct "
                + "location (/Users/huanglin/.aws/credentials), and is in valid format.", e);
    }

    AmazonSimpleDB sdb = new AmazonSimpleDBClient(credentials);

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon SimpleDB");
    System.out.println("===========================================\n");

    String myDomain = "Twitter";

    String filter = word;
    String nextToken = null;
    SelectResult selectResult = null;
    do {
        String selectExpression = "";
        if (word.equals("all"))
            selectExpression = "select * from MyStore LIMIT 2500";
        else
            selectExpression = "select * from " + myDomain + " where content like '%" + filter
                    + "%' LIMIT 2500";
        System.out.println("Selecting: " + selectExpression + "\n");
        SelectRequest selectRequest = new SelectRequest(selectExpression);
        selectRequest.setNextToken(nextToken);
        selectResult = sdb.select(selectRequest);
        nextToken = selectResult.getNextToken();
        List<Item> list = selectResult.getItems();
        for (Item item : list) {
            System.out.println("    itemIndex: " + item.getName());
            List<Attribute> attributeTmp = new ArrayList<Attribute>();
            attributeTmp = item.getAttributes();
            record tmp = new record();
            for (int i = 0; i < 5; i++) {
                if (attributeTmp.get(i).getName().equals("content"))
                    tmp.content = attributeTmp.get(i).getValue();
                else if (attributeTmp.get(i).getName().equals("geoLat"))
                    tmp.x = Double.parseDouble(attributeTmp.get(i).getValue());
                else if (attributeTmp.get(i).getName().equals("Username"))
                    tmp.username = attributeTmp.get(i).getValue();
                else if (attributeTmp.get(i).getName().equals("Location"))
                    tmp.location = attributeTmp.get(i).getValue();
                else
                    tmp.y = Double.parseDouble(attributeTmp.get(i).getValue());
            }
            result.add(tmp);
        }
    } while (nextToken != null);

    return result;
}

From source file:at.ac.tuwien.infosys.jcloudscale.vm.ec2.EC2Wrapper.java

License:Apache License

EC2Wrapper(EC2CloudPlatformConfiguration config) throws IOException {
    this.config = config;
    this.log = JCloudScaleConfiguration.getLogger(this);

    // connect to EC2
    InputStream credentialsAsStream = new FileInputStream(config.getAwsConfigFile());
    creds = new PropertiesCredentials(credentialsAsStream);
    ec2Client = new AmazonEC2Client(creds);
    ec2Client.setEndpoint(config.getAwsEndpoint());
}

From source file:aws.sample.AmazonDynamoDBSample.java

License:Open Source License

/**
 * The only information needed to create a client are security credentials consisting of the AWS Access Key ID and Secret Access Key. All other configuration, such as the service endpoints, are performed automatically. Client parameters, such as proxies, can be specified in an optional ClientConfiguration object when constructing a client.
 * //from   w  ww  .j  av a  2s  .  c  o m
 * @see com.amazonaws.auth.BasicAWSCredentials
 * @see com.amazonaws.auth.PropertiesCredentials
 * @see com.amazonaws.ClientConfiguration
 */
private static void init() throws Exception {
    System.setProperty("com.amazonaws.sdk.disableCertChecking", "true");

    AWSCredentials credentials = new PropertiesCredentials(
            AmazonDynamoDBSample.class.getResourceAsStream("/AwsCredentials.properties"));
    Debug.line(credentials.getAWSAccessKeyId(), credentials.getAWSSecretKey());
    dynamoDB = new AmazonDynamoDBClient(credentials);

}

From source file:aws.sample.AwsConsoleApp.java

License:Open Source License

/**
 * The only information needed to create a client are security credentials consisting of the AWS Access Key ID and Secret Access Key. All other configuration, such as the service endpoints, are performed automatically. Client parameters, such as proxies, can be specified in an optional ClientConfiguration object when constructing a client.
 * //  ww w .  j a v  a2  s  . co  m
 * @see com.amazonaws.auth.BasicAWSCredentials
 * @see com.amazonaws.auth.PropertiesCredentials
 * @see com.amazonaws.ClientConfiguration
 */
private static void init() throws Exception {
    AWSCredentials credentials = new PropertiesCredentials(
            AwsConsoleApp.class.getResourceAsStream("/AwsCredentials.properties"));

    ec2 = new AmazonEC2Client(credentials);
    s3 = new AmazonS3Client(credentials);
    sdb = new AmazonSimpleDBClient(credentials);
}

From source file:aws.sample.AWSJavaMailSample.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*/*w w w . jav a 2 s .  co m*/
     * Important: Be sure to fill in your AWS access credentials in the AwsCredentials.properties file before you try to run this sample. http://aws.amazon.com/security-credentials
     */
    PropertiesCredentials credentials = new PropertiesCredentials(
            AWSJavaMailSample.class.getResourceAsStream("/AwsCredentials.properties"));
    AmazonSimpleEmailService ses = new AmazonSimpleEmailServiceClient(credentials);

    /*
     * Before you can send email via Amazon SES, you need to verify that you own the email address from which you?l be sending email. This will trigger a verification email, which will contain a link that you can click on to complete the verification process.
     */
    verifyEmailAddress(ses, FROM);

    /*
     * If you've just signed up for SES, then you'll be placed in the Amazon SES sandbox, where you must also verify the email addresses you want to send mail to.
     * 
     * You can uncomment the line below to verify the TO address in this sample.
     * 
     * Once you have full access to Amazon SES, you will *not* be required to verify each email address you want to send mail to.
     * 
     * You can request full access to Amazon SES here: http://aws.amazon.com/ses/fullaccessrequest
     */
    // verifyEmailAddress(ses, TO);

    /*
     * Setup JavaMail to use the Amazon Simple Email Service by specifying the "aws" protocol.
     */
    Properties props = new Properties();
    props.setProperty("mail.transport.protocol", "aws");

    /*
     * Setting mail.aws.user and mail.aws.password are optional. Setting these will allow you to send mail using the static transport send() convince method. It will also allow you to call connect() with no parameters. Otherwise, a user name and password must be specified in connect.
     */
    props.setProperty("mail.aws.user", credentials.getAWSAccessKeyId());
    props.setProperty("mail.aws.password", credentials.getAWSSecretKey());

    Session session = Session.getInstance(props);

    try {
        // Create a new Message
        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(FROM));
        msg.addRecipient(Message.RecipientType.TO, new InternetAddress(TO));
        msg.setSubject(SUBJECT);
        msg.setText(BODY);
        msg.saveChanges();

        // Reuse one Transport object for sending all your messages
        // for better performance
        Transport t = new AWSJavaMailTransport(session, null);
        t.connect();
        t.sendMessage(msg, null);

        // Close your transport when you're completely done sending
        // all your messages
        t.close();
    } catch (AddressException e) {
        e.printStackTrace();
        System.out.println("Caught an AddressException, which means one or more of your "
                + "addresses are improperly formatted.");
    } catch (MessagingException e) {
        e.printStackTrace();
        System.out.println("Caught a MessagingException, which means that there was a "
                + "problem sending your message to Amazon's E-mail Service check the "
                + "stack trace for more information.");
    }
}

From source file:aws.sample.CreateSecurityGroupApp.java

License:Open Source License

/**
 * @param args/*  ww w. j  a  v a  2 s  .c  o m*/
 */
public static void main(String[] args) {
    // Retrieves the credentials from an AWSCredentials.properties file.
    AWSCredentials credentials = null;
    try {
        credentials = new PropertiesCredentials(
                InlineGettingStartedCodeSampleApp.class.getResourceAsStream("AwsCredentials.properties"));
    } catch (IOException e1) {
        System.out.println("Credentials were not properly entered into AwsCredentials.properties.");
        System.out.println(e1.getMessage());
        System.exit(-1);
    }

    // Create the AmazonEC2Client object so we can call various APIs.
    AmazonEC2 ec2 = new AmazonEC2Client(credentials);

    // Create a new security group.
    try {
        CreateSecurityGroupRequest securityGroupRequest = new CreateSecurityGroupRequest("GettingStartedGroup",
                "Getting Started Security Group");
        ec2.createSecurityGroup(securityGroupRequest);
    } catch (AmazonServiceException ase) {
        // Likely this means that the group is already created, so ignore.
        System.out.println(ase.getMessage());
    }

    String ipAddr = "0.0.0.0/0";

    // Get the IP of the current host, so that we can limit the Security Group
    // by default to the ip range associated with your subnet.
    try {
        InetAddress addr = InetAddress.getLocalHost();

        // Get IP Address
        ipAddr = addr.getHostAddress() + "/10";
    } catch (UnknownHostException e) {
    }

    // System.exit(-1);
    // Create a range that you would like to populate.
    ArrayList<String> ipRanges = new ArrayList<String>();
    ipRanges.add(ipAddr);

    // Open up port 23 for TCP traffic to the associated IP from above (e.g. ssh traffic).
    ArrayList<IpPermission> ipPermissions = new ArrayList<IpPermission>();
    IpPermission ipPermission = new IpPermission();
    ipPermission.setIpProtocol("tcp");
    ipPermission.setFromPort(new Integer(22));
    ipPermission.setToPort(new Integer(22));
    ipPermission.setIpRanges(ipRanges);
    ipPermissions.add(ipPermission);

    try {
        // Authorize the ports to the used.
        AuthorizeSecurityGroupIngressRequest ingressRequest = new AuthorizeSecurityGroupIngressRequest(
                "GettingStartedGroup", ipPermissions);
        ec2.authorizeSecurityGroupIngress(ingressRequest);
    } catch (AmazonServiceException ase) {
        // Ignore because this likely means the zone has already been authorized.
        System.out.println(ase.getMessage());
    }
}