gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject git commit: Fix for GORA-376: Gora Cassandra doesn't accept user credentials for connection
Date Thu, 25 Sep 2014 03:11:07 GMT
Repository: gora
Updated Branches:
  refs/heads/master a5f048277 -> d48708eca


Fix for GORA-376: Gora Cassandra doesn't accept user credentials for connection

Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/d48708ec
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/d48708ec
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/d48708ec

Branch: refs/heads/master
Commit: d48708eca5035fb576983e99e13f89045c1006b6
Parents: a5f0482
Author: vijuk <vijuk@users.noreply.github.com>
Authored: Wed Sep 24 18:15:20 2014 -0700
Committer: vijuk <vijuk@users.noreply.github.com>
Committed: Wed Sep 24 18:15:20 2014 -0700

----------------------------------------------------------------------
 .../gora/cassandra/store/CassandraClient.java   | 27 ++++++++++++++++++--
 .../gora/cassandra/store/CassandraStore.java    |  2 +-
 2 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/gora/blob/d48708ec/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraClient.java
----------------------------------------------------------------------
diff --git a/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraClient.java
b/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraClient.java
index 9e8cd7b..cb54ed1 100644
--- a/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraClient.java
+++ b/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraClient.java
@@ -94,6 +94,14 @@ public class CassandraClient<K, T extends PersistentBase> {
   private Serializer<K> keySerializer;
   
   /**
+   * Method to maintain backward compatibility with earlier versions. 
+  */
+  public void initialize(Class<K> keyClass, Class<T> persistentClass)
+    throws Exception {
+	initialize(keyClass, persistentClass, null);
+  }
+  
+  /**
    * Given our key, persistentClass from 
    * {@link org.apache.gora.cassandra.store.CassandraStore#initialize(Class, Class, Properties)}
    * we make best efforts to dictate our data model. 
@@ -105,17 +113,32 @@ public class CassandraClient<K, T extends PersistentBase> {
    * defining a mutator from and by which we can mutate this object.
    * @param keyClass the Key by which we wish o assign a record object
    * @param persistentClass the generated {@link org.apache.org.gora.persistency.Peristent}
bean representing the data.
+   * @param properties key value pairs from gora.properties
    * @throws Exception
    */
-  public void initialize(Class<K> keyClass, Class<T> persistentClass) throws
Exception {
+  public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties
properties) throws Exception {
     this.keyClass = keyClass;
 
     // get cassandra mapping with persistent class
     this.persistentClass = persistentClass;
     this.cassandraMapping = CassandraMappingManager.getManager().get(persistentClass);
+	Map<String, String> accessMap = null;
+	if (properties != null) {
+		String username = properties
+				.getProperty("gora.cassandrastore.username");
+		if (username != null) {
+			accessMap = new HashMap<String, String>();
+			accessMap.put("username", username);
+			String password = properties
+					.getProperty("gora.cassandrastore.password");
+			if (password != null) {
+				accessMap.put("password", password);
+			}
+		}
+	}
 
     this.cluster = HFactory.getOrCreateCluster(this.cassandraMapping.getClusterName(), 
-        new CassandraHostConfigurator(this.cassandraMapping.getHostName()));
+        new CassandraHostConfigurator(this.cassandraMapping.getHostName()), accessMap);
     
     // add keyspace to cluster
     checkKeyspace();

http://git-wip-us.apache.org/repos/asf/gora/blob/d48708ec/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
----------------------------------------------------------------------
diff --git a/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
b/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
index 496f1f0..660391e 100644
--- a/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
+++ b/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
@@ -149,7 +149,7 @@ public class CassandraStore<K, T extends PersistentBase> extends
DataStoreBase<K
         readOpConsLvl = DataStoreFactory.findProperty(properties, this, READ_OP_CL, null);
         writeOpConsLvl = DataStoreFactory.findProperty(properties, this, WRITE_OP_CL, null);
       }
-      this.cassandraClient.initialize(keyClass, persistent);
+      this.cassandraClient.initialize(keyClass, persistent, properties);
     } catch (Exception e) {
       LOG.error(e.getMessage());
       LOG.error(e.getStackTrace().toString());


Mime
View raw message