List of usage examples for com.amazonaws.auth AWSCredentialsProvider AWSCredentialsProvider
AWSCredentialsProvider
From source file:org.apache.pulsar.io.kinesis.KinesisSink.java
License:Apache License
private AWSCredentialsProvider defaultCredentialProvider(String accessKey, String secretKey) { return new AWSCredentialsProvider() { @Override//w w w. j av a 2 s.c o m public AWSCredentials getCredentials() { return new AWSCredentials() { @Override public String getAWSAccessKeyId() { return accessKey; } @Override public String getAWSSecretKey() { return secretKey; } }; } @Override public void refresh() { // no-op } }; }
From source file:org.geowebcache.s3.S3BlobStoreInfo.java
License:Open Source License
private AWSCredentialsProvider getCredentialsProvider() { if (null != awsSecretKey && null != awsAccessKey) { return new AWSCredentialsProvider() { @Override/*from w w w. j a v a2 s. c om*/ public AWSCredentials getCredentials() { if ("".equals(awsAccessKey) && "".equals(awsSecretKey)) { return new AnonymousAWSCredentials(); } return new BasicAWSCredentials(awsAccessKey, awsSecretKey); } @Override public void refresh() { } }; } return new DefaultAWSCredentialsProviderChain(); }
From source file:org.traccar.database.DataManager.java
License:Apache License
/** * Initialize database/*from www. j a v a 2 s .c o m*/ */ private void initDatabase(Properties properties) throws Exception { // Load driver String driver = properties.getProperty("database.driver"); if (driver != null) { String driverFile = properties.getProperty("database.driverFile"); if (driverFile != null) { URL url = new URL("jar:file:" + new File(driverFile).getAbsolutePath() + "!/"); URLClassLoader cl = new URLClassLoader(new URL[] { url }); Driver d = (Driver) Class.forName(driver, true, cl).newInstance(); DriverManager.registerDriver(new DriverDelegate(d)); } else { Class.forName(driver); } } // Initialize data source ComboPooledDataSource ds = new ComboPooledDataSource(); ds.setDriverClass(properties.getProperty("database.driver")); ds.setJdbcUrl(properties.getProperty("database.url")); ds.setUser(properties.getProperty("database.user")); ds.setPassword(properties.getProperty("database.password")); ds.setIdleConnectionTestPeriod(600); ds.setTestConnectionOnCheckin(true); dataSource = ds; // Load statements from configuration String query; query = properties.getProperty("database.selectDevice"); if (query != null) { queryGetDevices = new NamedParameterStatement(query, dataSource); } awsAccessKeyId = properties.getProperty("aws.accessKey"); awsSecretAccessKey = properties.getProperty("aws.accessSecret"); String awsSQSQueueName = properties.getProperty("aws.queueName"); if (awsAccessKeyId != null && awsSecretAccessKey != null) { AWSCredentialsProvider credentialsProvider = new AWSCredentialsProvider() { @Override public AWSCredentials getCredentials() { return new AWSCredentials() { @Override public String getAWSAccessKeyId() { return awsAccessKeyId; } @Override public String getAWSSecretKey() { return awsSecretAccessKey; } }; } @Override public void refresh() { } }; snsClient = new AmazonSNSClient(credentialsProvider); snsClient.setRegion(Region.getRegion(Regions.AP_SOUTHEAST_1)); GsonBuilder builder = new GsonBuilder(); gson = builder.create(); if (awsSQSQueueName != null) { // Create the connection factory using the environment variable credential provider. // Connections this factory creates can talk to the queues in us-east-1 region. SQSConnectionFactory connectionFactory = SQSConnectionFactory.builder() .withRegion(Region.getRegion(Regions.AP_SOUTHEAST_1)) .withAWSCredentialsProvider(credentialsProvider).build(); // Create the connection. SQSConnection connection = connectionFactory.createConnection(); // Get the wrapped client AmazonSQSMessagingClientWrapper client = connection.getWrappedAmazonSQSClient(); // Create an SQS queue named 'TestQueue' if it does not already exist. if (!client.queueExists(awsSQSQueueName)) { client.createQueue(awsSQSQueueName); } // Create the non-transacted session with AUTO_ACKNOWLEDGE mode Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Create a queue identity with name 'TestQueue' in the session Queue queue = session.createQueue(awsSQSQueueName); // Create a consumer for the 'TestQueue'. MessageConsumer consumer = session.createConsumer(queue); // Instantiate and set the message listener for the consumer. consumer.setMessageListener(new AWSSqsMessageListener()); // Start receiving incoming messages. connection.start(); } } query = properties.getProperty("database.insertPosition"); if (query != null) { queryAddPosition = new NamedParameterStatement(query, dataSource, Statement.RETURN_GENERATED_KEYS); } query = properties.getProperty("database.updatePosition"); if (query != null) { queryUpdatePosition = new NamedParameterStatement(query, dataSource); } query = properties.getProperty("database.updateLatestPosition"); if (query != null) { queryUpdateLatestPosition = new NamedParameterStatement(query, dataSource); } }
From source file:ubicrypt.core.provider.s3.S3Provider.java
License:Open Source License
@Override public Observable<ProviderStatus> init(long userId) { return Observable.<ProviderStatus>create(subscriber -> { if (conf == null) { subscriber.onError(new RuntimeException("conf not specified")); return; }/*from ww w . j a va2 s . c o m*/ try { AmazonS3ClientBuilder clientb = AmazonS3ClientBuilder.standard() .withCredentials(new AWSCredentialsProvider() { @Override public AWSCredentials getCredentials() { return new AWSCredentials() { @Override public String getAWSAccessKeyId() { return conf.getAccessKeyId(); } @Override public String getAWSSecretKey() { return conf.getSecrectKey(); } }; } @Override public void refresh() { } }); if (conf.getRegion() != null) { clientb.withRegion(conf.getRegion()); } client = clientb.build(); prefix = Long.toString(userId, MAX_RADIX) + "/"; try { client.headBucket(new HeadBucketRequest(conf.getBucket())); } catch (AmazonS3Exception e) { switch (e.getErrorCode()) { case "404 Not Found": client.createBucket(conf.getBucket()); break; default: subscriber.onError(e); return; } } maxKey.set(client.listObjects(conf.getBucket(), prefix).getObjectSummaries().stream().map(obj -> { try { return Long.valueOf(substringAfter(obj.getKey(), prefix), MAX_RADIX); } catch (Exception e) { return 0L; } }).max(Long::compareTo).orElse(0L)); initialized.set(true); subscriber.onNext(ProviderStatus.initialized); subscriber.onCompleted(); } catch (Exception e) { subscriber.onError(e); } }).subscribeOn(Schedulers.io()); }