Back to index

nordugrid-arc-nox  1.1.0~rc6
test_samltoken.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 <fstream>
00007 
00008 #include <arc/xmlsec/XmlSecUtils.h>
00009 #include "SAMLToken.h"
00010 
00011 int main(void) {
00012   std::string xml("\
00013 <S:Envelope xmlns:S=\"http://www.w3.org/2003/05/soap-envelope\"\
00014   xmlns:wsa=\"http://www.w3.org/2005/08/addressing\"\
00015   xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">\
00016   <S:Header>\
00017   </S:Header>\
00018   <S:Body>\
00019     <f:Delete xmlns:f=\"http://example.com/fabrikam\">\
00020        <maxCount>42</maxCount>\
00021     </f:Delete>\
00022   </S:Body>\
00023 </S:Envelope>\
00024 ");
00025   Arc::init_xmlsec();
00026 
00027   std::string cert = "../../../tests/echo/testcert.pem";
00028   std::string key = "../../../tests/echo/testkey-nopass.pem";  
00029 
00030   /*Generate the signature SAML Token*/
00031   Arc::SOAPEnvelope soap1(xml);
00032   Arc::SAMLToken st1(soap1, cert, key, Arc::SAMLToken::SAML2);
00033 
00034   std::string str;
00035   st1.GetXML(str);
00036   std::cout<<"SOAP message with SAMLToken:"<<std::endl<<str<<std::endl<<std::endl;
00037 
00038   /*Parse the SAML Token*/
00039   Arc::SOAPEnvelope soap2(str);
00040   Arc::SAMLToken st2(soap2);
00041   if(!st2) {
00042     std::cout<<"Failed parsing previously generated SAMLToken"<<std::endl<<std::endl;
00043   } else if(!(st2.Authenticate("../../../tests/echo/testcacert.pem", ""))) {
00044     std::cout<<"Failed to authenticate to previously generated SAMLToken"<<std::endl<<std::endl;
00045   }
00046 
00047   Arc::final_xmlsec(); 
00048   return 0;
00049 }
00050