Author: tyrell
Date: Fri May 16 02:06:32 2008
New Revision: 17110
Log:
Adding trusted certificate uploading capability to user keystores. Users can
now upload their trusted certificates to be stored in their personal keystore.
These certificates will be used during mashup sharing.
Modified:
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
trunk/mashup/java/modules/www/cert_manager.jsp
trunk/mashup/java/modules/www/taskbar.jsp
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 02:06:32 2008
@@ -26,6 +26,7 @@
import org.wso2.javascript.rhino.JavaScriptEngineConstants;
import org.wso2.mashup.MashupConstants;
import org.wso2.mashup.MashupFault;
+import org.wso2.mashup.utils.MashupUtils;
import org.wso2.registry.RegistryConstants;
import org.wso2.registry.RegistryException;
import org.wso2.registry.Resource;
@@ -43,14 +44,23 @@
import org.wso2.wsas.persistence.dataobject.ServiceIdentifierDO;
import org.wso2.wsas.persistence.exception.ServiceNotFoundException;
+import javax.activation.DataHandler;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.List;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.CertificateException;
public class MashupAdminService {
@@ -497,7 +507,8 @@
ServerManager serverManager = ServerManager.getInstance();
ConfigurationContext configContext = serverManager.configContext;
-
configContext.getAxisConfiguration().getService(serviceName).addExposedTransport(transportName);
+ configContext.getAxisConfiguration().getService(serviceName)
+ .addExposedTransport(transportName);
success = true;
return Boolean.valueOf(success);
@@ -510,11 +521,56 @@
ServerManager serverManager = ServerManager.getInstance();
ConfigurationContext configContext = serverManager.configContext;
-
configContext.getAxisConfiguration().getService(serviceName).removeExposedTransport(transportName);
+ configContext.getAxisConfiguration().getService(serviceName)
+ .removeExposedTransport(transportName);
success = true;
return Boolean.valueOf(success);
}
-
+ public String importCert(String userName, String alias, DataHandler cert)
throws MashupFault {
+ try {
+ InputStream certIn = cert.getDataSource().getInputStream();
+
+ 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);
+
+ // Check to prevent alias conflicts
+ int seq = 0;
+ while (userKeyStore.containsAlias(alias)) {
+ seq++;
+ alias = alias + "." + seq;
+ }
+
+ userKeyStore.setCertificateEntry(alias,
+
CertificateFactory.getInstance("X.509").
+
generateCertificate(certIn));
+ 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.");
+ }
+
+ } 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);
+ }
+
+ return null;
+ }
}
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
(original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
Fri May 16 02:06:32 2008
@@ -98,7 +98,9 @@
import java.security.NoSuchAlgorithmException;
import java.security.KeyStore;
import java.security.PrivateKey;
+import java.security.KeyStoreException;
import java.security.cert.X509Certificate;
+import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
@@ -1053,6 +1055,32 @@
return scripts;
}
+ public static KeyStore getUserKeyStore(String userName) {
+
+ // Getting this users keystore from registry
+ Resource ksResource = getUserKeystoreResource(userName);
+
+ try {
+ KeyStore keyStore = KeyStore.getInstance("JKS");
+ char[] keyPassphrase =
+
ksResource.getProperty(MashupConstants.USER_KEYSTORE_PASSWORD).toCharArray();
+ keyStore.load(new ByteArrayInputStream((byte[])
ksResource.getContent()),
+ keyPassphrase);
+ return keyStore;
+ } catch (KeyStoreException e) {
+ log.error(e);
+ } catch (IOException e) {
+ log.error(e);
+ } catch (NoSuchAlgorithmException e) {
+ log.error(e);
+ } catch (CertificateException e) {
+ log.error(e);
+ } catch (RegistryException e) {
+ log.error(e);
+ }
+
+ return null;
+ }
public static Resource getUserKeystoreResource(String userName) {
ServerManager serverManager = ServerManager.getInstance();
@@ -1074,8 +1102,34 @@
}
+ public static boolean putUserKeystoreResource(String userName, byte[]
keyStoreContent) {
+
+ ServerManager serverManager = ServerManager.getInstance();
+ ConfigurationContext configContext = serverManager.configContext;
+ EmbeddedRegistry embeddedRegistry =
+ (EmbeddedRegistry)
configContext.getAxisConfiguration().getParameterValue(
+ RegistryConstants.REGISTRY);
+
+ try {
+ UserRegistry systemRegistry = embeddedRegistry.getSystemRegistry();
+ String path = MashupConstants.USERS_PATH + "/" + userName +
MashupConstants
+ .USER_KEYSTORE_PATH;
+
+ // Updating the existing keystore with new content
+ Resource userKeyStoreResource = getUserKeystoreResource(userName);
+ userKeyStoreResource.setContent(keyStoreContent);
+ systemRegistry.put(path, userKeyStoreResource);
+
+ return true;
+ } catch (RegistryException e) {
+ log.error(e);
+ }
+
+ return false;
+ }
+
+
/**
- *
* Gets all certificates from a user's keystore
*
* @param userName The name of the user
@@ -1086,13 +1140,7 @@
Format formatter = new SimpleDateFormat("dd/MM/yyyy");
// Getting this users keystore from registry
- Resource ksResource = getUserKeystoreResource(userName);
-
- KeyStore keyStore = KeyStore.getInstance("JKS");
- char[] keyPassphrase =
-
ksResource.getProperty(MashupConstants.USER_KEYSTORE_PASSWORD).toCharArray();
- keyStore.load(new ByteArrayInputStream((byte[])
ksResource.getContent()),
- keyPassphrase);
+ KeyStore keyStore = getUserKeyStore(userName);
Enumeration aliases = keyStore.aliases();
List certDataList = new ArrayList();
@@ -1131,7 +1179,6 @@
/**
- *
* Retrieves a File's content as a byte array
*
* @param file A File object
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 02:06:32 2008
@@ -36,6 +36,78 @@
<!-- Required Javascript -->
<script language="javascript" src="js/common.js"
type="text/javascript"></script>
+ <script language="javascript" src="js/mashup-main.js"
type="text/javascript"></script>
+ <script language="javascript" src="js/mashup-utils.js"
type="text/javascript"></script>
+ <script language="javascript"
src="js/yui/yahoo-dom-event/yahoo-dom-event.js"
+ type="text/javascript"></script>
+ <script language="javascript" src="js/yui/connection/connection.js"
+ type="text/javascript"></script>
+ <script language="javascript" src="js/wso2/WSRequest.js"
+ type="text/javascript"></script>
+
+ <script type="text/javascript" language="JavaScript">
+
+ var callback =
+ {
+ success:handleSuccess,
+ failure:handleFailure,
+ upload:handleSuccess
+ };
+
+ function handleSuccess(o) {
+ clearText();
+ location.reload();
+ }
+
+ function handleFailure(o) {
+ alert("Failed to add the certificate. [" + o.responseText + "]");
+ }
+
+ function submitFormAsync(formId, isFileUpload) {
+ var form = document.getElementById(formId);
+
+ if ((isFileUpload) && (document.getElementById("cert").value ==
"")) {
+ WSO2.MashupUtils.dialog("Insufficient data", "<pre>Please
browse your file system for a valid certificate.</pre><br><input type='button'
value='Close' onclick='WSO2.MashupUtils.dialog.close();'", 70, 70);
+ } else if ((!isFileUpload) &&
(document.getElementById("alias").value == "")) {
+ WSO2.MashupUtils.dialog("Insufficient data", "<pre>Please type
an alias for the certificate.</pre><br><input type='button' value='Close'
onclick='WSO2.MashupUtils.dialog.close();'", 70, 70);
+ } else {
+ if (isFileUpload) {
+ YAHOO.util.Connect.setForm(form, true, true);
+ YAHOO.util.Connect.asyncRequest("POST",
form.getAttribute("action"), callback, null);
+ } else {
+ YAHOO.util.Connect.setForm(form);
+ YAHOO.util.Connect.asyncRequest("POST",
form.getAttribute("action"), callback, null);
+ }
+ }
+ }
+
+ function noEnter(e) {
+ var keynum = "";
+ if (window.event) // IE
+ {
+ keynum = e.keyCode;
+
+ if (keynum == 13) {
+ e.cancelBubble = true;
+ e.returnValue = false;
+ }
+ }
+ else if (e.which) // Netscape/Firefox/Opera
+ {
+ keynum = e.which;
+ if (keynum == 13) {
+ e.preventDefault();
+ }
+ }
+
+ }
+
+ function clearText() {
+ document.getElementById("cert").value = "";
+ document.getElementById("alias").value = "";
+ }
+
+ </script>
</head>
<body>
<div id="page">
@@ -53,13 +125,27 @@
%>
<fieldset>
<legend>Add a new certificate</legend>
- <div><label>Certificate<font color="red">*</font></label><input
- type="file" size="50" id="certificateFile"
name="certificateFile"/>
+ <br/>
- <input type="submit" value="Upload" align="right"
- onclick="return
validateimportCertificate();"/>
- </div>
+ <form id="form" method="post" enctype="multipart/form-data"
+ action="/services/MashupAdminService/importCert"
+ target="uploadFrame">
+ <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;"/>
+ <br/>
+ <br/>
+ <label>Alias<font color="red">*</font></label><input
type="text" id="alias"
+
name="alias"
+
style="margin-left: 32px;"/>
+ <br/>
+ <br/>
+ <input type="button" value="Upload" align="right"
+ onclick="return submitFormAsync('form',true);"/>
+ </form>
</fieldset>
+ <br/>
<fieldset>
<legend>You are currently trusting the following
certificates</legend>
<table id="certificates">
Modified: trunk/mashup/java/modules/www/taskbar.jsp
==============================================================================
--- trunk/mashup/java/modules/www/taskbar.jsp (original)
+++ trunk/mashup/java/modules/www/taskbar.jsp Fri May 16 02:06:32 2008
@@ -189,6 +189,12 @@
<li>
<a href="stub_gen.jsp" target="_blank">Use the Java Script Stub
Generator</a>
</li>
+
+<li>
+ <a href="cert_manager.jsp" target="_blank">Manage my trusted
certificates</a>
+</li>
+
+
<!--<li>
<a href="#">Use the data service assistant</a>
</li>-->
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev