Example usage for com.amazonaws.auth AWSCredentialsProvider AWSCredentialsProvider

List of usage examples for com.amazonaws.auth AWSCredentialsProvider AWSCredentialsProvider

Introduction

In this page you can find the example usage for com.amazonaws.auth AWSCredentialsProvider AWSCredentialsProvider.

Prototype

AWSCredentialsProvider

Source Link

Usage

From source file:c3.ops.priam.defaultimpl.ClearCredential.java

License:Apache License

public AWSCredentialsProvider getAwsCredentialProvider() {
    return new AWSCredentialsProvider() {
        public AWSCredentials getCredentials() {
            return new BasicAWSCredentials(AWS_ACCESS_ID, AWS_KEY);
        }/*from  w w  w.j a v  a2 s  .com*/

        public void refresh() {
            // NOP
        }
    };
}

From source file:com.eucalyptus.simpleworkflow.common.client.WorkflowClientStandalone.java

License:Open Source License

private AWSCredentialsProvider getCredentialsProvider() {
    AWSCredentialsProvider provider = null;
    if (this.credentialPropertyFile != null) {
        provider = new AWSCredentialsProvider() {
            private String accessKey = null;
            private String secretAccessKey = null;

            private void readProperty() throws FileNotFoundException, IOException {
                final FileInputStream stream = new FileInputStream(new File(credentialPropertyFile));
                try {
                    Properties credentialProperties = new Properties();
                    credentialProperties.load(stream);

                    if (credentialProperties.getProperty("accessKey") == null
                            || credentialProperties.getProperty("secretKey") == null) {
                        throw new IllegalArgumentException("The specified file (" + credentialPropertyFile
                                + ") doesn't contain the expected properties 'accessKey' "
                                + "and 'secretKey'.");
                    }/*from   w  w w .jav a 2s.  c om*/
                    accessKey = credentialProperties.getProperty("accessKey");
                    secretAccessKey = credentialProperties.getProperty("secretKey");
                } finally {
                    try {
                        stream.close();
                    } catch (final IOException e) {
                    }
                }
            }

            @Override
            public AWSCredentials getCredentials() {
                if (this.accessKey == null || this.secretAccessKey == null) {
                    try {
                        readProperty();
                    } catch (final Exception ex) {
                        throw new RuntimeException("Failed to read credentials file", ex);
                    }
                }
                return new BasicAWSCredentials(accessKey, secretAccessKey);
            }

            @Override
            public void refresh() {
                this.accessKey = null;
            }
        };
    } else {
        provider = new InstanceProfileCredentialsProvider();
    }

    return provider;
}

From source file:com.example.base.KinesisConnectorExecutor.java

License:Open Source License

public KinesisConnectorExecutor(String configFile, String content) {
    this.content = content;
    InputStream configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile);

    if (configStream == null) {
        String msg = "Could not find resource " + configFile + " in the classpath";
        throw new IllegalStateException(msg);
    }//from w w  w  . j a va 2 s  .co  m
    properties = new Properties();
    try {
        properties.load(configStream);
        configStream.close();
    } catch (IOException e) {
        String msg = "Could not load properties file " + configFile + " from classpath";
        throw new IllegalStateException(msg, e);
    }
    AWSCredentialsProvider prov = new AWSCredentialsProvider() {
        @Override
        public AWSCredentials getCredentials() {
            return new AWSCredentials() {
                @Override
                public String getAWSAccessKeyId() {
                    return "AKIAJMOK3KHKIRPDXQBA";
                }

                @Override
                public String getAWSSecretKey() {
                    return "s2MEQ6k4acTakezkqFdoYWw909DqLwIro8ZeR9Iy";
                }
            };
        }

        @Override
        public void refresh() {

        }
    };
    this.config = new KinesisConnectorConfiguration(properties, prov);
    setupAWSResources();
    setupInputStream();

    // Initialize executor with configurations
    super.initialize(config, content);
}

From source file:com.example.base.StreamSource.java

License:Open Source License

/**
 * Creates a new StreamSource.// w  w w .  j  av  a2s  .c  om
 * 
 * @param config
 *        Configuration to determine which stream to put records to and get {@link AWSCredentialsProvider}
 * @param inputFile
 *        File containing record data to emit on each line
 * @param loopOverStreamSource
 *        Loop over the stream source to continually put records
 */
public StreamSource(String content, KinesisConnectorConfiguration config, String inputFile,
        boolean loopOverStreamSource) {
    this.config = config;
    this.content = content;
    this.inputFile = inputFile;
    this.loopOverInputFile = loopOverStreamSource;
    this.objectMapper = new ObjectMapper();
    kinesisClient = new AmazonKinesisClient(new AWSCredentialsProvider() {
        @Override
        public AWSCredentials getCredentials() {
            return new AWSCredentials() {
                @Override
                public String getAWSAccessKeyId() {
                    return "AKIAJMOK3KHKIRPDXQBA";
                }

                @Override
                public String getAWSSecretKey() {
                    return "s2MEQ6k4acTakezkqFdoYWw909DqLwIro8ZeR9Iy";
                }
            };
        }

        @Override
        public void refresh() {

        }
    });
    kinesisClient.setRegion(RegionUtils.getRegion(config.REGION_NAME));
    if (config.KINESIS_ENDPOINT != null) {
        kinesisClient.setEndpoint(config.KINESIS_ENDPOINT);
    }
    KinesisUtils.createInputStream(config);
}

From source file:com.netflix.dynomitemanager.sidecore.aws.ClearCredential.java

License:Apache License

@Override
public AWSCredentialsProvider getAwsCredentialProvider() {
    return new AWSCredentialsProvider() {
        public AWSCredentials getCredentials() {
            return ClearCredential.this.getCredentials();
        }//from   w  ww  . j  a v  a 2s .  c o  m

        @Override
        public void refresh() {
            // NOP            
        }
    };
}

From source file:com.netflix.priam.defaultimpl.ClearCredential.java

License:Apache License

public AWSCredentialsProvider getAwsCredentialProvider() {
    return new AWSCredentialsProvider() {
        public AWSCredentials getCredentials() {
            return new BasicAWSCredentials(AWS_ACCESS_ID, AWS_KEY);
        }/*from   w  ww  .  j  av  a  2s. co m*/

        public void refresh() {
            // NOP            
        }
    };
}

From source file:com.pinterest.secor.uploader.S3UploadManager.java

License:Apache License

public S3UploadManager(SecorConfig config) {
    super(config);

    final String accessKey = mConfig.getAwsAccessKey();
    final String secretKey = mConfig.getAwsSecretKey();
    final String endpoint = mConfig.getAwsEndpoint();
    final String region = mConfig.getAwsRegion();
    final String awsRole = mConfig.getAwsRole();

    s3Path = mConfig.getS3Path();

    AmazonS3 client;/*from   w w  w .ja v  a  2  s. c om*/
    AWSCredentialsProvider provider;

    ClientConfiguration clientConfiguration = new ClientConfiguration();
    boolean isHttpProxyEnabled = mConfig.getAwsProxyEnabled();

    //proxy settings
    if (isHttpProxyEnabled) {
        LOG.info("Http Proxy Enabled for S3UploadManager");
        String httpProxyHost = mConfig.getAwsProxyHttpHost();
        int httpProxyPort = mConfig.getAwsProxyHttpPort();
        clientConfiguration.setProxyHost(httpProxyHost);
        clientConfiguration.setProxyPort(httpProxyPort);
    }

    if (accessKey.isEmpty() || secretKey.isEmpty()) {
        provider = new DefaultAWSCredentialsProviderChain();
    } else {
        provider = new AWSCredentialsProvider() {
            public AWSCredentials getCredentials() {
                return new BasicAWSCredentials(accessKey, secretKey);
            }

            public void refresh() {
            }
        };
    }

    if (!awsRole.isEmpty()) {
        provider = new STSAssumeRoleSessionCredentialsProvider(provider, awsRole, "secor");
    }

    client = new AmazonS3Client(provider, clientConfiguration);

    if (!endpoint.isEmpty()) {
        client.setEndpoint(endpoint);
    } else if (!region.isEmpty()) {
        client.setRegion(Region.getRegion(Regions.fromName(region)));
    }

    mManager = new TransferManager(client);
}

From source file:com.zero_x_baadf00d.play.module.aws.s3.AmazonS3ModuleInitializer.java

License:Open Source License

/**
 * Create a simple instance of {@code S3Module}.
 *
 * @param lifecycle     The application life cycle
 * @param configuration The application configuration
 * @since 16.03.13/*www.  j  av  a2s. c o  m*/
 */
@Inject
public AmazonS3ModuleInitializer(final ApplicationLifecycle lifecycle, final Config configuration) {
    final String accessKey;
    final String secretKey;

    if (configuration.hasPath("aws.s3.authKey")) {
        accessKey = configuration.getString("aws.s3.authKey");
    } else {
        accessKey = configuration.getString("aws.authKey");
    }
    if (configuration.hasPath("aws.s3.authSecret")) {
        secretKey = configuration.getString("aws.s3.authSecret");
    } else {
        secretKey = configuration.getString("aws.authSecret");
    }
    final String endPoint = configuration.getString("aws.s3.endPoint");
    final String signingRegion = configuration.getString("aws.s3.signingRegion");

    final boolean withPathStyle = configuration.hasPath("aws.s3.withPathStyle")
            && configuration.getBoolean("aws.s3.withPathStyle");
    final boolean withChunkedEncodingDisabled = configuration.hasPath("aws.s3.disableChunkedEncoding")
            && configuration.getBoolean("aws.s3.disableChunkedEncoding");

    PlayS3.bucketName = configuration.getString("aws.s3.bucketName");
    PlayS3.publicUrl = configuration.hasPath("aws.s3.publicUrl") ? configuration.getString("aws.s3.publicUrl")
            : "/";
    if (!PlayS3.publicUrl.endsWith("/")) {
        PlayS3.publicUrl += "/";
    }

    if (accessKey == null || secretKey == null || PlayS3.bucketName == null) {
        throw new RuntimeException("S3Module is not properly configured");
    }

    PlayS3.amazonS3 = AmazonS3ClientBuilder.standard().withCredentials(new AWSCredentialsProvider() {
        @Override
        public AWSCredentials getCredentials() {
            return new BasicAWSCredentials(accessKey, secretKey);
        }

        @Override
        public void refresh() {
            // Not used with basic AWS credentials
        }
    }).withPathStyleAccessEnabled(withPathStyle).withChunkedEncodingDisabled(withChunkedEncodingDisabled)
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, signingRegion))
            .build();
    try {
        PlayS3.amazonS3.createBucket(PlayS3.bucketName);
    } catch (final AmazonS3Exception ex) {
        if (ex.getErrorCode().compareTo("BucketAlreadyOwnedByYou") != 0
                && ex.getErrorCode().compareTo("AccessDenied") != 0) {
            throw ex;
        }
    } finally {
        Logger.info("Using PlayS3 Bucket: " + PlayS3.bucketName);
    }

    lifecycle.addStopHook(() -> CompletableFuture.completedFuture(null));
}

From source file:org.apache.flink.streaming.connectors.kinesis.util.AWSUtil.java

License:Apache License

/**
 * Return a {@link AWSCredentialsProvider} instance corresponding to the configuration properties.
 *
 * @param configProps the configuration properties
 * @return The corresponding AWS Credentials Provider instance
 *///from w w w  . j a  v a 2  s.  co  m
public static AWSCredentialsProvider getCredentialsProvider(final Properties configProps) {
    CredentialProvider credentialProviderType;
    if (!configProps.containsKey(AWSConfigConstants.AWS_CREDENTIALS_PROVIDER)) {
        if (configProps.containsKey(AWSConfigConstants.AWS_ACCESS_KEY_ID)
                && configProps.containsKey(AWSConfigConstants.AWS_SECRET_ACCESS_KEY)) {
            // if the credential provider type is not specified, but the Access Key ID and Secret Key are given, it will default to BASIC
            credentialProviderType = CredentialProvider.BASIC;
        } else {
            // if the credential provider type is not specified, it will default to AUTO
            credentialProviderType = CredentialProvider.AUTO;
        }
    } else {
        credentialProviderType = CredentialProvider
                .valueOf(configProps.getProperty(AWSConfigConstants.AWS_CREDENTIALS_PROVIDER));
    }

    AWSCredentialsProvider credentialsProvider;

    switch (credentialProviderType) {
    case ENV_VAR:
        credentialsProvider = new EnvironmentVariableCredentialsProvider();
        break;
    case SYS_PROP:
        credentialsProvider = new SystemPropertiesCredentialsProvider();
        break;
    case PROFILE:
        String profileName = configProps.getProperty(AWSConfigConstants.AWS_PROFILE_NAME, null);
        String profileConfigPath = configProps.getProperty(AWSConfigConstants.AWS_PROFILE_PATH, null);
        credentialsProvider = (profileConfigPath == null) ? new ProfileCredentialsProvider(profileName)
                : new ProfileCredentialsProvider(profileConfigPath, profileName);
        break;
    case BASIC:
        credentialsProvider = new AWSCredentialsProvider() {
            @Override
            public AWSCredentials getCredentials() {
                return new BasicAWSCredentials(configProps.getProperty(AWSConfigConstants.AWS_ACCESS_KEY_ID),
                        configProps.getProperty(AWSConfigConstants.AWS_SECRET_ACCESS_KEY));
            }

            @Override
            public void refresh() {
                // do nothing
            }
        };
        break;
    default:
    case AUTO:
        credentialsProvider = new DefaultAWSCredentialsProviderChain();
    }

    return credentialsProvider;
}

From source file:org.apache.hadoop.dynamodb.DynamoDBClient.java

License:Open Source License

protected AWSCredentialsProvider getAWSCredentialsProvider(Configuration conf) {
    List<AWSCredentialsProvider> providersList = new ArrayList<>();

    // try to load custom credential provider, fail if a provider is specified but cannot be
    // initialized
    String providerClass = conf.get(DynamoDBConstants.CUSTOM_CREDENTIALS_PROVIDER_CONF);
    if (!Strings.isNullOrEmpty(providerClass)) {
        try {//w w  w.jav a2  s  .com
            providersList.add(
                    (AWSCredentialsProvider) ReflectionUtils.newInstance(Class.forName(providerClass), conf));
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Custom AWSCredentialsProvider not found: " + providerClass, e);
        }
    }

    // try to fetch credentials from core-site
    String accessKey = conf.get(DYNAMODB_CREDENTIAL_PAIR_NAME.getAccessKeyName());
    String secretKey;
    if (Strings.isNullOrEmpty(accessKey)) {
        accessKey = conf.get(DEFAULT_CREDENTIAL_PAIR_NAME.getAccessKeyName());
        secretKey = conf.get(DEFAULT_CREDENTIAL_PAIR_NAME.getSecretKeyName());
    } else {
        secretKey = conf.get(DYNAMODB_CREDENTIAL_PAIR_NAME.getSecretKeyName());
    }

    if (Strings.isNullOrEmpty(accessKey) || Strings.isNullOrEmpty(secretKey)) {
        providersList.add(new InstanceProfileCredentialsProvider());
    } else {
        final AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        providersList.add(new AWSCredentialsProvider() {
            @Override
            public AWSCredentials getCredentials() {
                return credentials;
            }

            @Override
            public void refresh() {
            }
        });
    }

    AWSCredentialsProvider[] providerArray = providersList
            .toArray(new AWSCredentialsProvider[providersList.size()]);

    AWSCredentialsProviderChain providerChain = new AWSCredentialsProviderChain(providerArray);
    providerChain.setReuseLastProvider(true);
    return providerChain;
}