public void testDoubleDots() throws Exception { String filename = System.getProperty("user.home")+"/aws.properties"; PropertiesCredentials credentials = new PropertiesCredentials(new File(filename)); AmazonS3Client client = new AmazonS3Client(credentials); client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true)); client.setRegion(Region.getRegion(Regions.EU_WEST_1)); testPrefix(client,"",6); Collections.sort(prefixTestResults); for (String s : prefixTestResults) { System.out.println(s); } }
/** * Creates the AWSCredentials object based on the properties file. * @return AWSCredentials object * @throws FileNotFoundException * @throws IllegalArgumentException * @throws IOException */ private AWSCredentials getCredentials() throws FileNotFoundException, IllegalArgumentException, IOException { if(authentication == null){ InputStream awsCredInpStr = getClass().getClassLoader().getResourceAsStream(awsCredentialsProperties); if (awsCredInpStr == null) LOG.info("AWS Credentials File was not found on the classpath!"); AWSCredentials credentials = new PropertiesCredentials(awsCredInpStr); setConf(credentials); } return (AWSCredentials)authentication; }
public static void main (String[] args) throws Exception { String credentials = new String("secretKey=MD/FGPCuKkq9EBCpV0qXbfTbaQByFdQYPiM9/BzA" + "\n" + "accessKey=AKIAICG6X3TDB3GIBQIQ"); AmazonS3Client s3 = new AmazonS3Client(new PropertiesCredentials(new ByteArrayInputStream(credentials.getBytes()))); File f = new File("C:\rfcs\rfc4912.txt"); String s = readFileAsString(f); for (int i = 0; i < 1000; i++) { ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(s.getBytes().length); s3.putObject("cryptosearch", "test/"+i, new ByteArrayInputStream(s.getBytes()), metadata); } }
public Storage (String name) throws FileNotFoundException, IOException { File creds = new File(Configuration.CREDS_FILE); if (creds.exists()) { _s3 = new AmazonS3Client(new PropertiesCredentials(creds)); } else { _s3 = new AmazonS3Client(); } _s3.setEndpoint(Configuration.S3_ENDPOINT); _bucket = name; }
public CreateEndpointJob() { try { client = new AmazonSNSClient( new PropertiesCredentials( BatchCreatePlatformEndpointSample.class .getClassLoader() .getResourceAsStream(BatchCreatePlatformEndpointSample.AWSCREDENTIALSPROPERTIES_FILE))); } catch (Exception e) { System.err .println("[ERROR] Error opening file <" + BatchCreatePlatformEndpointSample.AWSCREDENTIALSPROPERTIES_FILE + ">" + " " + e.getMessage()); System.exit(BatchCreatePlatformEndpointSample.CREDENTIAL_RETRIEVAL_FAILURE_ERROR_CODE); } }
private AWSCredentials loadCredentialFile(String credentialsFilePath) throws IllegalArgumentException { try { return new PropertiesCredentials(getInputStream(credentialsFilePath)); } catch (IOException ioe) { throw new IllegalArgumentException("Error: Failed to read credential file " + credentialsFilePath); } }
public void uploadFileToS3(String uploadFileName, String bucketName, String keyName){ try { AmazonS3 s3client = new AmazonS3Client(new PropertiesCredentials( AmazonS3Manager.class.getResourceAsStream( "AwsCredentials.properties"))); System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFileName); s3client.putObject(new PutObjectRequest( bucketName, keyName, file)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, 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 " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public AWSCredentials getAwsCredentials() { try { return new PropertiesCredentials(getUserProperitesFile()); } catch (IOException e) { console .write("Cannot find or read configuration file at'" + getUserPropertiesFilePath() + "'"); //$NON-NLS-1$ //$NON-NLS-2$ throw new RuntimeException(e); } }
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()); }
@Override public void setup() { try { InputStream is = null; is = new FileInputStream(SystemConstants.FILE_CREDENTIALS_AMAZON); PropertiesCredentials credentials = new PropertiesCredentials(is); EC2 = new AmazonEC2Client(credentials); EC2.setEndpoint("ec2.sa-east-1.amazonaws.com"); } catch (IOException ioe) { throw new RuntimeException(ioe); }//, IllegalArgumentException }
private void setDynamoDBProperties(Properties properties) throws IOException { setSerializationType(properties.getProperty(SERIALIZATION_TYPE)); PropertiesCredentials creds = DynamoDBUtils.getCredentials(this.getClass()); setPreferredSchema(properties.getProperty(PREF_SCH_NAME)); setDynamoDBClient(DynamoDBUtils.getClient( properties.getProperty(CLI_TYP_PROP), creds)); getDynamoDBClient().setEndpoint(properties.getProperty(ENDPOINT_PROP)); setDynamoDbMapping(readMapping()); setConsistency(properties.getProperty(CONSISTENCY_READS)); }
public static AWSCredentials getCredentials(InputStream credentialsInputStream) throws MessagingException { try { return new PropertiesCredentials(credentialsInputStream); } catch (IOException e) { throw new MessagingException("Could not read properties", e); } }
/** * Create the S3 Client API handle, obtaining the AWS credential from a .properties file * * @return */ protected AmazonS3 makeS3Connection() { AmazonS3 s3client=null; // Setup Amazon S3 client try { s3client = new AmazonS3Client(new PropertiesCredentials( SigningWorker.class.getResourceAsStream("/AwsCredentials.properties"))); // Starts with slash because SigningGenerator is not in the "default" package. } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return s3client; }
public static AWSCredentialsProvider getAwsCredentials() { try { return new StaticCredentialsProvider(new PropertiesCredentials(new File(System.getProperty("user.home"), ".ec2/credentials.properties"))); } catch (IOException e) { return new DefaultAWSCredentialsProviderChain(); } }
private AWSCredentialsProvider initCredentials() { // Attempt to use any credentials specified in context.xml first if (credentialsExistInContextConfig()) { // Fail fast if credentials aren't valid as user has likely made a configuration mistake if (credentialsInContextConfigAreValid()) { throw new AmazonClientException("Incomplete AWS security credentials specified in context.xml."); } logger.debug("Using AWS access key ID and secret key from context.xml"); return new StaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)); } // Use any explicitly specified credentials properties file next if (credentialsFile != null) { try { logger.debug("Reading security credentials from properties file: " + credentialsFile); PropertiesCredentials credentials = new PropertiesCredentials(credentialsFile); logger.debug("Using AWS credentials from file: " + credentialsFile); return new StaticCredentialsProvider(credentials); } catch (Exception e) { throw new AmazonClientException( "Unable to read AWS security credentials from file specified in context.xml: " + credentialsFile, e); } } // Fall back to the default credentials chain provider if credentials weren't explicitly set AWSCredentialsProvider defaultChainProvider = new DefaultAWSCredentialsProviderChain(); if (defaultChainProvider.getCredentials() == null) { logger.debug("Loading security credentials from default credentials provider chain."); throw new AmazonClientException("Unable to find AWS security credentials. " + "Searched JVM system properties, OS env vars, and EC2 instance roles. " + "Specify credentials in Tomcat's context.xml file or put them in one of the places mentioned above."); } logger.debug("Using default AWS credentials provider chain to load credentials"); return defaultChainProvider; }
public BaseS3(File file) throws Exception { if (accessKey != null && secretKey != null) creds = new BasicAWSCredentials(accessKey, secretKey); else creds = new PropertiesCredentials(file); }
public BaseS3(InputStream is) throws Exception { if (accessKey != null && secretKey != null) creds = new BasicAWSCredentials(accessKey, secretKey); else creds = new PropertiesCredentials(is); }
public CreateEndpointJob() { try { client = new AmazonSNSClient( new PropertiesCredentials( BatchCreatePlatformEndpointSample.class .getResourceAsStream(BatchCreatePlatformEndpointSample.AWSCREDENTIALSPROPERTIES_FILE))); } catch (IOException ioe) { System.err .print("[ERROR] Error opening file" + BatchCreatePlatformEndpointSample.AWSCREDENTIALSPROPERTIES_FILE + ": " + ioe.getMessage()); System.exit(BatchCreatePlatformEndpointSample.CREDENTIAL_RETRIEVAL_FAILURE_ERROR_CODE); } }
public static void main(String[] args) throws IOException{ /* * TODO: 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 */ AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials( SNSMobilePush.class .getResourceAsStream("AwsCredentials.properties"))); sns.setEndpoint("https://sns.us-west-2.amazonaws.com"); System.out.println("===========================================\n"); System.out.println("Getting Started with Amazon SNS"); System.out.println("===========================================\n"); try { SNSMobilePush sample = new SNSMobilePush(sns); // TODO: Uncomment the services you wish to use. //sample.demoAndroidAppNotification(Platform.GCM); //sample.demoKindleAppNotification(Platform.ADM); //sample.demoAppleAppNotification(Platform.APNS); //sample.demoAppleAppNotification(Platform.APNS_SANDBOX); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SNS, 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 SNS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
public SQSTestBase() { PropertiesFileCredentialsProvider file = new PropertiesFileCredentialsProvider(getTestCredsFilePath()); testCreds = (PropertiesCredentials)file.getCredentials(); sqs = new AmazonSQSClient(testCreds); }
public static void main(String[] args) throws IOException { /* * TODO: 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 */ AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials( SNSMobilePush.class .getResourceAsStream("AwsCredentials.properties"))); sns.setEndpoint("https://sns.us-west-2.amazonaws.com"); System.out.println("===========================================\n"); System.out.println("Getting Started with Amazon SNS"); System.out.println("===========================================\n"); try { SNSMobilePush sample = new SNSMobilePush(sns); /* TODO: Uncomment the services you wish to use. */ // sample.demoAndroidAppNotification(); // sample.demoKindleAppNotification(); // sample.demoAppleAppNotification(); // sample.demoAppleSandboxAppNotification(); // sample.demoBaiduAppNotification(); // sample.demoWNSAppNotification(); // sample.demoMPNSAppNotification(); } catch (AmazonServiceException ase) { System.out .println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SNS, 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 SNS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
/** * Init method to intialize AWS credentials. * * @throws Exception in case of error. */ public void init() throws Exception { AWSCredentials credentials = new PropertiesCredentials( AmazonDynamoDB.class.getResourceAsStream("AwsCredentials.properties")); dynamoDB = new AmazonDynamoDBClient(credentials); }
public static void setup() throws IOException, IllegalArgumentException { PropertiesCredentials credentials = new PropertiesCredentials(Ec2Commands.class.getResourceAsStream("/AwsCredentials.properties")); EC2 = new AmazonEC2Client(credentials); EC2.setEndpoint("ec2.us-west-2.amazonaws.com"); }
public static void main(String[] args) throws IOException { /* * TODO: 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 */ String awsAccessKey = System.getProperty("AWS_ACCESS_KEY_ID"); // "YOUR_AWS_ACCESS_KEY"; String awsSecretKey = System.getProperty("AWS_SECRET_KEY"); // "YOUR_AWS_SECRET_KEY"; if (awsAccessKey == null) awsAccessKey = AWS_ACCESS_KEY; if (awsSecretKey == null) awsSecretKey = AWS_SECRET_KEY; AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey); AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials( SNSMobilePush.class .getResourceAsStream("AwsCredentials.properties"))); // AmazonSNS sns = new AmazonSNSClient(credentials); sns.setEndpoint("https://sns.us-west-2.amazonaws.com"); System.out.println("===========================================\n"); System.out.println("Initializing Communication with Amazon SNS"); System.out.println("===========================================\n"); try { SNSMobilePush sample = new SNSMobilePush(sns); /* TODO: Uncomment the services you wish to use. */ // sample.starterAndroidAppNotification(); // sample.starterKindleAppNotification(); sample.starterAppleAppNotification(); // sample.starterAppleSandboxAppNotification(); // sample.starterBaiduAppNotification(); // sample.starterWNSAppNotification(); // sample.starterMPNSAppNotification(); } catch (AmazonServiceException ase) { System.out .println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SNS, 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 SNS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
public void testCombinations() throws Exception { String filename = System.getProperty("user.home")+"/aws.properties"; PropertiesCredentials credentials = new PropertiesCredentials(new File(filename)); AmazonS3Client client = new AmazonS3Client(credentials); client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true)); client.setRegion(Region.getRegion(Regions.EU_WEST_1)); testBucketName(client,"doesnotrxist.mjt.me.uk"); testBucketName(client,"name-with-hyphens.mjt.me.uk"); testBucketName(client,"name_underscore.mjt.me.uk"); testBucketName(client,"-initial-hyphen.mjt.me.uk"); testBucketName(client,".initial-dot.mjt.me.uk"); testBucketName(client,"CAPITALLETTERS.mjt.me.uk"); testBucketName(client,"dashdota.-.mjt.me.uk"); testBucketName(client,"dashdotb-.mjt.me.uk"); testBucketName(client,"dashdotc.-mjt.me.uk"); testBucketName(client,"?.mjt.me.uk"); testBucketName(client,"§.mjt.me.uk"); testBucketName(client,"\u2605.mjt.me.uk"); testBucketName(client,"\u3070.mjt.me.uk"); testBucketName(client," "); testBucketName(client,"s"); testBucketName(client,""); testBucketName(client,"asdf"); testBucketName(client,"192.168.0.1.mjt.me.uk"); testBucketName(client,"192.168.0"); testBucketName(client,"192.168.0.1"); testBucketName(client,"192.168.0.1.2"); testBucketName(client,"292.168.0.1"); testBucketName(client,"392.168.0.1"); testBucketName(client,"1000.168.0.1"); testBucketName(client,"10000.2.3.4"); testBucketName(client,"100000.2.3.4"); testBucketName(client,"1000000.2.3.4"); testBucketName(client,"1-000.168.0.1"); testBucketName(client,"2001:0db8:85a3:0000:0000:8a2e:0370:7334"); testBucketName(client,"asdfasdfasdfadsfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf.mjt.me.uk"); testBucketName(client,"a"); testBucketName(client,"aa"); testBucketName(client,"aaa"); testBucketName(client,"aaaa"); testBucketName(client,"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); testBucketName(client,"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); testBucketName(client,"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); testBucketName(client,"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); testBucketName(client,"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); }
public void testCombinations() throws Exception { String filename = System.getProperty("user.home")+"/aws.properties"; PropertiesCredentials credentials = new PropertiesCredentials(new File(filename)); AmazonS3Client client = new AmazonS3Client(credentials); client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true)); client.setRegion(Region.getRegion(Regions.EU_WEST_1)); testKey(client,"asdf.txt"); testKey(client," "); testKey(client,"qwer.txt?acl"); testKey(client,"../../../.."); testKey(client,"../../../."); testKey(client,"../../../"); testKey(client,"../../.."); testKey(client,"../../."); testKey(client,"../../"); testKey(client,"../.."); testKey(client,"../."); testKey(client,"../"); testKey(client,".."); testKey(client,"."); testKey(client,"./"); testKey(client,"./."); testKey(client,"././"); testKey(client,"././."); testKey(client,"////"); testKey(client,"/"); testKey(client,"\\\\\\"); testKey(client,"\\"); testKey(client,""); testKey(client,"\0"); testKey(client,"~"); testKey(client,"#"); testKey(client,"@"); testKey(client,";"); testKey(client,":"); testKey(client,"}"); testKey(client,"]"); testKey(client,"{"); testKey(client,"["); testKey(client,"'"); testKey(client,"\""); testKey(client,"+"); testKey(client,"="); testKey(client,"%"); testKey(client,"\u00a5"); testKey(client,"\u030a"); testKey(client,"\r"); testKey(client,"\n"); testKey(client,"\r\t"); testKey(client,"\t"); testKey(client,";"); testKey(client,"?"); testKey(client,"\01"); testKey(client,"\b"); testKey(client,"\uFFFD"); testKey(client,"\u0080"); testKey(client,"\uDC80"); testKey(client,"\uD800"); testKey(client,"\u200F"); testKey(client,"\u009F"); testKey(client,"\u00a0"); testKey(client,"\u2060"); testKey(client,"\uFEFF"); testKey(client,"asdf../.."); testKey(client,"asdf/../.."); testKey(client,"asdf/../../"); testKey(client,"asdf/../../.."); testKey(client,"../..asdf"); testKey(client,"../../asdf"); testKey(client,"..asdf/.."); testKey(client,"..asdf/asdf.."); testKey(client,"../asdf/.."); }
private static void createClient() throws IOException { AWSCredentials credentials = new PropertiesCredentials( LowLevelBatchWriteSyntax.class.getResourceAsStream("AwsCredentials.properties")); client = new AmazonDynamoDBClient(credentials); }