Uploaded image for project: 'Xerces-C++'
  1. Xerces-C++
  2. XERCESC-1472

Add Basic Authentication to NetAccessors/Socket

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.6.0
    • 2.7.0
    • Utilities
    • None
    • Redhat Advanced Server 3

    Description

      Below is a patch to util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp that sends a basic authentication header if the XMLURL has the username and password defined.

      --diff below--

          • util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp 2004-09-08 06:56:35.000000000 -0700
          • /home/xdb/UnixHTTPURLInputStream.cpp 2005-08-05 14:21:01.000000000 -0700
            ***************
          • 127,132 ****
          • 127,133 ----
            #include <xercesc/util/TransService.hpp>
            #include <xercesc/util/TranscodingException.hpp>
            #include <xercesc/util/PlatformUtils.hpp>
            + #include <xercesc/util/Base64.hpp>

      XERCES_CPP_NAMESPACE_BEGIN

      ***************

          • 211,216 ****
          • 212,219 ----
            const XMLCh* path = urlSource.getPath();
            const XMLCh* fragment = urlSource.getFragment();
            const XMLCh* query = urlSource.getQuery(); + const XMLCh* username = urlSource.getUser();
            + const XMLCh* password = urlSource.getPassword();

      //
      // Convert the hostName to the platform's code page for gethostbyname and
      ***************

          • 371,376 ****
          • 374,399 ----
            }
            strcat(fBuffer, CRLF);

      + if (username && password)
      + {
      + unsigned int len = XMLString::stringLen(username) + XMLString::stringLen(password) + 1;
      + char* userPass = (char *)fMemoryManager->allocate((len + 1) * sizeof(*userPass));
      + char* encodedData;
      +
      + userPass[0] = '\0';
      + strcat(userPass, XMLString::transcode(username, fMemoryManager));
      + strcat(userPass, ":");
      + strcat(userPass, XMLString::transcode(password, fMemoryManager));
      + encodedData = (char *)Base64::encode((XMLByte *)userPass, strlen(userPass), &len, fMemoryManager);
      +
      + if (encodedData)
      +

      { + char *authorization = (char *)fMemoryManager->allocate((strlen("Authorization: Basic ") + len + 3) * sizeof(*authorization)); + sprintf(authorization, "Authorization: Basic %s", encodedData); + strcat(fBuffer, authorization); + }

      + }
      +
      if(httpInfo!=0 && httpInfo->fHeaders!=0)
      strncat(fBuffer,httpInfo->fHeaders,httpInfo->fHeadersLen);

      Attachments

        Activity

          People

            Unassigned Unassigned
            claud9999 Chris Knight
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: