本文整理汇总了Java中com.amazonaws.internal.StaticCredentialsProvider类的典型用法代码示例。如果您正苦于以下问题:Java StaticCredentialsProvider类的具体用法?Java StaticCredentialsProvider怎么用?Java StaticCredentialsProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StaticCredentialsProvider类属于com.amazonaws.internal包,在下文中一共展示了StaticCredentialsProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildCredentials
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
public static AWSCredentialsProvider buildCredentials(Logger logger, DeprecationLogger deprecationLogger,
Settings settings, Settings repositorySettings, String clientName) {
try (SecureString key = getConfigValue(repositorySettings, settings, clientName, S3Repository.ACCESS_KEY_SETTING,
S3Repository.Repository.KEY_SETTING, S3Repository.Repositories.KEY_SETTING);
SecureString secret = getConfigValue(repositorySettings, settings, clientName, S3Repository.SECRET_KEY_SETTING,
S3Repository.Repository.SECRET_SETTING, S3Repository.Repositories.SECRET_SETTING)) {
if (key.length() == 0 && secret.length() == 0) {
logger.debug("Using instance profile credentials");
return new PrivilegedInstanceProfileCredentialsProvider();
} else {
logger.debug("Using basic key/secret credentials");
return new StaticCredentialsProvider(new BasicAWSCredentials(key.toString(), secret.toString()));
}
}
}
示例2: request_credentials_takes_precendence_over_client_credentials
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的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());
}
示例3: testProvide
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
@Test
public void testProvide() {
Env env = new Env().register("DYNAMODB_ENDPOINT", "fakeendpoint");
ClientConfiguration config = new ClientConfiguration();
config.setRetryPolicy(PredefinedRetryPolicies.NO_RETRY_POLICY);
AWSCredentialsProvider credentialsProvider = new StaticCredentialsProvider(
new BasicAWSCredentials("fake_access_key_id", "fake_secret_access_key"));
AmazonDynamoDBFactory factory = new AmazonDynamoDBFactory(env, credentialsProvider, config);
AmazonDynamoDB dynamoDB = factory.provide();
String message = "";
try {
dynamoDB.listTables();
} catch (AmazonClientException e) {
message = e.getMessage();
}
assertTrue(message.startsWith("Unable to execute HTTP request: fakeendpoint"));
factory.dispose(dynamoDB);
}
示例4: getAWSCredentialsProvider
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
/**
* <p> Gets the {@link AWSCredentialsProvider} based on the credentials in the given parameters. </p> <p> Returns {@link DefaultAWSCredentialsProviderChain}
* if either access or secret key is {@code null}. Otherwise returns a {@link StaticCredentialsProvider} with the credentials. </p>
*
* @param params - Access parameters
*
* @return AWS credentials provider implementation
*/
private AWSCredentialsProvider getAWSCredentialsProvider(S3FileTransferRequestParamsDto params)
{
List<AWSCredentialsProvider> providers = new ArrayList<>();
String accessKey = params.getAwsAccessKeyId();
String secretKey = params.getAwsSecretKey();
if (accessKey != null && secretKey != null)
{
providers.add(new StaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)));
}
for (HerdAWSCredentialsProvider herdAWSCredentialsProvider : params.getAdditionalAwsCredentialsProviders())
{
providers.add(new HerdAwsCredentialsProviderWrapper(herdAWSCredentialsProvider));
}
providers.add(new DefaultAWSCredentialsProviderChain());
return new AWSCredentialsProviderChain(providers.toArray(new AWSCredentialsProvider[providers.size()]));
}
示例5: getDynamoClient
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
private AmazonDynamoDBClient getDynamoClient(String tableName) {
AWSCredentialsProvider credentials = new AWSCredentialsProviderChain(new StaticCredentialsProvider(new BasicAWSCredentials("test", "test")));
AmazonDynamoDBClient amazonDynamoDBClient = new AmazonDynamoDBClient(credentials);
amazonDynamoDBClient.setEndpoint("http://localhost:8000");
ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
.withReadCapacityUnits(5L)
.withWriteCapacityUnits(10L);
CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName).withProvisionedThroughput(provisionedThroughput);
ArrayList<AttributeDefinition> attributeDefinitions= new ArrayList<AttributeDefinition>();
attributeDefinitions.add(new AttributeDefinition().withAttributeName("id").withAttributeType("S"));
createTableRequest.setAttributeDefinitions(attributeDefinitions);
ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
tableKeySchema.add(new KeySchemaElement().withAttributeName("id").withKeyType(KeyType.HASH));
createTableRequest.setKeySchema(tableKeySchema);
amazonDynamoDBClient.createTable(createTableRequest);
return amazonDynamoDBClient;
}
示例6: createClient
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
static <T extends AmazonWebServiceClient> T createClient( Class<T> clientType,
Identity identity )
{
Regions r = Regions.US_EAST_1;
if ( StringUtils.isNotBlank( identity.getAwsRegionName() ) )
{
r = Regions.fromName( identity.getAwsRegionName() );
}
AWSCredentialsProvider creds =
new StaticCredentialsProvider(
new BasicAWSCredentials(
identity.getAwsAccessKeyId(),
identity.getAwsSecretKey() ) );
return Region.getRegion( r ).createClient( clientType, creds, null );
}
示例7: getAllProfiles
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
@Deprecated
public Map<String, Profile> getAllProfiles() {
Map<String, Profile> legacyProfiles = new HashMap<String, Profile>();
for (Map.Entry<String, BasicProfile> entry : getAllBasicProfiles().entrySet()) {
final String profileName = entry.getKey();
legacyProfiles.put(profileName,
new Profile(profileName, entry.getValue().getProperties(),
new StaticCredentialsProvider(
getCredentials(profileName))));
}
return legacyProfiles;
}
示例8: Profile
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
public Profile(String profileName, AWSCredentials awsCredentials) {
Map<String, String> properties = new LinkedHashMap<String, String>();
properties.put(ProfileKeyConstants.AWS_ACCESS_KEY_ID, awsCredentials.getAWSAccessKeyId());
properties.put(ProfileKeyConstants.AWS_SECRET_ACCESS_KEY, awsCredentials.getAWSSecretKey());
if (awsCredentials instanceof AWSSessionCredentials) {
AWSSessionCredentials sessionCred = (AWSSessionCredentials)awsCredentials;
properties.put(ProfileKeyConstants.AWS_SESSION_TOKEN, sessionCred.getSessionToken());
}
this.profileName = profileName;
this.properties = properties;
this.awsCredentials = new StaticCredentialsProvider(awsCredentials);
}
示例9: credentialsExplicitlySet_UsesExplicitCredentials
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
@Test
public void credentialsExplicitlySet_UsesExplicitCredentials() throws Exception {
AWSCredentialsProvider provider = new StaticCredentialsProvider(
new BasicAWSCredentials("akid", "skid"));
AwsAsyncClientParams params = builderWithRegion().withCredentials(provider).build()
.getAsyncParams();
assertEquals(provider, params.getCredentialsProvider());
}
示例10: base_credentials_returned_when_no_request_credentials_is_present
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
@Test
public void base_credentials_returned_when_no_request_credentials_is_present() {
final String awsAccessKeyId = "foo";
final String awsSecretAccessKey = "bar";
final StaticCredentialsProvider base = new StaticCredentialsProvider
(new BasicAWSCredentials(awsAccessKeyId, awsSecretAccessKey));
AWSCredentialsProvider actual = CredentialUtils
.getCredentialsProvider((AmazonWebServiceRequest) null, base);
Assert.assertThat(actual, Matchers.instanceOf(StaticCredentialsProvider
.class));
assertEquals(awsAccessKeyId, actual.getCredentials().getAWSAccessKeyId());
assertEquals(awsSecretAccessKey, actual.getCredentials().getAWSSecretKey());
}
示例11: AmazonS3EncryptionClient
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
/**
* @deprecated use {@link AmazonS3EncryptionClientBuilder#withEncryptionMaterials(EncryptionMaterialsProvider)} and
* {@link AmazonS3EncryptionClientBuilder#withCredentials(AWSCredentialsProvider)} and
* {@link AmazonS3EncryptionClientBuilder#withCryptoConfiguration(CryptoConfiguration)} and
* {@link AmazonS3EncryptionClientBuilder#withClientConfiguration(ClientConfiguration)}
*/
@Deprecated
public AmazonS3EncryptionClient(AWSCredentials credentials,
EncryptionMaterialsProvider encryptionMaterialsProvider,
ClientConfiguration clientConfig, CryptoConfiguration cryptoConfig) {
this(new StaticCredentialsProvider(credentials),
encryptionMaterialsProvider, clientConfig, cryptoConfig);
}
示例12: createConnection
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
@Override
public Connection createConnection() throws JMSException {
Builder builder = SQSConnectionFactory.builder().withAWSCredentialsProvider(new StaticCredentialsProvider(new BasicAWSCredentials(this.accessKey,this.secretKey)));
if (this.regionName != null && ! this.regionName.isEmpty()) {
builder = builder.withRegionName(regionName);
}
this.factory = builder.build();
return factory.createConnection();
}
示例13: getCredentials
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
/**
*
* @return
*/
private AWSCredentialsProvider getCredentials() {
return new AWSCredentialsProviderChain(new StaticCredentialsProvider(
new AppenderCredentials()), new SystemPropertiesCredentialsProvider(),
new EnvironmentVariableCredentialsProvider(),
new ProfileCredentialsProvider(),
new InstanceProfileCredentialsProvider());
}
示例14: getAwsCredentialsProvider
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
private AWSCredentialsProvider getAwsCredentialsProvider(URI uri, Configuration conf)
{
Optional<AWSCredentials> credentials = getAwsCredentials(uri, conf);
if (credentials.isPresent()) {
return new StaticCredentialsProvider(credentials.get());
}
if (useInstanceCredentials) {
return new InstanceProfileCredentialsProvider();
}
throw new RuntimeException("S3 credentials not configured");
}
示例15: testStaticCredentials
import com.amazonaws.internal.StaticCredentialsProvider; //导入依赖的package包/类
@Test
public void testStaticCredentials()
throws Exception
{
Configuration config = new Configuration();
config.set(PrestoS3FileSystem.S3_ACCESS_KEY, "test_secret_access_key");
config.set(PrestoS3FileSystem.S3_SECRET_KEY, "test_access_key_id");
// the static credentials should be preferred
try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) {
fs.initialize(new URI("s3n://test-bucket/"), config);
assertInstanceOf(getAwsCredentialsProvider(fs), StaticCredentialsProvider.class);
}
}