ATLAS-3422: Cassandra audit repository updated to support authenticated Cassandra cluster
Signed-off-by: Madhan Neethiraj <madhan@apache.org>
diff --git a/distro/src/conf/atlas-application.properties b/distro/src/conf/atlas-application.properties
index e06e74a..e96f58a 100755
--- a/distro/src/conf/atlas-application.properties
+++ b/distro/src/conf/atlas-application.properties
@@ -35,6 +35,8 @@
# See the configuration documentation for more information about configuring the various storage backends.
#
atlas.graph.storage.backend=${graph.storage.backend}
+atlas.graph.storage.username=
+atlas.graph.storage.password=
atlas.graph.storage.hbase.table=apache_atlas_janus
${graph.storage.properties}
diff --git a/repository/src/main/java/org/apache/atlas/repository/audit/CassandraBasedAuditRepository.java b/repository/src/main/java/org/apache/atlas/repository/audit/CassandraBasedAuditRepository.java
index 4037ac2..1f9174e 100644
--- a/repository/src/main/java/org/apache/atlas/repository/audit/CassandraBasedAuditRepository.java
+++ b/repository/src/main/java/org/apache/atlas/repository/audit/CassandraBasedAuditRepository.java
@@ -69,6 +69,8 @@
public static final String CASSANDRA_PORT_PROPERTY = "atlas.graph.storage.port";
public static final String CASSANDRA_REPLICATION_FACTOR_PROPERTY = "atlas.EntityAuditRepository.replicationFactor";
public static final String CASSANDRA_AUDIT_KEYSPACE_PROPERTY = "atlas.EntityAuditRepository.keyspace";
+ public static final String CASSANDRA_USERNAME_PROPERTY = "atlas.graph.storage.username";
+ public static final String CASSANDRA_PASSWORD_PROPERTY = "atlas.graph.storage.password";
private static final String AUDIT_TABLE_SCHEMA =
"CREATE TABLE audit(entityid text, "
@@ -97,6 +99,8 @@
private Session cassSession;
private String clusterName;
private int port;
+ private String username;
+ private String password;
private Map<String, List<String>> auditExcludedAttributesCache = new HashMap<>();
private PreparedStatement insertStatement;
@@ -211,6 +215,8 @@
replicationFactor = APPLICATION_PROPERTIES.getInt(CASSANDRA_REPLICATION_FACTOR_PROPERTY, DEFAULT_REPLICATION_FACTOR);
clusterName = APPLICATION_PROPERTIES.getString(CASSANDRA_CLUSTERNAME_PROPERTY, DEFAULT_CLUSTER_NAME);
port = APPLICATION_PROPERTIES.getInt(CASSANDRA_PORT_PROPERTY, DEFAULT_PORT);
+ username = APPLICATION_PROPERTIES.getString(CASSANDRA_USERNAME_PROPERTY, "");
+ password = APPLICATION_PROPERTIES.getString(CASSANDRA_PASSWORD_PROPERTY, "");
}
@VisibleForTesting
@@ -222,7 +228,7 @@
Cluster.Builder cassandraClusterBuilder = Cluster.builder();
String hostname = APPLICATION_PROPERTIES.getString(CASSANDRA_HOSTNAME_PROPERTY, "localhost");
- Cluster cluster = cassandraClusterBuilder.addContactPoint(hostname).withClusterName(clusterName).withPort(port).build();
+ Cluster cluster = cassandraClusterBuilder.addContactPoint(hostname).withClusterName(clusterName).withPort(port).withCredentials(username.trim(), password.trim()).build();
try {
cassSession = cluster.connect();
if (cluster.getMetadata().getKeyspace(keyspace) == null) {
diff --git a/repository/src/test/java/org/apache/atlas/repository/audit/CassandraAuditRepositoryTest.java b/repository/src/test/java/org/apache/atlas/repository/audit/CassandraAuditRepositoryTest.java
index 26d3a60..6d28ada 100644
--- a/repository/src/test/java/org/apache/atlas/repository/audit/CassandraAuditRepositoryTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/audit/CassandraAuditRepositoryTest.java
@@ -38,6 +38,8 @@
private final String CLUSTER_HOST = "localhost";
private final String CLUSTER_NAME_TEST = "Test Cluster";
private final int CLUSTER_PORT = 9042;
+ private final String CLUSTER_USERNAME = "";
+ private final String CLUSTER_PASSWORD = "";
@BeforeClass
public void setup() {
@@ -61,6 +63,8 @@
props.put(CassandraBasedAuditRepository.CASSANDRA_CLUSTERNAME_PROPERTY, CLUSTER_NAME_TEST);
props.put(CassandraBasedAuditRepository.CASSANDRA_HOSTNAME_PROPERTY, CLUSTER_HOST);
props.put(CassandraBasedAuditRepository.CASSANDRA_PORT_PROPERTY, CLUSTER_PORT);
+ props.put(CassandraBasedAuditRepository.CASSANDRA_USERNAME_PROPERTY, CLUSTER_USERNAME);
+ props.put(CassandraBasedAuditRepository.CASSANDRA_PASSWORD_PROPERTY, CLUSTER_PASSWORD);
return props;
}
@@ -69,6 +73,7 @@
Cluster.Builder cassandraClusterBuilder = Cluster.builder();
Cluster cluster =
cassandraClusterBuilder.addContactPoint(CLUSTER_HOST).withClusterName(CLUSTER_NAME_TEST).withPort(CLUSTER_PORT)
+ .withCredentials(CLUSTER_USERNAME.trim(), CLUSTER_PASSWORD.trim())
.build();
int retryCount = 0;