Back to index

nordugrid-arc-nox  1.1.0~rc6
test_ClientSAML2SSO.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 #include <stdexcept>
00008 
00009 #include <arc/GUID.h>
00010 #include <arc/ArcConfig.h>
00011 #include <arc/Logger.h>
00012 #include <arc/URL.h>
00013 #include <arc/message/PayloadSOAP.h>
00014 #include <arc/message/MCC.h>
00015 #include <arc/client/ClientInterface.h>
00016 #include <arc/client/ClientSAML2SSO.h>
00017 #ifdef WIN32
00018 #include <arc/win32.h>
00019 #endif
00020 
00021 int main(void) {
00022   signal(SIGTTOU,SIG_IGN);
00023   signal(SIGTTIN,SIG_IGN);
00024   Arc::Logger logger(Arc::Logger::rootLogger, "Test");
00025   Arc::LogStream logcerr(std::cerr);
00026   Arc::Logger::rootLogger.addDestination(logcerr);
00027 
00028   std::string url_str("https://127.0.0.1:60000/echo");
00029   Arc::URL url(url_str);
00030 
00031   Arc::MCCConfig mcc_cfg;
00032   mcc_cfg.AddPrivateKey("../echo/testkey-nopass.pem");
00033   mcc_cfg.AddCertificate("../echo/testcert.pem");
00034   mcc_cfg.AddCAFile("../echo/testcacert.pem");
00035   mcc_cfg.AddCADir("../echo/certificates");
00036 
00037   Arc::NS echo_ns; echo_ns["echo"]="http://www.nordugrid.org/schemas/echo";
00038 
00039   std::string idp_name = "https://idp.testshib.org/idp/shibboleth";
00040   std::string username = "myself";
00041   std::string password = "myself";
00042 
00043 
00044   /******** Test to service with SAML2SSO **********/
00045 
00046   //Create a HTTP client
00047   logger.msg(Arc::INFO, "Creating a http client");
00048   Arc::ClientHTTPwithSAML2SSO *client_http;
00049   client_http = new Arc::ClientHTTPwithSAML2SSO(mcc_cfg,url);
00050   logger.msg(Arc::INFO, "Creating and sending request");
00051   Arc::PayloadRaw req_http;
00052   //req_http.Insert();
00053   Arc::PayloadRawInterface* resp_http = NULL;
00054   Arc::HTTPClientInfo info;
00055   if(client_http) {
00056     Arc::MCC_Status status = client_http->process("GET", "echo", &req_http,&info,&resp_http, idp_name, username, password);
00057     if(!status) {
00058       logger.msg(Arc::ERROR, "HTTP with SAML2SSO invokation failed");
00059       throw std::runtime_error("HTTP with SAML2SSO invokation failed");
00060     }
00061     if(resp_http == NULL) {
00062       logger.msg(Arc::ERROR,"There was no HTTP response");
00063       throw std::runtime_error("There was no HTTP response");
00064     }
00065   }
00066   if(resp_http) delete resp_http;
00067   if(client_http) delete client_http;
00068 
00069 
00070   //Create a SOAP client
00071   logger.msg(Arc::INFO, "Creating a soap client");
00072   Arc::ClientSOAPwithSAML2SSO *client_soap;
00073   client_soap = new Arc::ClientSOAPwithSAML2SSO(mcc_cfg,url);
00074   logger.msg(Arc::INFO, "Creating and sending request");
00075   Arc::PayloadSOAP req_soap(echo_ns);
00076   req_soap.NewChild("echo").NewChild("say")="HELLO";
00077   Arc::PayloadSOAP* resp_soap = NULL;
00078   if(client_soap) {
00079     Arc::MCC_Status status = client_soap->process(&req_soap,&resp_soap, idp_name, username, password);
00080     if(!status) {
00081       logger.msg(Arc::ERROR, "SOAP with SAML2SSO invokation failed");
00082       throw std::runtime_error("SOAP with SAML2SSO invokation failed");
00083     }
00084     if(resp_soap == NULL) {
00085       logger.msg(Arc::ERROR,"There was no SOAP response");
00086       throw std::runtime_error("There was no SOAP response");
00087     }
00088   }
00089   std::string xml_soap;
00090   resp_soap->GetXML(xml_soap);
00091   std::cout << "XML: "<< xml_soap << std::endl;
00092   std::cout << "Response: " << (std::string)((*resp_soap)["echoResponse"]["hear"]) << std::endl;
00093   if(resp_soap) delete resp_soap;
00094   if(client_soap) delete client_soap;
00095 
00096   return 0;
00097 }