當前位置: 首頁>>代碼示例>>Java>>正文


Java AWSCredentialsProvider.getCredentials方法代碼示例

本文整理匯總了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;
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:24,代碼來源:AWSCredentialsConfigurator.java

示例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);
    }
}
 
開發者ID:schibsted,項目名稱:strongbox,代碼行數:25,代碼來源:GroupModel.java

示例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;
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:18,代碼來源:AmazonHttpClient.java

示例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();
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:18,代碼來源:ProfilesConfigFile.java

示例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"));
}
 
開發者ID:HotelsDotCom,項目名稱:circus-train,代碼行數:10,代碼來源:SnsConfigurationTest.java

示例6: setCredentialsProvider

import com.amazonaws.auth.AWSCredentialsProvider; //導入方法依賴的package包/類
public void setCredentialsProvider(AWSCredentialsProvider credentialsProvider) {
    // Make sure they're usable first
    credentialsProvider.getCredentials();
    this.credentialsProvider = credentialsProvider;
}
 
開發者ID:datamachines,項目名稱:KafkaToSQS,代碼行數:6,代碼來源:AWSKafkaConfig.java


注:本文中的com.amazonaws.auth.AWSCredentialsProvider.getCredentials方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。