You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ek...@apache.org on 2015/06/08 11:45:25 UTC

[04/50] [abbrv] git commit: updated refs/heads/feature/vpc-ipv6 to 6140db5

framework: don't use raw SQL statements to save certificate in KeystoreDaoImpl

Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
(cherry picked from commit fb88a11f8228a3ff4798333a46c5c72b6b5ad88c)
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>


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

Branch: refs/heads/feature/vpc-ipv6
Commit: ab3b3c7fa1f3887a46b79437b0724116149dd96e
Parents: ca3ac68
Author: Rohit Yadav <ro...@shapeblue.com>
Authored: Fri May 29 18:32:40 2015 +0200
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Fri May 29 18:33:30 2015 +0200

----------------------------------------------------------------------
 .../security/keystore/KeystoreDaoImpl.java      | 63 ++++++++------------
 1 file changed, 25 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ab3b3c7f/framework/security/src/org/apache/cloudstack/framework/security/keystore/KeystoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/framework/security/src/org/apache/cloudstack/framework/security/keystore/KeystoreDaoImpl.java b/framework/security/src/org/apache/cloudstack/framework/security/keystore/KeystoreDaoImpl.java
index 8a8754d..0ec3c72 100644
--- a/framework/security/src/org/apache/cloudstack/framework/security/keystore/KeystoreDaoImpl.java
+++ b/framework/security/src/org/apache/cloudstack/framework/security/keystore/KeystoreDaoImpl.java
@@ -16,23 +16,17 @@
 // under the License.
 package org.apache.cloudstack.framework.security.keystore;
 
-import java.sql.PreparedStatement;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-import javax.ejb.Local;
-
-import org.springframework.stereotype.Component;
-
-import com.cloud.utils.crypt.DBEncryptionUtil;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.TransactionLegacy;
-import com.cloud.utils.exception.CloudRuntimeException;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
 
 @Component
 @Local(value = {KeystoreDao.class})
@@ -96,26 +90,19 @@ public class KeystoreDaoImpl extends GenericDaoBase<KeystoreVO, Long> implements
     @Override
     @DB
     public void save(String name, String certificate, String key, String domainSuffix) {
-        TransactionLegacy txn = TransactionLegacy.currentTxn();
-        try {
-            txn.start();
-
-            String sql =
-                "INSERT INTO keystore (`name`, `certificate`, `key`, `domain_suffix`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE `certificate`=?, `key`=?, `domain_suffix`=?";
-            PreparedStatement pstmt = txn.prepareAutoCloseStatement(sql);
-            pstmt.setString(1, name);
-            pstmt.setString(2, certificate);
-            pstmt.setString(3, DBEncryptionUtil.encrypt(key));
-            pstmt.setString(4, domainSuffix);
-            pstmt.setString(5, certificate);
-            pstmt.setString(6, DBEncryptionUtil.encrypt(key));
-            pstmt.setString(7, domainSuffix);
-
-            pstmt.executeUpdate();
-            txn.commit();
-        } catch (Exception e) {
-            txn.rollback();
-            throw new CloudRuntimeException("Unable to save certificate under name " + name + " due to exception", e);
+        KeystoreVO keystore = findByName(name);
+        if (keystore != null) {
+            keystore.setCertificate(certificate);
+            keystore.setKey(key);
+            keystore.setDomainSuffix(domainSuffix);
+            this.update(keystore.getId(), keystore);
+        } else {
+            keystore = new KeystoreVO();
+            keystore.setName(name);
+            keystore.setCertificate(certificate);
+            keystore.setKey(key);
+            keystore.setDomainSuffix(domainSuffix);
+            this.persist(keystore);
         }
     }
 
@@ -130,12 +117,12 @@ public class KeystoreDaoImpl extends GenericDaoBase<KeystoreVO, Long> implements
             ks.setDomainSuffix(domainSuffix);
             this.update(ks.getId(), ks);
         } else {
-            KeystoreVO newks = new KeystoreVO();
-            newks.setCertificate(certificate);
-            newks.setName(alias);
-            newks.setIndex(index);
-            newks.setDomainSuffix(domainSuffix);
-            persist(newks);
+            ks = new KeystoreVO();
+            ks.setCertificate(certificate);
+            ks.setName(alias);
+            ks.setIndex(index);
+            ks.setDomainSuffix(domainSuffix);
+            this.persist(ks);
         }
     }
 }