本文整理汇总了Java中com.amazonaws.auth.PropertiesCredentials类的典型用法代码示例。如果您正苦于以下问题:Java PropertiesCredentials类的具体用法?Java PropertiesCredentials怎么用?Java PropertiesCredentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PropertiesCredentials类属于com.amazonaws.auth包,在下文中一共展示了PropertiesCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
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);
}
}
示例2: testDoubleDots
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
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);
}
}
示例3: getCredentials
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
/**
* 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;
}
示例4: Storage
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
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;
}
示例5: CreateEndpointJob
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
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);
}
}
示例6: loadCredentialFile
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
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);
}
}
示例7: uploadFileToS3
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
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();
}
}
示例8: getAwsCredentials
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
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);
}
}
示例9: EC2Wrapper
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
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());
}
示例10: setup
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
@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
}
示例11: setDynamoDBProperties
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
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));
}
示例12: getCredentials
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
public static AWSCredentials getCredentials(InputStream credentialsInputStream) throws MessagingException {
try {
return new PropertiesCredentials(credentialsInputStream);
} catch (IOException e) {
throw new MessagingException("Could not read properties", e);
}
}
示例13: makeS3Connection
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
/**
* 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;
}
示例14: getAwsCredentials
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
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();
}
}
示例15: initCredentials
import com.amazonaws.auth.PropertiesCredentials; //导入依赖的package包/类
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;
}