Back to index

nordugrid-arc-nox  1.1.0~rc6
test_ClientX509Delegation_ARC.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/ClientX509Delegation.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   /******** Test to ARC delegation service **********/
00029 
00030   std::string arc_deleg_url_str("https://127.0.0.1:60000/delegation");
00031   //std::string arc_deleg_url_str("https://glueball.uio.no:60000/delegation");
00032   Arc::URL arc_deleg_url(arc_deleg_url_str);
00033   Arc::MCCConfig arc_deleg_mcc_cfg;
00034   arc_deleg_mcc_cfg.AddPrivateKey("../echo/testuserkey-nopass.pem");
00035   arc_deleg_mcc_cfg.AddCertificate("../echo/testusercert.pem");
00036   arc_deleg_mcc_cfg.AddCAFile("../echo/testcacert.pem");
00037   arc_deleg_mcc_cfg.AddCADir("../echo/certificates");
00038 
00039   //Create a delegation SOAP client 
00040   logger.msg(Arc::INFO, "Creating a delegation soap client");
00041   Arc::ClientX509Delegation *arc_deleg_client = NULL;
00042   arc_deleg_client = new Arc::ClientX509Delegation(arc_deleg_mcc_cfg, arc_deleg_url);
00043 
00044   //Delegate a credential to the delegation service.
00045   //The credential inside mcc configuration is used for delegating.
00046   std::string arc_delegation_id;
00047   if(arc_deleg_client) {
00048     if(!(arc_deleg_client->createDelegation(Arc::DELEG_ARC, arc_delegation_id))) {
00049       logger.msg(Arc::ERROR, "Delegation to ARC delegation service failed");
00050       throw std::runtime_error("Delegation to ARC delegation service failed");
00051     }
00052   }
00053   logger.msg(Arc::INFO, "Delegation ID: %s", arc_delegation_id.c_str());
00054 
00055   //Acquire the delegated credential from the delegation service
00056   std::string arc_delegation_cred;
00057   if(!arc_deleg_client->acquireDelegation(Arc::DELEG_ARC, arc_delegation_cred, arc_delegation_id)) {
00058     logger.msg(Arc::ERROR,"Can not get the delegation credential: %s from delegation service:%s",arc_delegation_id.c_str(),arc_deleg_url_str.c_str());
00059     throw std::runtime_error("Can not get the delegation credential from delegation service");
00060   }
00061   logger.msg(Arc::INFO, "Delegated credential from delegation service: %s", arc_delegation_cred.c_str());
00062 
00063   if(arc_deleg_client) delete arc_deleg_client;
00064 
00065   return 0;
00066 }