Back to index

nordugrid-arc-nox  1.1.0~rc6
test.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <iostream>
00006 
00007 #include "UsernameToken.h"
00008 
00009 int main(void) {
00010   std::string xml("\
00011 <S:Envelope xmlns:S=\"http://www.w3.org/2003/05/soap-envelope\"\
00012   xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">\
00013   <S:Header>\
00014   </S:Header>\
00015   <S:Body>\
00016     <f:Delete xmlns:f=\"http://example.com/fabrikam\">\
00017        <maxCount>42</maxCount>\
00018     </f:Delete>\
00019   </S:Body>\
00020 </S:Envelope>\
00021 ");
00022   
00023   std::string username("user");
00024   std::string password("pass");
00025   std::string derived_key;
00026   std::string derived_key3;
00027   std::string derived_key4;
00028    
00029   /*Generate the Username Token*/
00030   Arc::SOAPEnvelope soap(xml);
00031   std::string uid("test-1");
00032   Arc::UsernameToken ut1(soap, username, password, uid, Arc::UsernameToken::PasswordDigest);
00033 
00034   std::string str;
00035   soap.GetXML(str,true);
00036   std::cout<<"SOAP message with UsernameToken:"<<std::endl<<str<<std::endl<<std::endl;
00037 
00038   /*Parse the Username Token*/
00039   Arc::UsernameToken ut2(soap);
00040   if(!ut2) {
00041     std::cout<<"Failed parsing previously generated UsernameToken"<<std::endl<<std::endl;
00042   } else if(!ut2.Authenticate(password,derived_key)) {
00043     std::cout<<"Failed to authenticate to previously generated UsernameToken"<<std::endl<<std::endl;
00044   }
00045 
00046   /*Generate the UsenameToken, for derived key*/
00047   Arc::SOAPEnvelope soap1(xml);
00048   Arc::UsernameToken ut3(soap1, username, uid, true, 150);
00049 
00050   soap1.GetXML(str,true);
00051   std::cout<<"SOAP message with UsernameToken, for derived key:"<<std::endl<<str<<std::endl<<std::endl;
00052   ut3.Authenticate(password,derived_key3);
00053 
00054   /*Generate the derived key*/
00055   Arc::UsernameToken ut4(soap1);
00056   if(!ut4) {
00057     std::cout<<"Failed parsing previously generated UsernameToken"<<std::endl<<std::endl;
00058   } else if(!ut4.Authenticate(password,derived_key4)) {
00059     std::cout<<"Failed to authenticate to previously generated UsernameToken"<<std::endl<<std::endl;
00060   } else if(derived_key3 != derived_key4) {
00061     std::cout<<"Derived keys do not match: "<<derived_key3<<" != "<<derived_key4<<std::endl<<std::endl;
00062   } else {
00063     std::cout<<"Derived key: "<<derived_key4<<std::endl<<std::endl;
00064   };
00065 
00066   return 0;
00067 }
00068