Author: tyrell
Date: Fri May 16 06:07:37 2008
New Revision: 17126

Log:
Adding trusted certificate deletion.

Modified:
   
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
   trunk/mashup/java/modules/www/cert_manager.jsp
   trunk/mashup/java/modules/www/js/services.js

Modified: 
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
==============================================================================
--- 
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
   (original)
+++ 
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
   Fri May 16 06:07:37 2008
@@ -528,7 +528,7 @@
         return Boolean.valueOf(success);
     }
 
-    public String importCert(String userName, String alias, DataHandler cert) 
throws MashupFault {
+    public Boolean importCert(String userName, String alias, DataHandler cert) 
throws MashupFault {
         try {
             InputStream certIn = cert.getDataSource().getInputStream();
 
@@ -556,7 +556,10 @@
 
             // Updating the keystore in registry
             if (!MashupUtils.putUserKeystoreResource(userName, 
newKeyStoreContent.toByteArray())) {
-                throw new MashupFault("An error occured while adding the new 
certificate. Please refer the log for details.");
+                throw new MashupFault(
+                        "An error occured while adding the new certificate. 
Please refer the log for details.");
+            } else {
+                return Boolean.valueOf(true);
             }
 
         } catch (IOException e) {
@@ -571,6 +574,45 @@
             throw new MashupFault(e);
         }
 
-        return null;
+    }
+
+
+    public Boolean deleteCert(String userName, String alias) throws 
MashupFault {
+        try {
+
+            Resource useKeyStoreResource = 
MashupUtils.getUserKeystoreResource(userName);
+
+            KeyStore userKeyStore = KeyStore.getInstance("JKS");
+            char[] keyPassphrase =
+                    
useKeyStoreResource.getProperty(MashupConstants.USER_KEYSTORE_PASSWORD)
+                            .toCharArray();
+            userKeyStore.load(new ByteArrayInputStream((byte[]) 
useKeyStoreResource.getContent()),
+                              keyPassphrase);
+
+            // deleting the certificate entry from keystore
+            userKeyStore.deleteEntry(alias);
+
+            ByteArrayOutputStream newKeyStoreContent = new 
ByteArrayOutputStream();
+            userKeyStore.store(newKeyStoreContent, keyPassphrase);
+
+            // Updating the keystore in registry
+            if (!MashupUtils.putUserKeystoreResource(userName, 
newKeyStoreContent.toByteArray())) {
+                throw new MashupFault(
+                        "An error occured while adding the new certificate. 
Please refer the log for details.");
+            } else {
+                return Boolean.valueOf(true);
+            }
+
+        } catch (IOException e) {
+            throw new MashupFault(e);
+        } catch (KeyStoreException e) {
+            throw new MashupFault(e);
+        } catch (CertificateException e) {
+            throw new MashupFault(e);
+        } catch (RegistryException e) {
+            throw new MashupFault(e);
+        } catch (NoSuchAlgorithmException e) {
+            throw new MashupFault(e);
+        }
     }
 }

Modified: trunk/mashup/java/modules/www/cert_manager.jsp
==============================================================================
--- trunk/mashup/java/modules/www/cert_manager.jsp      (original)
+++ trunk/mashup/java/modules/www/cert_manager.jsp      Fri May 16 06:07:37 2008
@@ -44,8 +44,13 @@
             type="text/javascript"></script>
     <script language="javascript" src="js/wso2/WSRequest.js"
             type="text/javascript"></script>
+    <script type="text/javascript" 
src="../wsasadmin/global_params.js"></script>
+    <script type="text/javascript" src="../wsasadmin/js/main.js"></script>
+    <script language="javascript" src="js/services.js"
+            type="text/javascript"></script>
 
     <script type="text/javascript" language="JavaScript">
+        var currentUser = '<%=currentUser.trim()%>';
 
         var callback =
         {
@@ -63,7 +68,7 @@
             alert("Failed to add the certificate. [" + o.responseText + "]");
         }
 
-        function submitFormAsync(formId, isFileUpload) {            
+        function submitFormAsync(formId, isFileUpload) {
             var form = document.getElementById(formId);
 
             if ((isFileUpload) && (document.getElementById("cert").value == 
"")) {
@@ -107,6 +112,20 @@
             document.getElementById("alias").value = "";
         }
 
+        function deleteCertCallback() {
+            location.reload();
+        }
+
+        function deleteCert(certAlias) {
+            var response = confirm("You are about to delete the certificate 
with alias '" +
+                                   certAlias +
+                                   "'. This might prevent your 
services/mashups from connecting to the site bearing this certificate. Are you 
sure?");
+            if (response) {
+                // Calling the cert deletion service
+                wso2.mashup.services.deleteCertificate(currentUser, certAlias, 
deleteCertCallback)
+            }
+        }
+
     </script>
 </head>
 <body>
@@ -123,6 +142,8 @@
         <%
         } else {
         %>
+        <h3>Trusted Site Certificates of <%=RegistryUtils.getFullName(request, 
currentUser)%>
+        </h3>
         <fieldset>
             <legend>Add a new certificate</legend>
             <br/>
@@ -133,12 +154,13 @@
                 <input type="hidden" id="userName" name="userName" 
value="<%=currentUser%>"/>
                 <label>Certificate<font color="red">*</font></label><input
                     type="file" size="50" id="cert" name="cert"
-                    style="margin-left: 5px;"/>
+                    style="margin-left: 5px;" onkeydown="noEnter(event);"/>
                 <br/>
                 <br/>
                 <label>Alias<font color="red">*</font></label><input 
type="text" id="alias"
                                                                      
name="alias"
-                                                                     
style="margin-left: 32px;"/>
+                                                                     
style="margin-left: 32px;"
+                                                                     
onkeydown="noEnter(event);"/>
                 <br/>
                 <br/>
                 <input type="button" value="Upload" align="right"
@@ -151,13 +173,14 @@
             <table id="certificates">
                 <thead>
                     <tr class="mashup_label">
-                        <th>Alias</th>
-                        <th>IssuerDN</th>
-                        <th>NotAfter</th>
-                        <th>NotBefore</th>
-                        <th>SerialNumber</th>
-                        <th>SubjectDN</th>
-                        <th>Version</th>
+                        <th style="text-align: center;">Alias</th>
+                        <th style="text-align: center;">Issued by</th>
+                        <th style="text-align: center;">Issued to</th>
+                        <th style="text-align: center;">Valid from</th>
+                        <th style="text-align: center;">Valid till</th>
+                        <th style="text-align: center;">Serial Number</th>
+                        <th style="text-align: center;">Version</th>
+                        <th style="text-align: center;">Tasks</th>
                     </tr>
                 </thead>
                 <tbody>
@@ -174,16 +197,22 @@
                         </td>
                         <td><%=certs[x].getIssuerDN()%>
                         </td>
-                        <td><%=certs[x].getNotAfter()%>
+                        <td><%=certs[x].getSubjectDN()%>
                         </td>
                         <td><%=certs[x].getNotBefore()%>
                         </td>
-                        <td><%=certs[x].getSerialNumber()%>
+                        <td><%=certs[x].getNotAfter()%>
                         </td>
-                        <td><%=certs[x].getSubjectDN()%>
+                        <td><%=certs[x].getSerialNumber()%>
                         </td>
                         <td><%=certs[x].getVersion()%>
                         </td>
+                        <td>
+                            <a href="#" 
onclick="deleteCert('<%=certs[x].getAlias()%>');"><img
+                                    border="0" title="Delete this certificater"
+                                    alt="Delete certificate"
+                                    src="images/delete.gif"/></a>
+                        </td>
                     </tr>
                     <%
 

Modified: trunk/mashup/java/modules/www/js/services.js
==============================================================================
--- trunk/mashup/java/modules/www/js/services.js        (original)
+++ trunk/mashup/java/modules/www/js/services.js        Fri May 16 06:07:37 2008
@@ -423,6 +423,23 @@
 };
 
 /**
+ * @description Deletes a trusted certificate from the user keystore
+ * @param {String} userName User name of the keystore owner
+ * @param {String} certAlias Alias used when storing the certificate in the 
keystore
+ * @param {callback} callback User-defined callback function or object
+ */
+wso2.mashup.services.deleteCertificate = function (userName, certAlias, 
callback) {
+    var callURL = serverURL + "/" + "MashupAdminService" + "/" ;
+
+    var body_xml = '<req:deleteCert 
xmlns:req="http://service.admin.mashup.wso2.org/xsd";>\n' +
+                   ' <req:userName>' + userName + '</req:userName>\n' +
+                   ' <req:alias>' + certAlias + '</req:alias>\n' +
+                   ' </req:deleteCert>\n';
+
+    new wso2.wsf.WSRequest(callURL, "deleteCert", body_xml, callback, "", 
wso2.mashup.services.defaultErrHandler);
+};
+
+/**
  * @description Re deploys a JS Service
  * @param {String} serviceName Name of the Service
  * @param {callback} callback User-defined callback function or object

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to