You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ki...@apache.org on 2012/07/04 02:30:43 UTC

[1/2] git commit: Encrypting password values that are stored in the cluster_details table

Updated Branches:
  refs/heads/master 57927c9f2 -> 023c2e4f5


Encrypting password values that are stored in the cluster_details table


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/023c2e4f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/023c2e4f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/023c2e4f

Branch: refs/heads/master
Commit: 023c2e4f59942dbb8d0270334fb777d3804dab1e
Parents: b957933
Author: Vijayendra Bhamidipati <vi...@citrix.com>
Authored: Tue Jul 3 17:27:21 2012 -0700
Committer: kishan <ki...@cloud.com>
Committed: Tue Jul 3 17:27:21 2012 -0700

----------------------------------------------------------------------
 server/src/com/cloud/dc/ClusterDetailsDaoImpl.java |   41 ++++++++++-----
 1 files changed, 27 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/023c2e4f/server/src/com/cloud/dc/ClusterDetailsDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/dc/ClusterDetailsDaoImpl.java b/server/src/com/cloud/dc/ClusterDetailsDaoImpl.java
index e488695..4ee63c4 100755
--- a/server/src/com/cloud/dc/ClusterDetailsDaoImpl.java
+++ b/server/src/com/cloud/dc/ClusterDetailsDaoImpl.java
@@ -22,6 +22,7 @@ import java.util.Map;
 
 import javax.ejb.Local;
 
+import com.cloud.utils.crypt.DBEncryptionUtil;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
@@ -31,12 +32,12 @@ import com.cloud.utils.db.Transaction;
 public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long> implements ClusterDetailsDao {
     protected final SearchBuilder<ClusterDetailsVO> ClusterSearch;
     protected final SearchBuilder<ClusterDetailsVO> DetailSearch;
-    
+
     protected ClusterDetailsDaoImpl() {
         ClusterSearch = createSearchBuilder();
         ClusterSearch.and("clusterId", ClusterSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
         ClusterSearch.done();
-        
+
         DetailSearch = createSearchBuilder();
         DetailSearch.and("clusterId", DetailSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
         DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
@@ -48,32 +49,40 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long
         SearchCriteria<ClusterDetailsVO> sc = DetailSearch.create();
         sc.setParameters("clusterId", clusterId);
         sc.setParameters("name", name);
-        
-        return findOneIncludingRemovedBy(sc);
+
+        ClusterDetailsVO detail = findOneIncludingRemovedBy(sc);
+        if("password".equals(name) && detail != null){
+            detail.setValue(DBEncryptionUtil.decrypt(detail.getValue()));
+        }
+        return detail;
     }
-    
+
 
     @Override
     public Map<String, String> findDetails(long clusterId) {
         SearchCriteria<ClusterDetailsVO> sc = ClusterSearch.create();
         sc.setParameters("clusterId", clusterId);
-        
+
         List<ClusterDetailsVO> results = search(sc, null);
         Map<String, String> details = new HashMap<String, String>(results.size());
         for (ClusterDetailsVO result : results) {
-            details.put(result.getName(), result.getValue());
+            if("password".equals(result.getName())){
+                details.put(result.getName(), DBEncryptionUtil.decrypt(result.getValue()));
+            } else {
+                details.put(result.getName(), result.getValue());
+            }
         }
         return details;
     }
-    
+
     @Override
     public void deleteDetails(long clusterId) {
         SearchCriteria sc = ClusterSearch.create();
         sc.setParameters("clusterId", clusterId);
-        
+
         List<ClusterDetailsVO> results = search(sc, null);
         for (ClusterDetailsVO result : results) {
-        	remove(result.getId());
+            remove(result.getId());
         }
     }
 
@@ -84,9 +93,13 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long
         SearchCriteria<ClusterDetailsVO> sc = ClusterSearch.create();
         sc.setParameters("clusterId", clusterId);
         expunge(sc);
-        
+
         for (Map.Entry<String, String> detail : details.entrySet()) {
-            ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, detail.getKey(), detail.getValue());
+            String value = detail.getValue();
+            if("password".equals(detail.getKey())){
+                value = DBEncryptionUtil.encrypt(value);
+            }
+            ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, detail.getKey(), value);
             persist(vo);
         }
         txn.commit();
@@ -100,10 +113,10 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long
         sc.setParameters("clusterId", clusterId);
         sc.setParameters("name", name);
         expunge(sc);
-        
+
         ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, name, value);
         persist(vo);
         txn.commit();
     }
-    
+
 }