Author: keith
Date: Wed Jun  4 00:44:37 2008
New Revision: 17894
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=17894

Log:
Fixing Mahup sharing to work when the destination server requires HTTP Basic 
authentication as an additional layer. Fix for Mashup Mashup-822. Need to do 
more testing and exception handling.


Modified:
   trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
   
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/www/js/mashup-utils.js
   trunk/mashup/java/modules/www/js/services.js

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java?rev=17894&r1=17893&r2=17894&view=diff
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
(original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
Wed Jun  4 00:44:37 2008
@@ -272,5 +272,8 @@
     // Refers to the addressing module
     public static final String ADDRESSING = "addressing";
 
+    // Refers to the addressing module
+    public static final String HTTP_AUTH_REQUIRED = "withBasicAuth";
+
     public static final int BUFFER_SIZE = 40960;
 }

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java?rev=17894&r1=17893&r2=17894&view=diff
==============================================================================
--- 
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
      Wed Jun  4 00:44:37 2008
@@ -32,6 +32,7 @@
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.rpc.client.RPCServiceClient;
 import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.transport.http.HttpTransportProperties;
 import org.apache.commons.httpclient.protocol.Protocol;
 import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
 import org.wso2.authenticator.AuthenticatorException;
@@ -208,7 +209,8 @@
     public void uploadMashupService(String destinationServerAddress, 
DataHandler dataHandler,
                                     ConfigurationContext configCtx, String 
serviceJsFileName,
                                     String mashupServiceName, String username, 
String password,
-                                    String overwriteExisting, String 
localUserName)
+                                    String overwriteExisting, String 
localUserName, String mode,
+                                String basicAuthUsername, String 
basicAuthPassword)
             throws IOException{
 
         if (destinationServerAddress.startsWith("http://";)) {
@@ -230,6 +232,14 @@
                     + "/services/MashupSharingService/shareMashup");
         }
 
+        if (MashupConstants.HTTP_AUTH_REQUIRED.equals(mode)){
+            HttpTransportProperties.Authenticator authenticator = new 
HttpTransportProperties.Authenticator();
+            authenticator.setUsername(basicAuthUsername);
+            authenticator.setPassword(basicAuthPassword);
+            authenticator.setPreemptiveAuthentication(true);
+            options.setProperty(HTTPConstants.AUTHENTICATE, authenticator);
+        }
+
         options.setTo(sharingServiceEPR);
         options.setAction("urn:shareMashup");
         options.setProperty(HTTPConstants.CHUNKED, "false");
@@ -273,7 +283,8 @@
     public void uploadMashupService(String destinationServerAddress, 
DataHandler dataHandler,
                                     ConfigurationContext configCtx, String 
serviceJsFileName,
                                     String mashupServiceName, String 
infoCardToken,
-                                    String overwriteExisting)
+                                    String overwriteExisting, String mode,
+                                    String basicAuthUsername, String 
basicAuthPassword)
             throws AxisFault {
 
         if (destinationServerAddress.startsWith("http://";)) {
@@ -295,6 +306,14 @@
                     + "/services/MashupSharingService/shareMashupIC");
         }
 
+        if (MashupConstants.HTTP_AUTH_REQUIRED.equals(mode)){
+            HttpTransportProperties.Authenticator authenticator = new 
HttpTransportProperties.Authenticator();
+            authenticator.setUsername(basicAuthUsername);
+            authenticator.setPassword(basicAuthPassword);
+            authenticator.setPreemptiveAuthentication(true);
+            options.setProperty(HTTPConstants.AUTHENTICATE, authenticator);
+        }
+        
         options.setTo(sharingServiceEPR);
         options.setAction("urn:shareMashupIC");
         options.setProperty(HTTPConstants.CHUNKED, "false");

Modified: 
trunk/mashup/java/modules/coreservices/servicesharinghelper/src/org/wso2/mashup/coreservices/servicesharinghelper/ServiceSharingHelper.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/coreservices/servicesharinghelper/src/org/wso2/mashup/coreservices/servicesharinghelper/ServiceSharingHelper.java?rev=17894&r1=17893&r2=17894&view=diff
==============================================================================
--- 
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
 Wed Jun  4 00:44:37 2008
@@ -47,7 +47,8 @@
 
     public Boolean shareService(String serviceName, String username, String 
password,
                                 String destinationServerAddress, String 
overwriteExisting,
-                                String migrateTags, String localUser)
+                                String migrateTags, String localUser, String 
mode,
+                                String basicAuthUsername, String 
basicAuthPassword)
             throws IOException {
         boolean success;
         File serviceFile;
@@ -92,7 +93,9 @@
                 
serviceName.substring(serviceName.indexOf(MashupConstants.SEPARATOR_CHAR) + 1);
         
masshupArchiveManupulator.uploadMashupService(destinationServerAddress, 
dataHandler,
                                                       configContext, 
serviceFile.getName(),
-                                                      shortServiceName, 
username, password, overwriteExisting, localUser);
+                                                      shortServiceName, 
username, password,
+                                                      overwriteExisting, 
localUser, mode,
+                                                      basicAuthUsername, 
basicAuthPassword);
         log
                 .info("Shared Service \'" + serviceName + "' to the 
destination server"
                         + destinationServerAddress + " at " + 
date.format(currentTime) + "from "
@@ -103,7 +106,8 @@
 
     public Boolean shareServiceIC(String serviceName, String infoCardToken,
                                 String destinationServerAddress, String 
overwriteExisting,
-                                String migrateTags)
+                                String migrateTags, String mode,
+                                String basicAuthUsername, String 
basicAuthPassword)
             throws IOException {
         boolean success;
         File serviceFile;
@@ -148,7 +152,9 @@
                 
serviceName.substring(serviceName.indexOf(MashupConstants.SEPARATOR_CHAR) + 1);
         
masshupArchiveManupulator.uploadMashupService(destinationServerAddress, 
dataHandler,
                                                       configContext, 
serviceFile.getName(),
-                                                      shortServiceName, 
infoCardToken, overwriteExisting);
+                                                      shortServiceName, 
infoCardToken,
+                                                      overwriteExisting, mode, 
basicAuthUsername,
+                                                      basicAuthPassword);
         log
                 .info("Shared Service \'" + serviceName + "' to the 
destination server"
                         + destinationServerAddress + " at " + 
date.format(currentTime) + "from "

Modified: trunk/mashup/java/modules/www/js/mashup-utils.js
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/www/js/mashup-utils.js?rev=17894&r1=17893&r2=17894&view=diff
==============================================================================
--- trunk/mashup/java/modules/www/js/mashup-utils.js    (original)
+++ trunk/mashup/java/modules/www/js/mashup-utils.js    Wed Jun  4 00:44:37 2008
@@ -167,13 +167,13 @@
                         '<tr><td nowrap  height="25"><b>Destination Server 
Username: </b></td><td><input name="txtDestUsername" type="text" 
id="txtDestUsername" size="50"/></td></tr>' +
                         '<tr><td nowrap  height="25"><b>Destination Server 
Password: </b></td><td><input name="txtDestPassword" type="password" 
id="txtDestPassword" size="50"/></td></tr>' +
                         '<tr><td></td><td nowrap height="30" 
valign="bottom"><input type="button" id="cmdShare" value="Share" 
onclick="WSO2.MashupUtils.shareService(\'' +
-                        serviceName + '\', \'userpass\',\'' + localUserName + 
'\');"/></td></tr>';
+                        serviceName + '\', \'userpass\',\'' + localUserName + 
'\', \'noBasicAuth\',\'' + null + '\',\'' + null + '\',\'' + null + '\',\'' + 
null + '\',\'' + null + '\');"/></td></tr>';
 
     if (InformationCard.AreCardsSupported()) {
         strFrmService +=
         '<tr><td height="25"><hr>If you have an associated InfoCard to login 
to the destination server, use the option below</td><td><img 
src="images/infocard_92x64.png" border="0"</td></tr>' +
         '<tr><td height="25"><input type="button" 
onclick="WSO2.MashupUtils.shareService(\'' +
-        serviceName + '\', \'infocard\',\'' + localUserName + '\');" 
value="Share with infocard"/></td></tr>';
+        serviceName + '\', \'infocard\',\'' + localUserName + '\', 
\'noBasicAuth\',\'' + null + '\',\'' + null + '\',\'' + null + '\',\'' + null + 
'\',\'' + null + '\');" value="Share with infocard"/></td></tr>';
     }
 
     strFrmService += '</table>' +
@@ -186,8 +186,36 @@
     });
 };
 
+WSO2.MashupUtils.showMashupSharingWithHTTPBasicAuthDialog = function 
(serviceName, localUserName, mode, destAddress, destUsername, destPassword, 
overwriteExisting, migrateTags) {
 
-WSO2.MashupUtils.shareService = function (serviceName, mode, localUserName) {
+    //Creating the content div
+    var strFrmService = '<table align="center" border="0">' +
+                        '<tr><td nowrap  height="25"><b>Username: 
</b></td><td><input name="txtBasicAuthUsername" type="text" 
id="txtBasicAuthUsername" value="" size="50"/></td></tr>' +
+                        '<tr><td nowrap  height="25"><b>Password: 
</b></td><td><input name="txtBasicAuthPassword" type="password" 
id="txtBasicAuthPassword" size="50"/></td></tr>' +
+                        '<tr><td></td><td nowrap height="30" valign="bottom">';
+
+    if (mode == "infocard") {
+        strFrmService +=
+        '<input type="button" onclick="WSO2.MashupUtils.shareService(\'' +
+        serviceName + '\', \'infocard\',\'' + localUserName + '\' , 
\'withBasicAuth\',\'' + destAddress + '\',\'' + destUsername + '\',\'' + 
destPassword + '\',\'' + overwriteExisting + '\',\'' + migrateTags + '\');" 
value="Share Service"/></td></tr>';
+    } else {
+        strFrmService +=
+        '<input type="button" id="cmdShare" value="Share" 
onclick="WSO2.MashupUtils.shareService(\'' +
+                        serviceName + '\', \'userpass\',\'' + localUserName + 
'\' , \'withBasicAuth\',\'' + destAddress + '\',\'' + destUsername + '\',\'' + 
destPassword + '\',\'' + overwriteExisting + '\',\'' + migrateTags + 
'\');"/></td></tr>';
+    }
+
+    strFrmService += '</table>' +
+                     '<label id="lblStatus" style="width: auto;"></label>';
+
+    YAHOO.util.Event.onContentReady('doc3', function() {
+        // Instantiate the Dialog
+        WSO2.MashupUtils.dialog("Enter credentials to authenticate using HTTP 
Basic Authentication", strFrmService, 500, 100, 'txtBasicAuthUsername');
+    });
+};
+
+
+WSO2.MashupUtils.shareService = function (serviceName, mode, localUserName, 
basicAuth, destAddress,
+                                          destUsername, destPassword, 
overwriteExisting, migrateTags) {
     function submitServiceCallback() {
 
         var response ;
@@ -217,6 +245,10 @@
         if (!error) {
             this.params.innerHTML =
             "Failed to share the service. Please refer to system admin for 
more details.";
+        } else if (error.reason.indexOf("Transport error: 401 Error: 
Authorization Required") > -1) {
+            WSO2.MashupUtils.dialog.close();
+            
WSO2.MashupUtils.showMashupSharingWithHTTPBasicAuthDialog(serviceName, 
localUserName,
+                    mode, destAddress, destUsername, destPassword, 
overwriteExisting, migrateTags);
         } else if (error.reason.indexOf("Access Denied. Please login first") > 
-1) {
             wso2.wsf.Util.alertMessage("Your session has expired.");
                 //Envoking force logout
@@ -233,28 +265,37 @@
     }
 
     var labelElement = document.getElementById("lblStatus");
-    var destAddress = document.getElementById("txtDestAddress").value;
-    var destUsername = document.getElementById("txtDestUsername").value;
-    var destPassword = document.getElementById("txtDestPassword").value;
-    var overwriteExisting = "false";
-    if (document.getElementById("chkOverwrite").checked) {
-        overwriteExisting = "true";
-    }
-    var migrateTags = "false";
-    if (document.getElementById("chkTags").checked) {
-        migrateTags = "true";
+    if (basicAuth != "withBasicAuth") {
+        destAddress = document.getElementById("txtDestAddress").value;
+        destUsername = document.getElementById("txtDestUsername").value;
+        destPassword = document.getElementById("txtDestPassword").value;
+        overwriteExisting = "false";
+        if (document.getElementById("chkOverwrite").checked) {
+            overwriteExisting = "true";
+        }
+        migrateTags = "false";
+        if (document.getElementById("chkTags").checked) {
+            migrateTags = "true";
+        }
     }
 
-
     if (WSO2.MashupUtils.isUrl(destAddress)) {
-        labelElement.innerHTML = "Contacting backend services. Please wait...";
+
+        var infoCardToken;
+        var basicAuthUsername = "";
+        var basicAuthPassword = "";
+        if (basicAuth == "withBasicAuth") {
+            labelElement.innerHTML = "Contacting backend services. Please 
wait... Authenticating to remote site via HTTP Basic Authentication";
+            basicAuthUsername = 
document.getElementById("txtBasicAuthUsername").value;
+            basicAuthPassword = 
document.getElementById("txtBasicAuthPassword").value;
+            labelElement.innerHTML = "Contacting backend services. Please 
wait...";
+        }
 
         if (mode == "infocard") {
-            var infoCardToken = InformationCard.GetToken();
-            wso2.mashup.services.shareServiceIC(serviceName, destAddress, 
infoCardToken, overwriteExisting, migrateTags, submitServiceCallback, 
labelElement, submitServiceError);
+            infoCardToken = InformationCard.GetToken();
+            wso2.mashup.services.shareServiceIC(serviceName, destAddress, 
infoCardToken, overwriteExisting, migrateTags, submitServiceCallback, 
labelElement, submitServiceError, basicAuth, basicAuthUsername, 
basicAuthPassword);
         } else {
-            wso2.mashup.services.shareService(serviceName, destAddress, 
destUsername, destPassword, overwriteExisting, migrateTags, localUserName, 
submitServiceCallback, labelElement, submitServiceError);
-
+            wso2.mashup.services.shareService(serviceName, destAddress, 
destUsername, destPassword, overwriteExisting, migrateTags, localUserName, 
submitServiceCallback, labelElement, submitServiceError, basicAuth, 
basicAuthUsername, basicAuthPassword);
         }
     }
     else {

Modified: trunk/mashup/java/modules/www/js/services.js
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/www/js/services.js?rev=17894&r1=17893&r2=17894&view=diff
==============================================================================
--- trunk/mashup/java/modules/www/js/services.js        (original)
+++ trunk/mashup/java/modules/www/js/services.js        Wed Jun  4 00:44:37 2008
@@ -298,7 +298,7 @@
  */
 wso2.mashup.services.shareService =
 function (serviceName, destinationAddress, username, password, 
overwriteExisting, migrateTags, localUserName, callback, params,
-          errorCallback) {
+          errorCallback, mode, basicAuthUsername, basicAuthPassword) {
 
     var callURL = mashupServerURL + "/" + "ServiceSharingHelper" + "/" ;
 
@@ -314,7 +314,16 @@
                    '</req:migrateTags>\n' +
                    ' <req:localUser>' + localUserName +
                    '</req:localUser>\n' +
-                   ' </req:shareServiceRequest>\n';
+                   ' <req:mode>' + mode +
+                   '</req:mode>\n';
+
+    if (mode == "withBasicAuth") {
+        body_xml += ' <req:basicAuthUsername>' + basicAuthUsername +
+                    '</req:basicAuthUsername>\n' +
+                    ' <req:basicAuthPassword>' + basicAuthPassword +
+                    '</req:basicAuthPassword>\n';
+    }
+    body_xml += ' </req:shareServiceRequest>\n';
 
     new wso2.wsf.WSRequest(callURL, "shareService", body_xml, callback, 
params, errorCallback);
 };
@@ -331,7 +340,7 @@
  */
 wso2.mashup.services.shareServiceIC =
 function (serviceName, destinationAddress, infocardtoken, overwriteExisting, 
migrateTags, callback, params,
-          errorCallback) {
+          errorCallback, mode, basicAuthUsername, basicAuthPassword) {
 
     var callURL = mashupServerURL + "/" + "ServiceSharingHelper" + "/" ;
 
@@ -347,12 +356,21 @@
                    '</req:overwriteExisting>\n' +
                    ' <req:migrateTags>' + migrateTags +
                    '</req:migrateTags>\n' +
-                   ' </req:shareServiceICRequest>\n';
+                   ' <req:mode>' + mode +
+                   '</req:mode>\n';
+
+    if (mode == "withBasicAuth") {
+        body_xml += ' <req:basicAuthUsername>' + basicAuthUsername +
+                    '</req:basicAuthUsername>\n' +
+                    ' <req:basicAuthPassword>' + basicAuthPassword +
+                    '</req:basicAuthPassword>\n';
+    }
+
+    body_xml += ' </req:shareServiceICRequest>';
 
     new wso2.wsf.WSRequest(callURL, "shareServiceIC", body_xml, callback, 
params, errorCallback);
 };
 
-
 /**
  * @description Method used to get a list of faulty service archives
  * @method listFaultyArchives

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

Reply via email to