Author: keith
Date: Tue Jan  8 23:46:16 2008
New Revision: 12005

Log:

Fixing sharing so that it works correctly. Now in order to share you need to 
have an account on that machine. (Note that with this change sharing will not 
work on the org site untill we update its 
services.



Modified:
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java
   
trunk/mashup/java/modules/coreservices/servicesharinghelper/src/org/wso2/mashup/coreservices/servicesharinghelper/ServiceSharingHelper.java
   
trunk/mashup/java/modules/coreservices/sharingservice/src/org/wso2/mashup/share/service/MashupSharingService.java
   trunk/mashup/java/modules/www/js/mashup-utils.js
   trunk/mashup/java/modules/www/js/services.js

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java
      (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java
      Tue Jan  8 23:46:16 2008
@@ -35,6 +35,7 @@
 import org.wso2.mashup.MashupFault;
 import org.wso2.utils.ArchiveManipulator;
 import org.wso2.wsas.ServerConstants;
+import org.wso2.usermanager.UserManagerException;
 
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
@@ -128,9 +129,15 @@
      */
     public void uploadMashupService(String destinationServerAddress, 
DataHandler dataHandler,
                                     ConfigurationContext configCtx, String 
serviceJsFileName,
-                                    String mashupServiceName)
+                                    String mashupServiceName, String username, 
String password)
             throws AxisFault {
 
+        if (destinationServerAddress.startsWith("http://";)) {
+            // We should call this service in https mode as we are sending the 
users username
+            // and password as plain text.
+            throw new MashupFault("Cannot share via http as we need to send 
the username and " +
+                    "password as plain text. Please use Https.");
+        }
         // We use the RPCClient to call the sharing service
         RPCServiceClient serviceClient = new RPCServiceClient(configCtx, null);
         Options options = serviceClient.getOptions();
@@ -154,7 +161,7 @@
         // parameters to the service ServiceName string, service file name,
         // dataHandler of the bundled archive
         Object[] opAddEntryArgs =
-                new Object[] { mashupServiceName, serviceJsFileName, 
dataHandler };
+                new Object[] {mashupServiceName, username, 
password,serviceJsFileName, dataHandler};
         try {
             serviceClient.invokeRobust(opAddEntry, opAddEntryArgs);
         } catch (AxisFault axisFault) {
@@ -221,8 +228,8 @@
      * @param axisConfiguration - The corresponding AxisConfiguration
      * @throws AxisFault - Thrown in case an exception occurs
      */
-    public void downloadMashupService(String remoteServer, String serviceName,
-                                      MessageContext messageContext,
+    public void downloadMashupService(String remoteServer, String serviceName, 
String username,
+                                   String password, MessageContext 
messageContext,
                                       AxisConfiguration axisConfiguration) 
throws AxisFault {
         // We use the RPCClient to call the download service
         RPCServiceClient serviceClient = new RPCServiceClient(messageContext
@@ -242,7 +249,6 @@
         options.setTo(remoteSharingServiceEPR);
         options.setAction("urn:getMashup");
         QName opAddEntry = new 
QName("http://service.share.mashup.wso2.org/xsd";, "getMashup");
-
         Object[] opAddEntryArgs = new Object[] { serviceName };
 
         // There is a bug in Axis2 which prevents us from using
@@ -266,7 +272,8 @@
                         String fileName = fileNameElement.getText();
                         System.out.println(fileName + dataHandler);
                         try {
-                            deploySharedService(fileName, dataHandler, 
axisConfiguration);
+                            deploySharedService(fileName, username,  password,
+                                                dataHandler, 
axisConfiguration);
                         } catch (IOException e) {
                             throw new MashupFault(e);
                         }
@@ -290,13 +297,20 @@
      * @param axisConfiguration - Axis Configuration
      * @throws AxisFault - Thrown in case an exception occurs
      */
-    public void deploySharedService(String fileName, DataHandler dataHandler,
-                                    AxisConfiguration axisConfiguration) 
throws AxisFault {
+    public void deploySharedService(String fileName, String username, String 
password,
+                                    DataHandler dataHandler, AxisConfiguration 
axisConfiguration)
+            throws AxisFault {
+
+        try {
+            MashupUtils.authenticateUser(username, password);
+        } catch (UserManagerException e) {
+            throw AxisFault.makeFault(e);
+        }
         URL repository = axisConfiguration.getRepository();
         if (repository != null) {
             // Access the scripts deployment folder
             File repo = new File(repository.getFile());
-            File scriptsFolder = new File(repo, "scripts/shared");
+            File scriptsFolder = new File(repo, "scripts/" + username);
 
             // Checking whether a file with the same name exists
             File file = new File(scriptsFolder, fileName);

Modified: 
trunk/mashup/java/modules/coreservices/servicesharinghelper/src/org/wso2/mashup/coreservices/servicesharinghelper/ServiceSharingHelper.java
==============================================================================
--- 
trunk/mashup/java/modules/coreservices/servicesharinghelper/src/org/wso2/mashup/coreservices/servicesharinghelper/ServiceSharingHelper.java
 (original)
+++ 
trunk/mashup/java/modules/coreservices/servicesharinghelper/src/org/wso2/mashup/coreservices/servicesharinghelper/ServiceSharingHelper.java
 Tue Jan  8 23:46:16 2008
@@ -25,10 +25,12 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.wso2.javascript.rhino.JavaScriptEngineConstants;
+import org.wso2.mashup.MashupConstants;
 import org.wso2.mashup.MashupFault;
 import org.wso2.mashup.utils.MashupArchiveManupulator;
+import org.wso2.mashup.utils.MashupUtils;
+import org.wso2.usermanager.UserManagerException;
 import org.wso2.wsas.admin.service.GlobalAdmin;
-import org.wso2.wsas.admin.service.util.AdminAuthenticator;
 
 import javax.activation.DataHandler;
 import java.io.File;
@@ -45,7 +47,8 @@
 
     private static final Log log = LogFactory.getLog(GlobalAdmin.class);
 
-    public Boolean shareService(String serviceName, String 
destinationServerAddress)
+    public Boolean shareService(String serviceName, String username, String 
password,
+                                String destinationServerAddress)
             throws IOException {
         boolean success;
 
@@ -75,9 +78,11 @@
         // method.
         File serviceJS = (File) serviceJSParameter.getValue();
 
+        String shortServiceName =
+                
serviceName.substring(serviceName.indexOf(MashupConstants.SEPARATOR_CHAR) + 1);
         
masshupArchiveManupulator.uploadMashupService(destinationServerAddress, 
dataHandler,
                                                       configContext, 
serviceJS.getName(),
-                                                      axisService.getName());
+                                                      shortServiceName, 
username, password);
         log
                 .info("Shared Service \'" + serviceName + "' to the 
destination server"
                         + destinationServerAddress + " at " + 
date.format(currentTime) + "from "
@@ -108,15 +113,20 @@
         String remoteIP = (String) 
messageContext.getProperty(MessageContext.REMOTE_ADDR);
         SimpleDateFormat date = new SimpleDateFormat("'['yyyy-MM-dd 
HH:mm:ss,SSSS']'");
         Date currentTime = Calendar.getInstance().getTime();
-        boolean loggedIn = new AdminAuthenticator().authenticate(username, 
password);
+        boolean loggedIn = false;
+        try {
+            loggedIn = MashupUtils.authenticateUser(username, password);
+        } catch (UserManagerException e) {
+            throw AxisFault.makeFault(e);
+        }
         if (loggedIn) {
             AxisConfiguration axisConfiguration = 
configurationContext.getAxisConfiguration();
             
             // forms might have posted the data with URLEncoding
             remoteServer = URIEncoderDecoder.decode(remoteServer);
             MashupArchiveManupulator archiveManupulator = new 
MashupArchiveManupulator();
-            archiveManupulator.downloadMashupService(remoteServer, 
serviceName, messageContext,
-                                                     axisConfiguration);
+            archiveManupulator.downloadMashupService(remoteServer, 
serviceName, username,  password, 
+                                                     messageContext, 
axisConfiguration);
             log.info("Downloaded Service \'" + serviceName + " at " + 
date.format(currentTime));
             return Boolean.TRUE;
         }

Modified: 
trunk/mashup/java/modules/coreservices/sharingservice/src/org/wso2/mashup/share/service/MashupSharingService.java
==============================================================================
--- 
trunk/mashup/java/modules/coreservices/sharingservice/src/org/wso2/mashup/share/service/MashupSharingService.java
   (original)
+++ 
trunk/mashup/java/modules/coreservices/sharingservice/src/org/wso2/mashup/share/service/MashupSharingService.java
   Tue Jan  8 23:46:16 2008
@@ -22,6 +22,7 @@
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.wso2.javascript.rhino.JavaScriptEngineConstants;
+import org.wso2.mashup.MashupConstants;
 import org.wso2.mashup.MashupFault;
 import org.wso2.mashup.utils.DownloadServiceResponse;
 import org.wso2.mashup.utils.MashupArchiveManupulator;
@@ -52,7 +53,8 @@
      *                    Data of the bundled mashup archive.
      * @throws IOException - Thrown in case the service cannot be found
      */
-    public void shareMashup(String serviceName, String fileName, DataHandler 
dataHandler)
+    public void shareMashup(String serviceName, String username, String 
password, String fileName,
+                            DataHandler dataHandler)
             throws IOException {
         if (dataHandler == null) {
             throw new MashupFault("Cannot read the uploaded Mashup Service.");
@@ -60,12 +62,12 @@
         MessageContext messageContext = 
MessageContext.getCurrentMessageContext();
         AxisConfiguration axisConfiguration = 
messageContext.getConfigurationContext()
                 .getAxisConfiguration();
-        if (axisConfiguration.getService(serviceName) != null) {
+        if (axisConfiguration.getService(username + 
MashupConstants.SEPARATOR_CHAR + serviceName) != null) {
             throw new AxisFault(
                     "A Service with a same name already exists in the remote 
Mashup Server.");
         }
         MashupArchiveManupulator archiveManupulator = new 
MashupArchiveManupulator();
-        archiveManupulator.deploySharedService(fileName, dataHandler, 
axisConfiguration);
+        archiveManupulator.deploySharedService(fileName, username, password, 
dataHandler, axisConfiguration);
     }
 
     /**

Modified: trunk/mashup/java/modules/www/js/mashup-utils.js
==============================================================================
--- trunk/mashup/java/modules/www/js/mashup-utils.js    (original)
+++ trunk/mashup/java/modules/www/js/mashup-utils.js    Tue Jan  8 23:46:16 2008
@@ -150,11 +150,9 @@
     parent.setAttribute("id", "MashupSharingDialog");
 
     var lblDestAddress = document.createElement("label");
-    lblDestAddress.appendChild(document.createTextNode("Enter Destination 
Server Address "));
+    lblDestAddress.appendChild(document.createTextNode("Destination Server 
Address   "));
     parent.appendChild(lblDestAddress);
 
-    parent.appendChild(document.createElement("br"));
-
     var txtDestServerAddress = document.createElement("input");
     txtDestServerAddress.setAttribute("type", "text");
     txtDestServerAddress.setAttribute("id", "txtDestAddress");
@@ -165,6 +163,33 @@
     parent.appendChild(document.createElement("br"));
     parent.appendChild(document.createElement("br"));
 
+    var lblUsername = document.createElement("label");
+    lblUsername.appendChild(document.createTextNode("Destination Server 
Username   "));
+    parent.appendChild(lblUsername);
+
+    var txtDestServerUsername = document.createElement("input");
+    txtDestServerUsername.setAttribute("type", "text");
+    txtDestServerUsername.setAttribute("id", "txtDestUsername");
+    txtDestServerUsername.setAttribute("size", "50");
+    parent.appendChild(txtDestServerUsername);
+
+    parent.appendChild(document.createElement("br"));
+    parent.appendChild(document.createElement("br"));
+
+    var lblPassword = document.createElement("label");
+    lblPassword.appendChild(document.createTextNode("Destination Server 
Password   "));
+    parent.appendChild(lblPassword);
+
+
+    var txtDestServerPassword = document.createElement("input");
+    txtDestServerPassword.setAttribute("type", "password");
+    txtDestServerPassword.setAttribute("id", "txtDestPassword");
+    txtDestServerPassword.setAttribute("size", "50");
+    parent.appendChild(txtDestServerPassword);
+
+    parent.appendChild(document.createElement("br"));
+    parent.appendChild(document.createElement("br"));
+
     var lblStatusMessages = document.createElement("label");
     lblStatusMessages.setAttribute("id", "lblStatus");
     parent.appendChild(lblStatusMessages);
@@ -178,7 +203,7 @@
         if (browser == "ie" || browser == "ie7") {
             serviceSharingDialog = new 
YAHOO.widget.Dialog("MashupSharingDialog",
             {
-                width : "500px",
+                width : "600px",
                 x:YAHOO.util.Dom.getViewportWidth() /
                   8, //Manual fix for getting rubbish viewport dimensions in IE
                 y:100,
@@ -191,7 +216,7 @@
             });
         } else {
             serviceSharingDialog = new 
YAHOO.widget.Dialog("MashupSharingDialog",
-            { width : "500px",
+            { width : "600px",
                 fixedcenter : true,
                 draggable:true,
                 visible : false,
@@ -224,12 +249,14 @@
         // Event handlers for the Dialog
         function handleSubmit() {
             var labelElement = document.getElementById("lblStatus");
-            var dest = document.getElementById("txtDestAddress").value;
+            var destAddress = document.getElementById("txtDestAddress").value;
+            var destUsername = 
document.getElementById("txtDestUsername").value;
+            var destPassword = 
document.getElementById("txtDestPassword").value;
 
-            if (WSO2.MashupUtils.isUrl(dest)) {
+            if (WSO2.MashupUtils.isUrl(destAddress)) {
                 labelElement.innerHTML = "";
                 labelElement.appendChild(document.createTextNode("Contacting 
backend services. Please wait..."));
-                wso2.mashup.services.shareService(serviceName, dest, 
submitServiceCallback, labelElement, submitServiceError);
+                wso2.mashup.services.shareService(serviceName, destAddress, 
destUsername, destPassword, submitServiceCallback, labelElement, 
submitServiceError);
             }
             else {
                 labelElement.innerHTML = "";

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        Tue Jan  8 23:46:16 2008
@@ -155,7 +155,7 @@
  * @public
  * @static
  * @param {String} serviceName         Name of the service to retrieve 
operations
- * @param {boolean} serviceStatus The desired status of 
+ * @param {boolean} serviceStatus The desired status of
  * @param {callback} callBack  User-defined callback function or object
  */
 wso2.mashup.services.activationOfService = function (serviceName, 
serviceStatus, callback, params) {
@@ -187,7 +187,7 @@
  * @public
  * @static
  * @param {String} serviceName         Name of the service to update the 
documentation
- * @param {String} documentation       Updated documentation of the Service 
+ * @param {String} documentation       Updated documentation of the Service
  * @param {callback} callBack  User-defined callback function or object
  * @param {callback} params    Parameters to be set in the callback
  */
@@ -286,12 +286,14 @@
  * @param {callback} params    Parameters to be set in the callback
  */
 wso2.mashup.services.shareService =
-function (serviceName, destinationAddress, callback, params, errorCallback) {
+function (serviceName, destinationAddress, username, password, callback, 
params, errorCallback) {
 
     var callURL = serverURL + "/" + "ServiceSharingHelper" + "/" ;
 
     var body_xml = '<req:shareServiceRequest 
xmlns:req="http://servicesharinghelper.coreservices.mashup.wso2.org/xsd";>\n' +
                    ' <req:serviceName>' + serviceName + '</req:serviceName>\n' 
+
+                   ' <req:username>' + username + '</req:username>\n' +
+                   ' <req:password>' + password + '</req:password>\n' +
                    ' <req:destinationServerAddress>' + destinationAddress +
                    '</req:destinationServerAddress>\n' +
                    ' </req:shareServiceRequest>\n';
@@ -379,7 +381,7 @@
 };
 
 /**
- * @description Re deploys a JS Service 
+ * @description Re deploys a JS Service
  * @param {String} serviceName Name of the Service
  * @param {callback} callback User-defined callback function or object
  */
@@ -437,7 +439,7 @@
  * @method getSharableServices
  * @public
  * @static
- * @param {callback} callBack  User-defined callback function or object  
+ * @param {callback} callBack  User-defined callback function or object
  */
 wso2.mashup.services.getSharableServices = function(callback) {
 
@@ -453,7 +455,7 @@
 /**
  * @description Obtains the contents of a given URL
  * @param url The URL to get contents from
- * @param callback  User-defined callback function or object  
+ * @param callback  User-defined callback function or object
  */
 wso2.mashup.services.getUrlContents = function(url, userAgent, callback) {
     var callURL = serverURL + "/" + "ScraperService" + "/" ;
@@ -488,7 +490,7 @@
     }
 };
 
-    
+
 
 
 

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

Reply via email to