Skip to content
Permalink
Browse files
Merge pull request #1 from mgeiss/develop
added authentication provider
  • Loading branch information
mgeiss committed Apr 20, 2017
2 parents 29e99b2 + eaac3df commit fc4d246993846927d00d64346693ae8cc8218b45
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
@@ -15,7 +15,9 @@
*/
package io.mifos.core.cassandra.core;

import com.datastax.driver.core.AuthProvider;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.PlainTextAuthProvider;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.exceptions.InvalidQueryException;
import com.datastax.driver.mapping.Mapper;
@@ -154,8 +156,16 @@ public Session getSession(@Nonnull final String clusterName,
private Cluster getCluster(@Nonnull final String clusterName, @Nonnull final String contactPoints) {
CodecRegistry.register(new LocalDateTimeCodec());

final Cluster.Builder clusterBuilder = Cluster.builder()
.withClusterName(clusterName);
final Cluster.Builder clusterBuilder = Cluster.builder().withClusterName(clusterName);

if (this.env.containsProperty(CassandraConnectorConstants.CLUSTER_USER_PROP)) {
final String user = this.env.getProperty(CassandraConnectorConstants.CLUSTER_USER_PROP);
final String pwd = this.env.getProperty(CassandraConnectorConstants.CLUSTER_PASSWORD_PROP);

final AuthProvider authProvider = new PlainTextAuthProvider(user, pwd);
clusterBuilder.withAuthProvider(authProvider);
}

ContactPointUtils.process(clusterBuilder, contactPoints);
return clusterBuilder.build();
}
@@ -22,6 +22,9 @@ public interface CassandraConnectorConstants {
String CLUSTER_NAME_PROP = "cassandra.clusterName";
String CLUSTER_NAME_PROP_DEFAULT = "staging_cluster";

String CLUSTER_USER_PROP = "cassandra.cluster.user";
String CLUSTER_PASSWORD_PROP = "cassandra.cluster.pwd";

String CONTACT_POINTS_PROP = "cassandra.contactPoints";
String CONTACT_POINTS_PROP_DEFAULT = "127.0.0.1:9042,127.0.0.2:9042,127.0.0.3:9042";

0 comments on commit fc4d246

Please sign in to comment.