Java Code Examples for com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider

The following examples show how to use com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider. These examples are extracted from open source projects. 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 Project: beam   Source File: AwsModuleTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testClasspathPropertiesFileCredentialsProviderSerializationDeserialization()
    throws Exception {
  String credentialsFilePath = "/path/to/file";

  ClasspathPropertiesFileCredentialsProvider credentialsProvider =
      new ClasspathPropertiesFileCredentialsProvider(credentialsFilePath);

  String serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
  AWSCredentialsProvider deserializedCredentialsProvider =
      objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);

  assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());

  Field field =
      ClasspathPropertiesFileCredentialsProvider.class.getDeclaredField("credentialsFilePath");
  field.setAccessible(true);
  String deserializedCredentialsFilePath = (String) field.get(deserializedCredentialsProvider);
  assertEquals(credentialsFilePath, deserializedCredentialsFilePath);
}
 
Example 2
Source Project: beam   Source File: AwsModule.java    License: 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(AWSStaticCredentialsProvider.class.getSimpleName())) {
    return new AWSStaticCredentialsProvider(
        new BasicAWSCredentials(asMap.get(AWS_ACCESS_KEY_ID), asMap.get(AWS_SECRET_KEY)));
  } else if (typeName.equals(PropertiesFileCredentialsProvider.class.getSimpleName())) {
    return new PropertiesFileCredentialsProvider(asMap.get(CREDENTIALS_FILE_PATH));
  } else if (typeName.equals(
      ClasspathPropertiesFileCredentialsProvider.class.getSimpleName())) {
    return new ClasspathPropertiesFileCredentialsProvider(asMap.get(CREDENTIALS_FILE_PATH));
  } else if (typeName.equals(DefaultAWSCredentialsProviderChain.class.getSimpleName())) {
    return new DefaultAWSCredentialsProviderChain();
  } else if (typeName.equals(EnvironmentVariableCredentialsProvider.class.getSimpleName())) {
    return new EnvironmentVariableCredentialsProvider();
  } else if (typeName.equals(SystemPropertiesCredentialsProvider.class.getSimpleName())) {
    return new SystemPropertiesCredentialsProvider();
  } else if (typeName.equals(ProfileCredentialsProvider.class.getSimpleName())) {
    return new ProfileCredentialsProvider();
  } else if (typeName.equals(EC2ContainerCredentialsProviderWrapper.class.getSimpleName())) {
    return new EC2ContainerCredentialsProviderWrapper();
  } else {
    throw new IOException(
        String.format("AWS credential provider type '%s' is not supported", typeName));
  }
}
 
Example 3
/**
 * Creates a {@link PropertiesFileConfiguration} from values provided in a classpath properties file.
 *
 * @param propertiesFile the classpath properties file to load.
 */
public PropertiesFileConfiguration(String propertiesFile) {
    //load properties from configuration properties file
    Properties prop = loadProperty(propertiesFile);

    sqsUrl = prop.getProperty(SQS_URL);
    LibraryUtils.checkArgumentNotNull(sqsUrl, "Cannot find SQS URL in properties file.");

    String accessKey = prop.getProperty(ACCESS_KEY);
    String secretKey = prop.getProperty(SECRET_KEY);

    if (accessKey != null && secretKey != null) {
        awsCredentialsProvider = new ClasspathPropertiesFileCredentialsProvider(propertiesFile);
    }

    s3Region = prop.getProperty(S3_REGION);
    visibilityTimeout = getIntProperty(prop, VISIBILITY_TIMEOUT);

    sqsRegion = prop.getProperty(SQS_REGION);

    threadCount = getIntProperty(prop, THREAD_COUNT);
    threadTerminationDelaySeconds = getIntProperty(prop, THREAD_TERMINATION_DELAY_SECONDS);

    maxEventsPerEmit = getIntProperty(prop, MAX_EVENTS_PER_EMIT);
    enableRawEventInfo = getBooleanProperty(prop, ENABLE_RAW_EVENT_INFO);

    deleteMessageUponFailure  = getBooleanProperty(prop, DELETE_MESSAGE_UPON_FAILURE);
}
 
Example 4
public CustomCredentialsProviderChain() {
    super(new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(),
            new ClasspathPropertiesFileCredentialsProvider(),
            new InstanceProfileCredentialsProvider());
}
 
Example 5
public CustomCredentialsProviderChain() {
  super(new ClasspathPropertiesFileCredentialsProvider(), new InstanceProfileCredentialsProvider(),
      new SystemPropertiesCredentialsProvider(), new EnvironmentVariableCredentialsProvider());
}
 
Example 6
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
 
Example 7
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
 
Example 8
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
 
Example 9
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
 
Example 10
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
 
Example 11
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
 
Example 12
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
 
Example 13
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}