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);
}
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();
}
}
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;
}
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);
}
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));
}
Aggregations