本文整理汇总了Java中org.jets3t.service.security.AWSCredentials类的典型用法代码示例。如果您正苦于以下问题:Java AWSCredentials类的具体用法?Java AWSCredentials怎么用?Java AWSCredentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AWSCredentials类属于org.jets3t.service.security包,在下文中一共展示了AWSCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
public AWSCredentials get() throws BackgroundException {
final Host address = new HostParser(factory).get(url);
final Path access = new Path(address.getDefaultPath(), EnumSet.of(Path.Type.file));
address.setDefaultPath(String.valueOf(Path.DELIMITER));
final DAVSession connection = new DAVSession(address, trust, key);
connection.withListener(transcript).open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
final InputStream in = new DAVReadFeature(connection).read(access, new TransferStatus(), new DisabledConnectionCallback());
try {
final AWSCredentials credentials = this.parse(in);
connection.close();
return credentials;
}
finally {
connection.removeListener(transcript);
}
}
示例2: RequestEntityRestStorageService
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
public RequestEntityRestStorageService(final S3Session session,
final Jets3tProperties properties,
final HttpClientBuilder configuration) {
super(session.getHost().getCredentials().isAnonymousLogin() ? null :
new AWSCredentials(null, null) {
@Override
public String getAccessKey() {
return session.getHost().getCredentials().getUsername();
}
@Override
public String getSecretKey() {
return session.getHost().getCredentials().getPassword();
}
},
new PreferencesUseragentProvider().get(), null, properties);
this.session = session;
configuration.disableContentCompression();
configuration.setRetryHandler(new S3HttpRequestRetryHandler(this, preferences.getInteger("http.connections.retry")));
configuration.setRedirectStrategy(new DefaultRedirectStrategy() {
@Override
public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException {
if(response.containsHeader("x-amz-bucket-region")) {
final String host = ((HttpUriRequest) request).getURI().getHost();
if(!StringUtils.equals(session.getHost().getHostname(), host)) {
regionEndpointCache.putRegionForBucketName(
StringUtils.split(StringUtils.removeEnd(((HttpUriRequest) request).getURI().getHost(), session.getHost().getHostname()), ".")[0],
response.getFirstHeader("x-amz-bucket-region").getValue());
}
}
return super.getRedirect(request, response, context);
}
});
this.setHttpClient(configuration.build());
}
示例3: create
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
/**
* Generates a signed URL string that will grant access to an S3 resource (bucket or object)
* to whoever uses the URL up until the time specified.
*
* @param host Hostname
* @param bucket the name of the bucket to include in the URL, must be a valid bucket name.
* @param key the name of the object to include in the URL, if null only the bucket name is used.
* @param expiry Milliseconds
* @return a URL signed in such a way as to grant access to an S3 resource to whoever uses it.
*/
public String create(final Host host, final String user, final String secret,
final String bucket, final String region, final String key,
final long expiry) {
final String requestSignatureVersion;
if(StringUtils.isNotBlank(region)) {
requestSignatureVersion = S3Protocol.AuthenticationHeaderSignatureVersion.AWS4HMACSHA256.toString();
}
else {
requestSignatureVersion = S3Protocol.AuthenticationHeaderSignatureVersion.AWS2.toString();
}
return new RestS3Service(new AWSCredentials(StringUtils.strip(user), StringUtils.strip(secret))) {
@Override
public String getEndpoint() {
return host.getHostname();
}
}.createSignedUrlUsingSignatureVersion(requestSignatureVersion,
region, "GET", bucket, key, null, null, expiry / 1000, false, true, false);
}
示例4: testParse
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
@Test
public void testParse() throws Exception {
final AWSCredentials c = new AWSSessionCredentialsRetriever(new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DisabledTranscriptListener(),
"http://169.254.169.254/latest/meta-data/iam/security-credentials/s3access")
.parse(IOUtils.toInputStream("{\n" +
" \"Code\" : \"Success\",\n" +
" \"LastUpdated\" : \"2012-04-26T16:39:16Z\",\n" +
" \"Type\" : \"AWS-HMAC\",\n" +
" \"AccessKeyId\" : \"AKIAIOSFODNN7EXAMPLE\",\n" +
" \"SecretAccessKey\" : \"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY\",\n" +
" \"Token\" : \"token\",\n" +
" \"Expiration\" : \"2012-04-27T22:39:16Z\"\n" +
"}", Charset.defaultCharset()));
assertEquals("AKIAIOSFODNN7EXAMPLE", c.getAccessKey());
assertEquals("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", c.getSecretKey());
assertEquals("token", ((AWSSessionCredentials) c).getSessionToken());
}
示例5: initialize
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
@Override
public void initialize(URI uri, Configuration conf) throws IOException {
S3Credentials s3Credentials = new S3Credentials();
s3Credentials.initialize(uri, conf);
try {
AWSCredentials awsCredentials =
new AWSCredentials(s3Credentials.getAccessKey(),
s3Credentials.getSecretAccessKey());
this.s3Service = new RestS3Service(awsCredentials);
} catch (S3ServiceException e) {
handleException(e);
}
multipartEnabled =
conf.getBoolean("fs.s3n.multipart.uploads.enabled", false);
multipartBlockSize = Math.min(
conf.getLong("fs.s3n.multipart.uploads.block.size", 64 * 1024 * 1024),
MAX_PART_SIZE);
multipartCopyBlockSize = Math.min(
conf.getLong("fs.s3n.multipart.copy.block.size", MAX_PART_SIZE),
MAX_PART_SIZE);
serverSideEncryptionAlgorithm = conf.get("fs.s3n.server-side-encryption-algorithm");
bucket = new S3Bucket(uri.getHost());
}
示例6: initialize
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
@Override
public void initialize(URI uri, Configuration conf) throws IOException {
this.conf = conf;
S3Credentials s3Credentials = new S3Credentials();
s3Credentials.initialize(uri, conf);
try {
AWSCredentials awsCredentials =
new AWSCredentials(s3Credentials.getAccessKey(),
s3Credentials.getSecretAccessKey());
this.s3Service = new RestS3Service(awsCredentials);
} catch (S3ServiceException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
}
throw new S3Exception(e);
}
bucket = new S3Bucket(uri.getHost());
this.bufferSize = conf.getInt(
S3FileSystemConfigKeys.S3_STREAM_BUFFER_SIZE_KEY,
S3FileSystemConfigKeys.S3_STREAM_BUFFER_SIZE_DEFAULT
);
}
示例7: initialize
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
public void initialize(URI uri, Configuration conf) throws IOException {
S3Credentials s3Credentials = new S3Credentials();
s3Credentials.initialize(uri, conf);
try {
AWSCredentials awsCredentials =
new AWSCredentials(s3Credentials.getAccessKey(),
s3Credentials.getSecretAccessKey());
this.s3Service = new RestS3Service(awsCredentials);
} catch (S3ServiceException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
}
throw new S3Exception(e);
}
bucket = new S3Bucket(uri.getHost());
}
示例8: initialize
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
public void initialize(URI uri, Configuration conf) throws IOException {
this.conf = conf;
S3Credentials s3Credentials = new S3Credentials();
s3Credentials.initialize(uri, conf);
try {
AWSCredentials awsCredentials =
new AWSCredentials(s3Credentials.getAccessKey(),
s3Credentials.getSecretAccessKey());
this.s3Service = new RestS3Service(awsCredentials);
} catch (S3ServiceException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
}
throw new S3Exception(e);
}
bucket = new S3Bucket(uri.getHost());
this.bufferSize = conf.getInt("io.file.buffer.size", 4096);
}
示例9: refreshStoredCredentialsTable
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
/**
* Refreshes the table of stored AWS credentials by finding <tt>*.enc</tt> files in the
* directory specified as the Cockpit home folder.
*
*/
public void refreshStoredCredentialsTable() {
nicknamesTableModel.removeAll();
try {
File[] files = cockpitHomeFolder.listFiles();
for (int i = 0; files != null && i < files.length; i++) {
File candidateFile = files[i];
if (candidateFile.getName().endsWith(".enc")) {
// Load partial details from credentials file.
AWSCredentials credentials = AWSCredentials.load(null, candidateFile);
nicknamesTableModel.addAWSCredentialsFile(
credentials, candidateFile);
}
}
} catch (Exception e) {
String message = "Unable to find AWS Credential files in the folder "
+ cockpitHomeFolder.getAbsolutePath();
log.error(message, e);
ErrorDialog.showDialog(ownerFrame, hyperlinkListener, message, e);
}
}
示例10: addAWSCredentialsFile
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
public int addAWSCredentialsFile(AWSCredentials awsCredentials, File credentialsFile) {
int insertRow =
Collections.binarySearch(awsCredentialsList, awsCredentials, new Comparator() {
public int compare(Object o1, Object o2) {
String name1 = ((AWSCredentials)o1).getFriendlyName();
String name2 = ((AWSCredentials)o2).getFriendlyName();
int result = name1.compareToIgnoreCase(name2);
return result;
}
});
if (insertRow >= 0) {
// We already have an item with this key, replace it.
awsCredentialsList.remove(insertRow);
credentialFileList.remove(insertRow);
this.removeRow(insertRow);
} else {
insertRow = (-insertRow) - 1;
}
// New object to insert.
awsCredentialsList.add(insertRow, awsCredentials);
credentialFileList.add(insertRow, credentialsFile);
this.insertRow(insertRow, new Object[] {awsCredentials.getFriendlyName()});
return insertRow;
}
示例11: saveImage
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
private void saveImage(String filename, MultipartFile image)
throws ImageUploadException {
try {
AWSCredentials awsCredentials =
new AWSCredentials(s3AccessKey, s3SecretKey);
S3Service s3 = new RestS3Service(awsCredentials);
S3Bucket imageBucket = s3.getBucket("spitterImages");
S3Object imageObject = new S3Object(filename);
imageObject.setDataInputStream(
new ByteArrayInputStream(image.getBytes()));
imageObject.setContentLength(image.getBytes().length);
imageObject.setContentType("image/jpeg");
AccessControlList acl = new AccessControlList();
acl.setOwner(imageBucket.getOwner());
acl.grantPermission(GroupGrantee.ALL_USERS,
Permission.PERMISSION_READ);
imageObject.setAcl(acl);
s3.putObject(imageBucket, imageObject);
} catch (Exception e) {
throw new ImageUploadException("Unable to save image", e);
}
}
示例12: initialize
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
@Override
public void initialize(URI uri, Configuration conf) throws IOException {
S3Credentials s3Credentials = new S3Credentials();
s3Credentials.initialize(uri, conf);
try {
AWSCredentials awsCredentials =
new AWSCredentials(s3Credentials.getAccessKey(),
s3Credentials.getSecretAccessKey());
this.s3Service = new RestS3Service(awsCredentials);
} catch (S3ServiceException e) {
handleS3ServiceException(e);
}
multipartEnabled =
conf.getBoolean("fs.s3n.multipart.uploads.enabled", false);
multipartBlockSize = Math.min(
conf.getLong("fs.s3n.multipart.uploads.block.size", 64 * 1024 * 1024),
MAX_PART_SIZE);
multipartCopyBlockSize = Math.min(
conf.getLong("fs.s3n.multipart.copy.block.size", MAX_PART_SIZE),
MAX_PART_SIZE);
bucket = new S3Bucket(uri.getHost());
}
示例13: initialize
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
private void initialize() throws ServiceException, S3ServiceException {
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 AWSCredentials(awsAccessKey,
awsSecretKey);
s3service = new RestS3Service(credentials);
bucket = new S3Bucket("starter content repository");
storageService = new ThreadedS3Service(s3service, this);
fileUtils = new FileUtils(s3service);
}
示例14: S3Service
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
/**
* Construct an <code>S3Service</code> identified by the given user credentials.
*
* @param awsCredentials
* the S3 user credentials to use when communicating with S3, may be null in which case the
* communication is done as an anonymous user.
* @param invokingApplicationDescription
* a short description of the application using the service, suitable for inclusion in a
* user agent string for REST/HTTP requests. Ideally this would include the application's
* version number, for example: <code>Cockpit/0.6.1</code> or <code>My App Name/1.0</code>
* @param jets3tProperties
* JetS3t properties that will be applied within this service.
* @throws S3ServiceException
*/
protected S3Service(AWSCredentials awsCredentials, String invokingApplicationDescription,
Jets3tProperties jets3tProperties) throws S3ServiceException
{
this.awsCredentials = awsCredentials;
this.invokingApplicationDescription = invokingApplicationDescription;
this.jets3tProperties = jets3tProperties;
this.isHttpsOnly = jets3tProperties.getBoolProperty("s3service.https-only", true);
this.internalErrorRetryMax = jets3tProperties.getIntProperty("s3service.internal-error-retry-max", 5);
this.awsDevPayUserToken = jets3tProperties.getStringProperty("devpay.user-token", null);
this.awsDevPayProductToken = jets3tProperties.getStringProperty("devpay.product-token", null);
// Configure the InetAddress DNS caching times to work well with S3. The cached DNS will
// timeout after 5 minutes, while failed DNS lookups will be retried after 1 second.
System.setProperty("networkaddress.cache.ttl", "300");
System.setProperty("networkaddress.cache.negative.ttl", "1");
}
示例15: s3Service
import org.jets3t.service.security.AWSCredentials; //导入依赖的package包/类
@Provides
@Singleton
public Optional<S3Service> s3Service(Optional<S3Configuration> config) throws S3ServiceException {
if (!config.isPresent()) {
return Optional.absent();
}
return Optional.<S3Service>of(new RestS3Service(new AWSCredentials(config.get().getS3AccessKey(), config.get().getS3SecretKey())));
}