Search in sources :

Example 26 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project simplejpa by appoxy.

the class EntityManagerFactoryImpl method createClients.

private void createClients() {
    AWSCredentials awsCredentials = null;
    InputStream credentialsFile = getClass().getClassLoader().getResourceAsStream("AwsCredentials.properties");
    if (credentialsFile != null) {
        logger.info("Loading credentials from AwsCredentials.properties");
        try {
            awsCredentials = new PropertiesCredentials(credentialsFile);
        } catch (IOException e) {
            throw new PersistenceException("Failed loading credentials from AwsCredentials.properties.", e);
        }
    } else {
        logger.info("Loading credentials from simplejpa.properties");
        String awsAccessKey = (String) this.props.get(AWSACCESS_KEY_PROP_NAME);
        String awsSecretKey = (String) this.props.get(AWSSECRET_KEY_PROP_NAME);
        if (awsAccessKey == null || awsAccessKey.length() == 0) {
            throw new PersistenceException("AWS Access Key not found. It is a required property.");
        }
        if (awsSecretKey == null || awsSecretKey.length() == 0) {
            throw new PersistenceException("AWS Secret Key not found. It is a required property.");
        }
        awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
    }
    this.simpleDbClient = new AmazonSimpleDBClient(awsCredentials, createConfiguration(sdbSecure));
    this.simpleDbClient.setEndpoint(sdbEndpoint);
    this.s3Client = new AmazonS3Client(awsCredentials, createConfiguration(s3Secure));
    this.s3Client.setEndpoint(s3Endpoint);
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AmazonSimpleDBClient(com.amazonaws.services.simpledb.AmazonSimpleDBClient) InputStream(java.io.InputStream) PersistenceException(javax.persistence.PersistenceException) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) IOException(java.io.IOException) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 27 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project glacier-cli by carlossg.

the class Glacier method main.

public static void main(String[] args) throws Exception {
    options = commonOptions();
    try {
        CommandLineParser parser = new PosixParser();
        CommandLine cmd = parser.parse(options, args);
        List<String> arguments = Arrays.asList(cmd.getArgs());
        if (cmd.hasOption("help")) {
            usage();
        // Not reached
        }
        if (arguments.isEmpty()) {
            throw new GlacierCliException("Must provide at least one command.");
        }
        GlacierCliCommand command = GlacierCliCommand.get(arguments.get(0));
        if (command == null) {
            throw new GlacierCliException("Invalid command given: " + arguments.get(0));
        }
        String defaultPropertiesPath = System.getProperty("user.home") + "/AwsCredentials.properties";
        String propertiesPath = cmd.getOptionValue("properties", defaultPropertiesPath);
        File props = new File(propertiesPath);
        AWSCredentials credentials = new PropertiesCredentials(props);
        Glacier glacier = new Glacier(credentials, cmd.getOptionValue("region", "us-east-1"));
        switch(command) {
            // Archive commands
            case UPLOAD:
                if (arguments.size() < 3) {
                    throw new GlacierCliException("The upload command requires at least three parameters.");
                }
                for (String archive : arguments.subList(2, arguments.size())) {
                    glacier.upload(arguments.get(1), archive);
                }
                break;
            case DELETE:
                if (arguments.size() != 3) {
                    throw new GlacierCliException("The delete command requires exactly three parameters.");
                }
                glacier.delete(arguments.get(1), arguments.get(2));
                break;
            case DOWNLOAD:
                if (arguments.size() != 4) {
                    throw new GlacierCliException("The download command requires exactly four parameters.");
                }
                glacier.download(arguments.get(1), arguments.get(2), arguments.get(3));
                break;
            // Vault commands
            case CREATE_VAULT:
                if (arguments.size() != 2) {
                    throw new GlacierCliException("The create-vault command requires exactly one parameter.");
                }
                glacier.createVault(arguments.get(1));
                break;
            case DELETE_VAULT:
                if (arguments.size() != 2) {
                    throw new GlacierCliException("The delete-vault command requires exactly two parameters.");
                }
                glacier.deleteVault(arguments.get(1));
                break;
            case INVENTORY:
                if (arguments.size() != 2) {
                    throw new GlacierCliException("The inventory command requires exactly two parameters.");
                }
                glacier.inventory(arguments.get(1), cmd.getOptionValue("topic", "glacier"), cmd.getOptionValue("queue", "glacier"), cmd.getOptionValue("file", "glacier.json"));
                break;
            case INFO:
                if (arguments.size() != 2) {
                    throw new GlacierCliException("The info command requires exactly two parameters.");
                }
                glacier.info(arguments.get(1));
                break;
            case LIST:
                glacier.list();
                break;
        }
    } catch (GlacierCliException e) {
        System.err.println("error: " + e.getMessage());
        System.err.println();
        usage();
    } catch (UnrecognizedOptionException e) {
        System.err.println("error: Invalid argument: " + e.getOption());
        usage();
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) CommandLineParser(org.apache.commons.cli.CommandLineParser) File(java.io.File) AWSCredentials(com.amazonaws.auth.AWSCredentials) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException)

Example 28 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project aws-iam-ldap-bridge by denismo.

the class IAMSecretKeyValidator method verifyIAMPassword.

@Override
public boolean verifyIAMPassword(Entry user, String pw) throws LdapInvalidAttributeValueException, LdapAuthenticationException {
    boolean role = false;
    AWSCredentials creds;
    if (isRole(user)) {
        role = true;
        String[] parts = pw.split("\\|");
        if (parts == null || parts.length < 3)
            throw new LdapAuthenticationException();
        creds = new BasicSessionCredentials(parts[0], parts[1], parts[2]);
    } else {
        creds = new BasicAWSCredentials(user.get("accessKey").getString(), pw);
    }
    LOG.debug("Verifying {} {} with accessKey <hidden> and secretKey <hidden>", role ? "role" : "user", user.get("uid").getString());
    AmazonIdentityManagementClient client = new AmazonIdentityManagementClient(creds);
    try {
        client.getAccountSummary();
    } catch (AmazonClientException e) {
        System.err.println(e.getMessage());
        return false;
    } finally {
        client.shutdown();
    }
    return true;
}
Also used : AmazonIdentityManagementClient(com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) AmazonClientException(com.amazonaws.AmazonClientException) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 29 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project druid by druid-io.

the class TestAWSCredentialsProvider method testWithFixedAWSKeys.

@Test
public void testWithFixedAWSKeys() {
    AWSCredentialsConfig config = EasyMock.createMock(AWSCredentialsConfig.class);
    EasyMock.expect(config.getAccessKey()).andReturn("accessKeySample").atLeastOnce();
    EasyMock.expect(config.getSecretKey()).andReturn("secretKeySample").atLeastOnce();
    EasyMock.replay(config);
    AWSCredentialsProvider provider = awsModule.getAWSCredentialsProvider(config);
    AWSCredentials credentials = provider.getCredentials();
    assertEquals(credentials.getAWSAccessKeyId(), "accessKeySample");
    assertEquals(credentials.getAWSSecretKey(), "secretKeySample");
    // try to create
    s3Module.getRestS3Service(provider);
}
Also used : AWSCredentialsConfig(io.druid.common.aws.AWSCredentialsConfig) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 30 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project elasticsearch by elastic.

the class AwsEc2ServiceImplTests method launchAWSCredentialsWithElasticsearchSettingsTest.

protected void launchAWSCredentialsWithElasticsearchSettingsTest(Settings settings, String expectedKey, String expectedSecret) {
    AWSCredentials credentials = AwsEc2ServiceImpl.buildCredentials(logger, settings).getCredentials();
    assertThat(credentials.getAWSAccessKeyId(), is(expectedKey));
    assertThat(credentials.getAWSSecretKey(), is(expectedSecret));
}
Also used : AWSCredentials(com.amazonaws.auth.AWSCredentials)

Aggregations

AWSCredentials (com.amazonaws.auth.AWSCredentials)40 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)25 ClientConfiguration (com.amazonaws.ClientConfiguration)13 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)12 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)8 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)7 File (java.io.File)7 AmazonClientException (com.amazonaws.AmazonClientException)6 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)5 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)4 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)4 IOException (java.io.IOException)4 Instance (com.amazonaws.services.ec2.model.Instance)3 AmazonSimpleDBClient (com.amazonaws.services.simpledb.AmazonSimpleDBClient)3 Region (com.amazonaws.regions.Region)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 RegionRecord (edu.umass.cs.aws.support.RegionRecord)2 AWSCredentialsConfig (io.druid.common.aws.AWSCredentialsConfig)2 Point2D (java.awt.geom.Point2D)2 HashMap (java.util.HashMap)2