Back to index

nordugrid-arc-nox  1.1.0~rc6
test_client_with_delegation_sechandler.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <iostream>
00006 #include <signal.h>
00007 
00008 #include <arc/ArcConfig.h>
00009 #include <arc/Logger.h>
00010 #include <arc/URL.h>
00011 #include <arc/message/SOAPEnvelope.h>
00012 #include <arc/message/PayloadSOAP.h>
00013 #include <arc/message/MCC.h>
00014 #include <arc/message/MCCLoader.h>
00015 #include <arc/client/ClientInterface.h>
00016 #ifdef WIN32
00017 #include <arc/win32.h>
00018 #endif
00019 
00020 static Arc::Logger& logger = Arc::Logger::rootLogger;
00021 
00022 int main(void) {
00023 
00024   setlocale(LC_ALL, "");
00025 
00026   Arc::LogStream logcerr(std::cerr);
00027   Arc::Logger::getRootLogger().addDestination(logcerr);
00028 //  Arc::Logger::getRootLogger().setThreshold(Arc::WARNING);
00029 
00030   //This is an example that shows how the client or the client called 
00031   //by a service, delegates a proxy to a delegation service.
00032 
00033   //Note the "DelegationServiceEndpoint" should be changed according
00034   //the actual delegation endpoint.
00035   Arc::XMLNode sechanlder_nd("\
00036         <SecHandler name='delegation.handler' id='delegation' event='outgoing'>\
00037           <Type>x509</Type>\
00038           <Role>delegator</Role>\
00039           <!--DelegationServiceEndpoint>https://127.0.0.1:60000/delegation</DelegationServiceEndpoint-->\
00040           <DelegationServiceEndpoint>https://glueball.uio.no:60000/delegation</DelegationServiceEndpoint>\
00041           <PeerServiceEndpoint>https://127.0.0.1:60000/echo</PeerServiceEndpoint>\
00042           <KeyPath>../echo/userkey-nopass.pem</KeyPath>\
00043           <CertificatePath>../echo/usercert.pem</CertificatePath>\
00044           <!--ProxyPath>/tmp/5612d050.pem</ProxyPath-->\
00045           <!--DelegationCredIdentity>/O=KnowARC/OU=UiO/CN=squark.uio.no</DelegationCredIdentity-->\
00046           <CACertificatePath>../echo/testcacert.pem</CACertificatePath>\
00047           <CACertificatesDir>../echo/certificates</CACertificatesDir>\
00048         </SecHandler>");
00049 
00050   /*For the firstly client in the service invocation chain, the credential path
00051     should be configured for the 'delegator' role delegation handler.
00052      <KeyPath>../echo/testkey-nopass.pem</KeyPath>\
00053      <CertificatePath>../echo/testcert.pem</CertificatePath>\
00054      <!--ProxyPath>/tmp/5612d050.pem</ProxyPath-->\
00055     Alternatively, For the clients which are called in the intermediate 
00056     service inside the service invocation chain, the the 'Identity' should 
00057     be configured for the 'delegator' role delegation handler. The 'Identity' 
00058     can be parsed from the 'incoming' message context of the service itself 
00059     by service implementation: 
00060       std::string identity= msg->Attributes()->get("TLS:IDENTITYDN");
00061     Afterwards, the service implementation should change the client 
00062     (the client that this service will call to contact the next intemediate service) 
00063     configuration to add 'DelegationCredIdentity' like the following.
00064     <DelegationCredIdentity>/O=KnowARC/OU=UiO/CN=squark.uio.no</DelegationCredIdentity>\
00065 
00066     Filling "DelegationCredIdentity" element is the only code that is needed for 
00067     the ARC services that need to utilize the delegation functionality (more 
00068     specifically, to launch a more level of delegation).
00069   */
00070 
00071   std::string url_str("https://127.0.0.1:60000/echo");
00072   Arc::URL url(url_str);
00073 
00074   Arc::MCCConfig mcc_cfg;
00075   mcc_cfg.AddPrivateKey("../echo/userkey-nopass.pem");
00076   mcc_cfg.AddCertificate("../echo/usercert.pem");
00077   mcc_cfg.AddCADir("../echo/certificates");
00078   mcc_cfg.AddCAFile("../echo/testcacert.pem");
00079 
00080   //Create a SOAP client
00081   logger.msg(Arc::INFO, "Creating a soap client");
00082 
00083   Arc::ClientSOAP *client;
00084   client = new Arc::ClientSOAP(mcc_cfg,url,60);
00085   client->AddSecHandler(sechanlder_nd, "arcshc");
00086 
00087   //Create and send echo request
00088   logger.msg(Arc::INFO, "Creating and sending request");
00089   Arc::NS echo_ns; echo_ns["echo"]="http://www.nordugrid.org/schemas/echo";
00090   Arc::PayloadSOAP req(echo_ns);
00091   req.NewChild("echo").NewChild("say")="HELLO";
00092 
00093   Arc::PayloadSOAP* resp = NULL;
00094 
00095   if(client) {
00096     std::string str;
00097     req.GetXML(str);
00098     std::cout<<"request: "<<str<<std::endl;
00099     Arc::MCC_Status status = client->process(&req,&resp);
00100     if(!status) {
00101       logger.msg(Arc::ERROR, "SOAP invokation failed");
00102     }
00103     if(resp == NULL) {
00104       logger.msg(Arc::ERROR,"There was no SOAP response");
00105     }
00106   }
00107 
00108   std::string xml;
00109   resp->GetXML(xml);
00110   std::cout << "XML: "<< xml << std::endl;
00111   std::cout << "Response: " << (std::string)((*resp)["echoResponse"]["hear"]) << std::endl;
00112 
00113   if(resp) delete resp;
00114   if(client) delete client;
00115 
00116   return 0;
00117 }