Skip to content

Patch to support SSL-enabled client-to-node connections #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ <T> T execute(Action<T> action) {
throw new IllegalArgumentException("Password must be provided with username.");
}
}
if (keyspace.getCluster().isSSL())
builder.withSSL();
cluster = builder.build();

Metadata metadata = cluster.getMetadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public enum ClusterProperty {
CONTACTPOINTS(PROPERTY_PREFIX + "contactpoints", "Comma separated values of node IP addresses"),
PORT(PROPERTY_PREFIX + "port", "CQL native transport port"),
USERNAME(PROPERTY_PREFIX + "username", "Username for password authenticator"),
PASSWORD(PROPERTY_PREFIX + "password", "Password for password authenticator");
PASSWORD(PROPERTY_PREFIX + "password", "Password for password authenticator"),
SSL(PROPERTY_PREFIX + "ssl", "Cluster requires SSL connection (true/false)");

private String name;
private String description;
Expand All @@ -30,6 +31,7 @@ public String getDescription() {
private int port = 9042;
private String username;
private String password;
private boolean ssl;

public Cluster() {
String contactpointsP = System.getProperty(ClusterProperty.CONTACTPOINTS.getName());
Expand All @@ -47,6 +49,8 @@ public Cluster() {
String passwordP = System.getProperty(ClusterProperty.PASSWORD.getName());
if (null != passwordP && passwordP.trim().length() != 0)
this.password = passwordP;

this.ssl = Boolean.getBoolean(ClusterProperty.SSL.getName());
}

public String[] getContactpoints() {
Expand Down Expand Up @@ -80,4 +84,12 @@ public String getPassword() {
public void setPassword(String password) {
this.password = password;
}

public boolean isSSL() {
return ssl;
}

public void setSSL(boolean ssl) {
this.ssl = ssl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class BaseIT {
public static final int CASSANDRA_PORT = 9147;
public static final String CASSANDRA_USERNAME = "cassandra";
public static final String CASSANDRA_PASSWORD = "cassandra";
public static final boolean CASSANDRA_SSL = false;

private Session session;

Expand Down Expand Up @@ -57,6 +58,7 @@ protected Keyspace getKeyspace() {
ks.getCluster().setPort(CASSANDRA_PORT);
ks.getCluster().setUsername(CASSANDRA_USERNAME);
ks.getCluster().setPassword(CASSANDRA_PASSWORD);
ks.getCluster().setSSL(CASSANDRA_SSL);
return ks;
}

Expand All @@ -67,6 +69,8 @@ private Session getSession(Keyspace keyspace) {
com.datastax.driver.core.Cluster.Builder builder = new com.datastax.driver.core.Cluster.Builder();
builder.addContactPoints(CASSANDRA_CONTACT_POINT).withPort(CASSANDRA_PORT);
builder.withCredentials(keyspace.getCluster().getUsername(), keyspace.getCluster().getPassword());
if (keyspace.getCluster().isSSL())
builder.withSSL();
Cluster cluster = builder.build();
session = cluster.connect();
return session;
Expand Down