Java Code Examples for software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider#create()

The following examples show how to use software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: S3BundlePersistenceProvider.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
private AwsCredentialsProvider getCredentialsProvider(final ProviderConfigurationContext configurationContext) {
    final String credentialsProviderValue = configurationContext.getProperties().get(CREDENTIALS_PROVIDER_PROP);
    if (StringUtils.isBlank(credentialsProviderValue)) {
        throw new ProviderCreationException("The property '" + CREDENTIALS_PROVIDER_PROP + "' must be provided");
    }

    CredentialProvider credentialProvider;
    try {
        credentialProvider = CredentialProvider.valueOf(credentialsProviderValue);
    } catch (Exception e) {
        throw new ProviderCreationException("The property '" + CREDENTIALS_PROVIDER_PROP + "' must be one of ["
                + CredentialProvider.STATIC + ", " + CredentialProvider.DEFAULT_CHAIN + " ]");
    }

    if (CredentialProvider.STATIC == credentialProvider) {
        final String accesKeyValue = configurationContext.getProperties().get(ACCESS_KEY_PROP);
        final String secretAccessKey = configurationContext.getProperties().get(SECRET_ACCESS_KEY_PROP);

        if (StringUtils.isBlank(accesKeyValue) || StringUtils.isBlank(secretAccessKey)) {
            throw new ProviderCreationException("The properties '" + ACCESS_KEY_PROP + "' and '" + SECRET_ACCESS_KEY_PROP
                    + "' must be provided when using " + CredentialProvider.STATIC + " credentials provider");
        }

        LOGGER.debug("Creating StaticCredentialsProvider");
        final AwsCredentials awsCredentials = AwsBasicCredentials.create(accesKeyValue, secretAccessKey);
        return StaticCredentialsProvider.create(awsCredentials);

    } else {
        LOGGER.debug("Creating DefaultCredentialsProvider");
        return DefaultCredentialsProvider.create();
    }
}
 
Example 2
Source File: AwsModule.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public AwsCredentialsProvider deserializeWithType(
    JsonParser jsonParser, DeserializationContext context, TypeDeserializer typeDeserializer)
    throws IOException {
  Map<String, String> asMap =
      jsonParser.readValueAs(new TypeReference<Map<String, String>>() {});

  String typeNameKey = typeDeserializer.getPropertyName();
  String typeName = asMap.get(typeNameKey);
  if (typeName == null) {
    throw new IOException(
        String.format("AWS credentials provider type name key '%s' not found", typeNameKey));
  }

  if (typeName.equals(StaticCredentialsProvider.class.getSimpleName())) {
    return StaticCredentialsProvider.create(
        AwsBasicCredentials.create(asMap.get(ACCESS_KEY_ID), asMap.get(SECRET_ACCESS_KEY)));
  } else if (typeName.equals(DefaultCredentialsProvider.class.getSimpleName())) {
    return DefaultCredentialsProvider.create();
  } else if (typeName.equals(EnvironmentVariableCredentialsProvider.class.getSimpleName())) {
    return EnvironmentVariableCredentialsProvider.create();
  } else if (typeName.equals(SystemPropertyCredentialsProvider.class.getSimpleName())) {
    return SystemPropertyCredentialsProvider.create();
  } else if (typeName.equals(ProfileCredentialsProvider.class.getSimpleName())) {
    return ProfileCredentialsProvider.create();
  } else if (typeName.equals(ContainerCredentialsProvider.class.getSimpleName())) {
    return ContainerCredentialsProvider.builder().build();
  } else {
    throw new IOException(
        String.format("AWS credential provider type '%s' is not supported", typeName));
  }
}
 
Example 3
Source File: AwsModuleTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testAwsCredentialsProviderSerializationDeserialization() throws Exception {
  AwsCredentialsProvider credentialsProvider = DefaultCredentialsProvider.create();
  String serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
  AwsCredentialsProvider deserializedCredentialsProvider =
      objectMapper.readValue(serializedCredentialsProvider, DefaultCredentialsProvider.class);
  assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());

  credentialsProvider = EnvironmentVariableCredentialsProvider.create();
  serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
  deserializedCredentialsProvider =
      objectMapper.readValue(serializedCredentialsProvider, AwsCredentialsProvider.class);
  assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());

  credentialsProvider = SystemPropertyCredentialsProvider.create();
  serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
  deserializedCredentialsProvider =
      objectMapper.readValue(serializedCredentialsProvider, AwsCredentialsProvider.class);
  assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());

  credentialsProvider = ProfileCredentialsProvider.create();
  serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
  deserializedCredentialsProvider =
      objectMapper.readValue(serializedCredentialsProvider, AwsCredentialsProvider.class);
  assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());

  credentialsProvider = ContainerCredentialsProvider.builder().build();
  serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
  deserializedCredentialsProvider =
      objectMapper.readValue(serializedCredentialsProvider, AwsCredentialsProvider.class);
  assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
}
 
Example 4
Source File: S3ClientConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public AwsCredentialsProvider awsCredentialsProvider(S3ClientConfigurarionProperties s3props) {

    if (StringUtils.isBlank(s3props.getAccessKeyId())) {
        // Return default provider
        return DefaultCredentialsProvider.create();
    } 
    else {
        // Return custom credentials provider
        return () -> {
            AwsCredentials creds = AwsBasicCredentials.create(s3props.getAccessKeyId(), s3props.getSecretAccessKey());
            return creds;
        };
    }
}
 
Example 5
Source File: TranscribeStreamingIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
private static AwsCredentialsProvider getCredentials() {
    return DefaultCredentialsProvider.create();
}
 
Example 6
Source File: TranscribeStreamingDemoApp.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
private static AwsCredentialsProvider getCredentials() {
    return DefaultCredentialsProvider.create();
}
 
Example 7
Source File: AwsOptions.java    From beam with Apache License 2.0 4 votes vote down vote up
@Override
public AwsCredentialsProvider create(PipelineOptions options) {
  return DefaultCredentialsProvider.create();
}
 
Example 8
Source File: AwsDefaultProviderChainPlugin.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Override
public software.amazon.awssdk.auth.credentials.AwsCredentialsProvider getV2CredentialsProvider() {
    return DefaultCredentialsProvider.create();
}