Updated Branches:
  refs/heads/master 4a207b627 -> db67a55e3

Create keystore if there is not exist

Signed-off-by: Manula Thantriwatte <[email protected]>


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

Branch: refs/heads/master
Commit: db67a55e348ccd3474f5098f0fecf9d6846563d1
Parents: 4a207b6
Author: Dinesh Bandara <[email protected]>
Authored: Wed Jan 22 12:20:41 2014 +0530
Committer: Manula Thantriwatte <[email protected]>
Committed: Wed Jan 22 13:31:20 2014 +0530

----------------------------------------------------------------------
 .../stratos/keystore/mgt/KeyStoreGenerator.java  | 19 +++++++++++++++++++
 .../keystore/mgt/KeystoreTenantMgtListener.java  |  4 +++-
 2 files changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/db67a55e/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeyStoreGenerator.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeyStoreGenerator.java
 
b/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeyStoreGenerator.java
index 1946c64..76f5259 100644
--- 
a/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeyStoreGenerator.java
+++ 
b/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeyStoreGenerator.java
@@ -94,6 +94,25 @@ public class KeyStoreGenerator {
     }
 
     /**
+     * This method checks the existance of a keystore
+     *
+     * @return
+     * @throws KeyStoreMgtException
+     */
+    public boolean isKeyStoreExists() throws KeyStoreMgtException {
+        boolean isKeyStoreExists = false;
+        String keyStoreName = generateKSNameFromDomainName();
+        try {
+            isKeyStoreExists = 
govRegistry.resourceExists(RegistryResources.SecurityManagement.KEY_STORES + 
"/" + keyStoreName);
+        } catch (RegistryException e) {
+            String msg = "Error while checking the existance of keystore";
+            log.error(msg, e);
+            throw new KeyStoreMgtException(msg, e);
+        }
+        return isKeyStoreExists;
+    }
+
+    /**
      * This method generates the keypair and stores it in the keystore
      *
      * @param keyStore A keystore instance

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/db67a55e/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeystoreTenantMgtListener.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeystoreTenantMgtListener.java
 
b/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeystoreTenantMgtListener.java
index be91f38..d73215f 100644
--- 
a/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeystoreTenantMgtListener.java
+++ 
b/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeystoreTenantMgtListener.java
@@ -40,7 +40,9 @@ public class KeystoreTenantMgtListener implements 
TenantMgtListener {
     public void onTenantCreate(TenantInfoBean tenantInfo) throws 
StratosException {
         try {
             KeyStoreGenerator ksGenerator = new 
KeyStoreGenerator(tenantInfo.getTenantId());
-            ksGenerator.generateKeyStore();
+            if (!ksGenerator.isKeyStoreExists()){
+                ksGenerator.generateKeyStore();
+            }
         } catch (KeyStoreMgtException e) {
             String message = "Error when generating the keystore";
             log.error(message, e);

Reply via email to