Back to index

nordugrid-arc-nox  1.1.0~rc6
test_delegation_client.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 <glibmm.h>
00010 
00011 #include <arc/User.h>
00012 #include <arc/StringConv.h>
00013 #include <arc/GUID.h>
00014 #include <arc/ArcConfig.h>
00015 #include <arc/Logger.h>
00016 #include <arc/URL.h>
00017 #include <arc/message/PayloadSOAP.h>
00018 #include <arc/message/MCC.h>
00019 #include <arc/client/ClientInterface.h>
00020 #include <arc/client/ClientX509Delegation.h>
00021 #ifdef WIN32
00022 #include <arc/win32.h>
00023 #endif
00024 
00025 //The following is for showing how to use the specific client API
00026 // (ClientX509Delegation) to delegate a proxy to ARC delegation 
00027 //service, and gLite (gridsite) delegation service individually.
00028 int main(void) {
00029   signal(SIGTTOU,SIG_IGN);
00030   signal(SIGTTIN,SIG_IGN);
00031   Arc::Logger logger(Arc::Logger::rootLogger, "Test");
00032   Arc::LogStream logcerr(std::cerr);
00033   Arc::Logger::rootLogger.addDestination(logcerr);
00034 
00035   /******** Test to ARC delegation service **********/
00036   //Note the endpoint here should be changed 
00037   //into the actual endpoint of delegation service.
00038 
00039 //  std::string arc_deleg_url_str("https://127.0.0.1:60000/delegation");
00040   std::string arc_deleg_url_str("https://glueball.uio.no:60000/delegation");
00041   Arc::URL arc_deleg_url(arc_deleg_url_str);
00042   Arc::MCCConfig arc_deleg_mcc_cfg;
00043   arc_deleg_mcc_cfg.AddPrivateKey("../echo/testkey-nopass.pem");
00044   arc_deleg_mcc_cfg.AddCertificate("../echo/testcert.pem");
00045   arc_deleg_mcc_cfg.AddCAFile("../echo/testcacert.pem");
00046   arc_deleg_mcc_cfg.AddCADir("../echo/certificates");
00047   //Create a delegation SOAP client 
00048   logger.msg(Arc::INFO, "Creating a delegation soap client");
00049   Arc::ClientX509Delegation *arc_deleg_client = NULL;
00050   arc_deleg_client = new Arc::ClientX509Delegation(arc_deleg_mcc_cfg, arc_deleg_url);
00051   std::string arc_delegation_id;
00052   if(arc_deleg_client) {
00053     if(!(arc_deleg_client->createDelegation(Arc::DELEG_ARC, arc_delegation_id))) {
00054       logger.msg(Arc::ERROR, "Delegation to ARC delegation service failed");
00055       if(arc_deleg_client) delete arc_deleg_client;
00056       return 1;
00057     }
00058   }
00059   logger.msg(Arc::INFO, "Delegation ID: %s", arc_delegation_id.c_str());
00060   if(arc_deleg_client) delete arc_deleg_client;  
00061 
00062   /******** Test to gridsite delegation service **********/
00063   std::string gs_deleg_url_str("https://cream.grid.upjs.sk:8443/ce-cream/services/gridsite-delegation");
00064   Arc::URL gs_deleg_url(gs_deleg_url_str);
00065   Arc::MCCConfig gs_deleg_mcc_cfg;
00066   //Somehow gridsite delegation service only accepts proxy certificate,
00067   //not the EEC certificate, so we need to generate the proxy certificate
00068   //firstly.
00069   //Note the proxy needs to be generated before running this test.
00070   //And the proxy should be created by using a credential signed by officially
00071   //certified CAs, if the peer gridside delegation service only trusts
00072   //official CAs, not testing CA such as the InstantCA. It also applies to
00073   //the delegation to ARC delegation service.
00074   Arc::User user;
00075   std::string proxy_path  = Glib::build_filename(Glib::get_tmp_dir(),"x509up_u" + Arc::tostring(user.get_uid()));
00076   gs_deleg_mcc_cfg.AddProxy(proxy_path);
00077   gs_deleg_mcc_cfg.AddCADir("../echo/certificates");
00078   //Create a delegation SOAP client
00079   logger.msg(Arc::INFO, "Creating a delegation soap client");
00080   Arc::ClientX509Delegation *gs_deleg_client = NULL;
00081   gs_deleg_client = new Arc::ClientX509Delegation(gs_deleg_mcc_cfg, gs_deleg_url);
00082   std::string gs_delegation_id;
00083   gs_delegation_id = Arc::UUID();
00084   if(gs_deleg_client) {
00085     if(!(gs_deleg_client->createDelegation(Arc::DELEG_GRIDSITE, gs_delegation_id))) {
00086       logger.msg(Arc::ERROR, "Delegation to gridsite delegation service failed");
00087       if(gs_deleg_client) delete gs_deleg_client;
00088       return 1;
00089     }
00090   }
00091   logger.msg(Arc::INFO, "Delegation ID: %s", gs_delegation_id.c_str());
00092   if(gs_deleg_client) delete gs_deleg_client;
00093 
00094   return 0;
00095 }