本文整理汇总了Java中com.amazonaws.auth.AWSCredentialsProvider.getCredentials方法的典型用法代码示例。如果您正苦于以下问题:Java AWSCredentialsProvider.getCredentials方法的具体用法?Java AWSCredentialsProvider.getCredentials怎么用?Java AWSCredentialsProvider.getCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.auth.AWSCredentialsProvider
的用法示例。
在下文中一共展示了AWSCredentialsProvider.getCredentials方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import com.amazonaws.auth.AWSCredentialsProvider; //导入方法依赖的package包/类
@Override
public Credentials configure(final Host host) {
final Credentials credentials = host.getCredentials();
// Only for AWS
if(host.getHostname().endsWith(PreferencesFactory.get().getProperty("s3.hostname.default"))) {
if(!credentials.validate(host.getProtocol(), new LoginOptions(host.getProtocol()).password(false))) {
// Lookup from default profile if no access key is set in bookmark
for(AWSCredentialsProvider provider : providers) {
try {
final AWSCredentials c = provider.getCredentials();
credentials.setUsername(c.getAWSAccessKeyId());
credentials.setPassword(c.getAWSSecretKey());
break;
}
catch(SdkClientException e) {
log.debug(String.format("Ignore failure loading credentials from provider %s", provider));
// Continue searching with next provider
}
}
}
}
return credentials;
}
示例2: resolveBaseCredentials
import com.amazonaws.auth.AWSCredentialsProvider; //导入方法依赖的package包/类
private AWSCredentialsProvider resolveBaseCredentials(final ClientConfiguration clientConfiguration, final ProfileIdentifier profileIdentifier) {
try {
AWSCredentialsProvider credentialsProvider = new CustomCredentialsProviderChain(clientConfiguration, profileIdentifier, MFAToken.defaultMFATokenSupplier());
// Test if getCredentials will throw
credentialsProvider.getCredentials();
return credentialsProvider;
} catch (Exception e) {
throw new RuntimeException(String.format("Failed to resolve credentials.\n" +
"\n" +
"If you entered an MFA token, the token was incorrect, or the MFA is misconfigured\n" +
"\n" +
"The following locations are included in the credentials chain:\n" +
" - environment variables\n" +
" - system properties\n" +
" - credential file (%s) and config file (%s)\n" +
" - ec2 container metadata\n" +
"\n" +
"Please refer to the documentation for how to configure credentials",
AWSCLIConfigFile.getCredentialProfilesFile().map(File::getAbsolutePath).orElse("not specified"),
AWSCLIConfigFile.getConfigFile().map(File::getAbsolutePath).orElse("not specified")), e);
}
}
示例3: getCredentialsFromContext
import com.amazonaws.auth.AWSCredentialsProvider; //导入方法依赖的package包/类
/**
* Returns the credentials from the execution if exists. Else returns null.
*/
private AWSCredentials getCredentialsFromContext() {
final AWSCredentialsProvider credentialsProvider = executionContext.getCredentialsProvider();
AWSCredentials credentials = null;
if (credentialsProvider != null) {
awsRequestMetrics.startEvent(Field.CredentialsRequestTime);
try {
credentials = credentialsProvider.getCredentials();
} finally {
awsRequestMetrics.endEvent(Field.CredentialsRequestTime);
}
}
return credentials;
}
示例4: getCredentials
import com.amazonaws.auth.AWSCredentialsProvider; //导入方法依赖的package包/类
/**
* Returns the AWS credentials for the specified profile.
*/
public AWSCredentials getCredentials(String profileName) {
final AWSCredentialsProvider provider = credentialProviderCache.get(profileName);
if (provider != null) {
return provider.getCredentials();
} else {
BasicProfile profile = allProfiles.getProfile(profileName);
if (profile == null) {
throw new IllegalArgumentException("No AWS profile named '" + profileName + "'");
}
final AWSCredentialsProvider newProvider = fromProfile(profile);
credentialProviderCache.put(profileName, newProvider);
return newProvider.getCredentials();
}
}
示例5: credentials
import com.amazonaws.auth.AWSCredentialsProvider; //导入方法依赖的package包/类
@Test
public void credentials() throws IOException {
when(conf.getPassword("access.key")).thenReturn("accessKey".toCharArray());
when(conf.getPassword("secret.key")).thenReturn("secretKey".toCharArray());
AWSCredentialsProvider credentialsProvider = configuration.awsCredentialsProvider(conf);
AWSCredentials awsCredentials = credentialsProvider.getCredentials();
assertThat(awsCredentials.getAWSAccessKeyId(), is("accessKey"));
assertThat(awsCredentials.getAWSSecretKey(), is("secretKey"));
}
示例6: setCredentialsProvider
import com.amazonaws.auth.AWSCredentialsProvider; //导入方法依赖的package包/类
public void setCredentialsProvider(AWSCredentialsProvider credentialsProvider) {
// Make sure they're usable first
credentialsProvider.getCredentials();
this.credentialsProvider = credentialsProvider;
}