axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sam...@apache.org
Subject cvs commit: ws-axis/c/src/engine/client Stub.cpp
Date Fri, 25 Feb 2005 13:07:39 GMT
samisa      2005/02/25 05:07:39

  Modified:    c/include/axis/client Stub.hpp
               c/src/engine/client Stub.cpp
  Log:
  Support for Basic Authentication was added.
  AXISCPP-484.
  
  Revision  Changes    Path
  1.16      +36 -0     ws-axis/c/include/axis/client/Stub.hpp
  
  Index: Stub.hpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/include/axis/client/Stub.hpp,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Stub.hpp	24 Feb 2005 15:13:08 -0000	1.15
  +++ Stub.hpp	25 Feb 2005 13:07:39 -0000	1.16
  @@ -708,6 +708,26 @@
       */
       AXIS_PROTOCOL_TYPE getTransportProtocol();
   
  +  /**
  +    * Sets the username to be used for basic authentication
  +    */
  +    void setUsername(const char* pcUsername);
  +
  +  /**
  +    * Sets the password to be used for basic authentication
  +    */
  +    void setPassword(const char* pcPassword);
  +
  +  /**
  +    * Gets the username used for basic authentication
  +    */
  +    const char* getUsername();
  +
  +  /**
  +    * Gets the password used for basic authentication
  +    */
  +    const char* getPassword();
  +
     protected:
     /**
       * Apply user set preferences to each call made on the Stub object.
  @@ -735,6 +755,12 @@
       * of the Axis engine.
       */
       Call *getCall() { return m_pCall; }
  +
  +  /**
  +    * Set Authorization header for basic authentication
  +    */
  +    void setAuthorizationHeader();
  +
       Call *m_pCall;
   
     /**
  @@ -772,6 +798,16 @@
       */
       SOAPTransport* m_pTransport;
   
  +
  +  /**
  +    * Username
  +    */
  +   char* m_pcUsername;
  +
  +  /**
  +    * Password
  +    */
  +   char* m_pcPassword;
   };
   
   AXIS_CPP_NAMESPACE_END
  
  
  
  1.37      +79 -0     ws-axis/c/src/engine/client/Stub.cpp
  
  Index: Stub.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/engine/client/Stub.cpp,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- Stub.cpp	24 Feb 2005 15:13:08 -0000	1.36
  +++ Stub.cpp	25 Feb 2005 13:07:39 -0000	1.37
  @@ -24,10 +24,12 @@
   #include "../../soap/SoapSerializer.h"
   #include "../../soap/Attribute.h"
   #include "../../common/AxisUtils.h"
  +#include "../../soap/apr_base64.h"
   
   AXIS_CPP_NAMESPACE_USE
   
   Stub::Stub(const char *pcEndPointUri, AXIS_PROTOCOL_TYPE eProtocol) 
  +:m_pcUsername(NULL), m_pcPassword(NULL)
   {
       m_pCall = new Call();
       m_pCall->setProtocol(eProtocol);
  @@ -56,6 +58,11 @@
   	    delete m_vSOAPMethodAttributes[j];
   	    m_vSOAPMethodAttributes[j] = NULL;
       }
  +    
  +    if(m_pcUsername)
  +        delete [] m_pcUsername;
  +    if(m_pcPassword)
  +        delete [] m_pcPassword;
   }
   
   void Stub::setEndPoint(const char *pcEndPoint)
  @@ -388,3 +395,75 @@
   	    return NULL;
       }
   }
  +
  +void Stub::setUsername(const char* pcUsername)
  +{
  +    if(m_pcUsername) 
  +    {
  +        delete [] m_pcUsername;
  +        m_pcUsername = NULL;
  +    }
  +
  +    if(!pcUsername)
  +        return;
  +
  +    m_pcUsername = new char[strlen(pcUsername) + 1];
  +    strcpy(m_pcUsername, pcUsername);
  +
  +    if (m_pcPassword)
  +    {
  +        setAuthorizationHeader();
  +    }
  +}
  +
  +void Stub::setPassword(const char* pcPassword)
  +{
  +    if(m_pcPassword)
  +    {
  +        delete [] m_pcPassword;
  +        m_pcPassword = NULL;
  +    }
  +    
  +    if(!pcPassword)
  +        return;
  +
  +    m_pcPassword = new char[strlen(pcPassword) + 1];
  +    strcpy(m_pcPassword, pcPassword);
  +
  +    if (m_pcUsername)
  +    {
  +        setAuthorizationHeader();
  +    }
  +}
  +
  +const char* Stub::getUsername()
  +{
  +    return m_pcUsername;
  +}
  +
  +const char* Stub::getPassword()
  +{
  +    return m_pcPassword;
  +}
  +
  +void Stub::setAuthorizationHeader()
  +{
  +    char* cpUsernamePassword = new char[strlen(m_pcUsername) + strlen(m_pcPassword) + 2];
  +    strcpy( cpUsernamePassword, m_pcUsername );
  +    strcat( cpUsernamePassword, ":" );
  +    strcat( cpUsernamePassword, m_pcPassword );
  +
  +    int len = apr_base64_encode_len (strlen(cpUsernamePassword));
  +    AxisChar* base64Value = new AxisChar[len + 1];
  +    len = apr_base64_encode_binary (base64Value, (const unsigned char*)cpUsernamePassword,
strlen(cpUsernamePassword));
  +
  +    std::string strValue = "Basic ";
  +    strValue += base64Value;
  +
  +    if (m_pTransport)
  +        m_pTransport->setTransportProperty("Authorization", strValue.c_str());
  +
  +    delete [] cpUsernamePassword;
  +    delete [] base64Value;
  +}
  +
  
  
  

Mime
View raw message