HTTP Basic Authentication Support

Topics: Developer Forum, Project Management Forum, User Forum
Developer
May 15, 2007 at 2:33 PM
Hi,

I've extended the client to support HTTP Basic authentication. Enclosed below is patch for release 2.3

//multi-line
Comparing files soapclient.js and SOAPCLIENT_ORI.JS
***** soapclient.js
  113:  
  114:  SOAPClient.username = null;
  115:  SOAPClient.password = null;
  116:  
  117:  SOAPClient.invoke = function(url, method, parameters, async, callback)
***** SOAPCLIENT_ORI.JS
  113:  
  114:  SOAPClient.invoke = function(url, method, parameters, async, callback)
*****
 
***** soapclient.js
  173:          var xmlHttp = SOAPClient._getXmlHttp();
  174:          if (SOAPClient.userName && SOAPClient.password){
  175:                  xmlHttp.open("POST", url, async, SOAPClient.userName, SOAPClient.password);
  176:                  // Some WS implementations (i.e. BEA WebLogic Server 10.0 JAX-WS) don't support Challenge/Response HTTP BASIC, 
  177:  o we send authorization headers in the first request
  178:                  xmlHttp.setRequestHeader("Authorization", "Basic " + SOAPClient._toBase64(SOAPClient.userName + ":" + SOAPClien
  179:  .password));
  180:          }
  181:          else
  182:                  xmlHttp.open("POST", url, async);
  183:          var soapaction = ((ns.lastIndexOf("/") != ns.length - 1) ? ns + "/" : ns) + method;
***** SOAPCLIENT_ORI.JS
  170:          var xmlHttp = SOAPClient._getXmlHttp();
  171:          xmlHttp.open("POST", url, async);
  172:          var soapaction = ((ns.lastIndexOf("/") != ns.length - 1) ? ns + "/" : ns) + method;
*****
 
***** soapclient.js
  390:  
  391:  SOAPClient._toBase64 = function(input)
  392:  {
  393:          var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  394:          var output = "";
  395:          var chr1, chr2, chr3;
  396:          var enc1, enc2, enc3, enc4;
  397:          var i = 0;
  398:  
  399:          do {
  400:                  chr1 = input.charCodeAt(i++);
  401:                  chr2 = input.charCodeAt(i++);
  402:                  chr3 = input.charCodeAt(i++);
  403:  
  404:                  enc1 = chr1 >> 2;
  405:                  enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
  406:                  enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
  407:                  enc4 = chr3 & 63;
  408:  
  409:                  if (isNaN(chr2)) {
  410:                          enc3 = enc4 = 64;
  411:                  } else if (isNaN(chr3)) {
  412:                          enc4 = 64;
  413:                  }
  414:  
  415:                  output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
  416:                  keyStr.charAt(enc3) + keyStr.charAt(enc4);
  417:          } while (i < input.length);
  418:  
  419:          return output;
  420:  }
***** SOAPCLIENT_ORI.JS
*****

If you need the full .js file, or want me to commit it to the project, just let me know. I'd like to help enhance the client further.

Alex
Coordinator
May 28, 2007 at 1:09 PM
Yeah! That's great!
Welcome in the project team :-)