本文整理匯總了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;
}