当前位置: 首页>>代码示例>>Java>>正文


Java AWSCredentials类代码示例

本文整理汇总了Java中com.amazonaws.auth.AWSCredentials的典型用法代码示例。如果您正苦于以下问题:Java AWSCredentials类的具体用法?Java AWSCredentials怎么用?Java AWSCredentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AWSCredentials类属于com.amazonaws.auth包,在下文中一共展示了AWSCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: client

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
private AmazonIdentityManagement client() {
    return AmazonIdentityManagementClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(new AWSCredentials() {
                @Override
                public String getAWSAccessKeyId() {
                    return bookmark.getCredentials().getUsername();
                }

                @Override
                public String getAWSSecretKey() {
                    return bookmark.getCredentials().getPassword();
                }
            }))
            .withClientConfiguration(configuration)
            .withRegion(Regions.DEFAULT_REGION).build();
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:17,代码来源:AmazonIdentityConfiguration.java

示例2: get

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
@Override
public Credentials get() {
    if (getIdentity() == null || getIdentity().trim().isEmpty() || getCredential() == null || getCredential().trim().isEmpty()) {
        DefaultAWSCredentialsProviderChain chain = new DefaultAWSCredentialsProviderChain();

        AWSCredentials cred = chain.getCredentials();

        if (cred instanceof BasicSessionCredentials) {
            BasicSessionCredentials sesCred = (BasicSessionCredentials)cred;

            return new SessionCredentials.Builder()
                .identity(sesCred.getAWSAccessKeyId())
                .credential(sesCred.getAWSSecretKey())
                .sessionToken(sesCred.getSessionToken())
                .build();
        } else {
            return new Credentials.Builder<>()
                .identity(cred.getAWSAccessKeyId())
                .credential(cred.getAWSSecretKey())
                .build();
        }
    }

    return super.get();
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:26,代码来源:AwsCredentialsSupplier.java

示例3: testAWSCredentials

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
@Test
public void testAWSCredentials() throws Exception {
    // Ask for connection
    AmazonEC2 client = ec2comm.getEC2();
    assertNotNull(client);
    assertNotNull(credProvider);

    AWSCredentials credentials = credProvider.getCredentials();
    assertEquals("access_key", credentials.getAWSAccessKeyId());
    assertEquals("secret_key", credentials.getAWSSecretKey());

    credProvider.refresh();
    credentials = credProvider.getCredentials();
    assertEquals("access_key", credentials.getAWSAccessKeyId());
    assertEquals("secret_key", credentials.getAWSSecretKey());

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:EC2CommunicationTest.java

示例4: configure

import com.amazonaws.auth.AWSCredentials; //导入依赖的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

示例5: shouldHaveAwsCredentialsIntanceWhenEndpointUrlIsNotProvidedAndProfileIsProvided

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
@Test
public void shouldHaveAwsCredentialsIntanceWhenEndpointUrlIsNotProvidedAndProfileIsProvided() {
    ReflectionTestUtils.setField(config, "ENDPOINT_URL", "");
    ReflectionTestUtils.setField(config, "PROFILE", "default");
    Assert.isInstanceOf(AWSCredentials.class,
            config.awsCredentials(new StubProfileCredentialsProvider()));
}
 
开发者ID:simplymequeeny,项目名称:dynamodb-client-web-gui,代码行数:8,代码来源:AwsConfigTest.java

示例6: start

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
private void start() throws IOException {
    //this.port = findFreeLocalPort(); @see https://github.com/findify/sqsmock/pull/7
    this.api = new SQSService(this.port, 1);
    this.api.start();

    AWSCredentials credentials = new AnonymousAWSCredentials();
    this.sqsClient = new MockSQSClient(credentials);

    this.endpoint = String.format("http://localhost:%s", this.port);
    this.sqsClient.setEndpoint(endpoint);

    this.sqsUrl = this.sqsClient.createQueue(this.getClass().getSimpleName()).getQueueUrl();
    ((MockSQSClient)this.sqsClient).setQueueUrl(this.sqsUrl);

    this.started = true;
}
 
开发者ID:riboseinc,项目名称:aws-codecommit-trigger-plugin,代码行数:17,代码来源:MockAwsSqs.java

示例7: testEnvironmentVariable

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
@Test
public void testEnvironmentVariable() throws Exception {
    Map<String, String> immutableEnv = System.getenv();

    Class<?> unMap = Class.forName("java.util.Collections$UnmodifiableMap");
    Field m = unMap.getDeclaredField("m");
    m.setAccessible(true);

    @SuppressWarnings("unchecked")
    Map<String, String> env = (Map<String, String>) m.get(immutableEnv);

    try {
        env.put(AwsProfileNameLoader.AWS_PROFILE_ENVIRONMENT_VARIABLE, "test");

        ProfileCredentialsProvider provider = newProvider();

        AWSCredentials credentials = provider.getCredentials();
        Assert.assertEquals("test", credentials.getAWSAccessKeyId());
        Assert.assertEquals("test key", credentials.getAWSSecretKey());

    } finally {
        env.remove(AwsProfileNameLoader.AWS_PROFILE_ENVIRONMENT_VARIABLE);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:25,代码来源:ProfileCredentialsProviderTest.java

示例8: assertEqualCredentials

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
private static void assertEqualCredentials(AWSCredentials expected, AWSCredentials actual) {
    assertEquals(expected.getAWSAccessKeyId(),
            actual.getAWSAccessKeyId());
    assertEquals(expected.getAWSAccessKeyId(),
            actual.getAWSAccessKeyId());

    if (expected instanceof AWSSessionCredentials) {
        assertTrue(actual instanceof AWSSessionCredentials);

        AWSSessionCredentials expectedSession = (AWSSessionCredentials)expected;
        AWSSessionCredentials actualSession   = (AWSSessionCredentials)actual;
        assertEquals(expectedSession.getSessionToken(),
                actualSession.getSessionToken());
    } else {
        assertFalse(actual instanceof AWSSessionCredentials);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:18,代码来源:ProfilesConfigFileWriterTest.java

示例9: testTwoProfileWithSameName

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
/**
 * Tests two profiles having same name. The second profile overrides the first profile. Also
 * checks if the AWS Access Key ID and AWS Secret Access Key are mapped properly under the
 * profile.
 */
@Test
public void testTwoProfileWithSameName() throws URISyntaxException {
    ProfilesConfigFile profile = new ProfilesConfigFile(
            ProfileResourceLoader.profilesWithSameProfileName().asFile());

    AWSCredentials defaultCred = profile.getCredentials(DEFAULT_PROFILE_NAME);
    assertNotNull(defaultCred);
    assertTrue(defaultCred instanceof BasicAWSCredentials);

    AWSCredentials testCred = profile.getCredentials(PROFILE_NAME_TEST);
    assertNotNull(testCred);
    assertTrue(testCred instanceof AWSSessionCredentials);
    AWSSessionCredentials testSessionCred = (AWSSessionCredentials) testCred;
    assertEquals(testSessionCred.getAWSAccessKeyId(), "testProfile2");
    assertEquals(testSessionCred.getAWSSecretKey(), "testProfile2");
    assertEquals(testSessionCred.getSessionToken(), "testProfile2");

}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:24,代码来源:CredentialProfilesTest.java

示例10: verifyBaseAfterCopy

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
private static void verifyBaseAfterCopy(final ProgressListener listener,
        final AWSCredentials credentials,
        final RequestMetricCollector collector,
        final AmazonWebServiceRequest from, final AmazonWebServiceRequest to) {
    RequestClientOptions toOptions;
    Map<String, String> headers = to.getCustomRequestHeaders();
    assertTrue(2 == headers.size());
    assertEquals("v1", headers.get("k1"));
    assertEquals("v2", headers.get("k2"));
    Map<String, List<String>> parmas = to.getCustomQueryParameters();
    assertTrue(2 == parmas.size());
    assertEquals(Arrays.asList("v1"), parmas.get("k1"));
    assertEquals(Arrays.asList("v2a", "v2b"), parmas.get("k2"));
    assertSame(listener, to.getGeneralProgressListener());
    assertSame(credentials, to.getRequestCredentials());
    assertSame(collector, to.getRequestMetricCollector());

    assertTrue(1234 == to.getReadLimit());
    toOptions = to.getRequestClientOptions();
    assertEquals(
            from.getRequestClientOptions().getClientMarker(
                    Marker.USER_AGENT),
            toOptions.getClientMarker(Marker.USER_AGENT));
    assertTrue(1234 == toOptions.getReadLimit());
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:26,代码来源:AmazonWebServiceRequestTest.java

示例11: request_credentials_takes_precendence_over_client_credentials

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
@Test
public void request_credentials_takes_precendence_over_client_credentials() {
    final String awsAccessKeyId = "foo";
    final String awsSecretAccessKey = "bar";
    final AWSCredentials reqCredentials = new BasicAWSCredentials(awsAccessKeyId,
                                                                  awsSecretAccessKey);
    EmptyAmazonWebServiceRequest req = new EmptyAmazonWebServiceRequest();
    req.setRequestCredentials(reqCredentials);
    AWSCredentialsProvider actual = CredentialUtils.getCredentialsProvider(req,
                                                                           null);

    Assert.assertThat(actual, Matchers.instanceOf(StaticCredentialsProvider
                                                          .class));
    assertEquals(awsAccessKeyId, actual.getCredentials().getAWSAccessKeyId());
    assertEquals(awsSecretAccessKey, actual.getCredentials().getAWSSecretKey());
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:17,代码来源:CredentialUtilsTest.java

示例12: sign

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
public void sign(SignableRequest<?> request, AWSCredentials credentials) throws SdkClientException {
    AWSCredentials sanitizedCredentials = sanitizeCredentials(credentials);

    if ( sanitizedCredentials instanceof AWSSessionCredentials ) {
        addSessionCredentials(request, (AWSSessionCredentials) sanitizedCredentials);
    }

    String expirationInSeconds = Long.toString(expiration.getTime() / 1000L);

    String canonicalString = RestUtils.makeS3CanonicalString(
            httpVerb, resourcePath, request, expirationInSeconds);

    String signature = super.signAndBase64Encode(canonicalString, sanitizedCredentials.getAWSSecretKey(), SigningAlgorithm.HmacSHA1);

    request.addParameter("AWSAccessKeyId", sanitizedCredentials.getAWSAccessKeyId());
    request.addParameter("Expires", expirationInSeconds);
    request.addParameter("Signature", signature);
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:19,代码来源:S3QueryStringSigner.java

示例13: launchAWSCredentialsWithElasticsearchSettingsTest

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
protected void launchAWSCredentialsWithElasticsearchSettingsTest(Settings singleRepositorySettings, Settings settings,
                                                                 String expectedKey, String expectedSecret) {
    String configName = InternalAwsS3Service.CLIENT_NAME.get(singleRepositorySettings);
    AWSCredentials credentials = InternalAwsS3Service.buildCredentials(logger, deprecationLogger, settings,
        singleRepositorySettings, configName).getCredentials();
    assertThat(credentials.getAWSAccessKeyId(), is(expectedKey));
    assertThat(credentials.getAWSSecretKey(), is(expectedSecret));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:AwsS3ServiceImplTests.java

示例14: AmazonEC2HostProvider

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
public AmazonEC2HostProvider(final AWSCredentials credentials, final ClientConfiguration configuration, String endpoint, Function<Instance, Host> instance_converter) {

        this.instance_converter = instance_converter;
        ec2_client = new AmazonEC2Client(credentials, configuration);
        ec2_client.setEndpoint(endpoint);
        next_host_index = new AtomicInteger();
    }
 
开发者ID:stacs-srg,项目名称:shabdiz,代码行数:8,代码来源:AmazonEC2HostProvider.java

示例15: S3Utils

import com.amazonaws.auth.AWSCredentials; //导入依赖的package包/类
public S3Utils() {
	accountsDirectory = AccountsDirectory.getInstance();
	final Account s3Account = accountsDirectory.getAccount("s3").get();
	final AWSCredentials credentials = new BasicAWSCredentials(
			s3Account.getProperty("accessKey"), s3Account.getProperty("secretKey")
	);

	s3client = AmazonS3ClientBuilder
			.standard()
			.withCredentials(new AWSStaticCredentialsProvider(credentials))
			.withRegion(Regions.US_WEST_1)
			.build();
}
 
开发者ID:syndesisio,项目名称:syndesis-qe,代码行数:14,代码来源:S3Utils.java


注:本文中的com.amazonaws.auth.AWSCredentials类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。