Back to index

nordugrid-arc-nox  1.1.0~rc6
update_credentials.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <arc/message/SOAPEnvelope.h>
00006 #include <arc/ws-addressing/WSA.h>
00007 #include "job.h"
00008 #include "tools.h"
00009 
00010 #include "arex.h"
00011 
00012 namespace ARex {
00013 
00014 
00015 Arc::MCC_Status ARexService::UpdateCredentials(ARexGMConfig& config,Arc::XMLNode in,Arc::XMLNode out,const std::string& credentials) {
00016   /*
00017   UpdateCredentials (deleg)
00018     DelegatedToken
00019       Reference (multiple)
00020 
00021   UpdateCredentialsResponse (deleg)
00022 
00023   NotAuthorizedFault
00024   InvalidRequestMessageFault
00025   InvalidActivityIdentifierFault
00026   */
00027   {
00028     std::string s;
00029     in.GetXML(s);
00030     logger_.msg(Arc::VERBOSE, "UpdateCredentials: request = \n%s", s);
00031   };
00032   // Extract job id from references
00033   Arc::XMLNode refnode = in["DelegatedToken"]["Reference"];
00034   if(!refnode) {
00035     // Must refer to job
00036     logger_.msg(Arc::ERROR, "UpdateCredentials: missing Reference");
00037     Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Must have Activity specified in Reference");
00038     InvalidRequestMessageFault(fault,"deleg:Reference","Wrong multiplicity");
00039     out.Destroy();
00040     return Arc::MCC_Status();
00041   }
00042   if((bool)(refnode[1])) {
00043     // Only one job can be updated per operation (profile)
00044     logger_.msg(Arc::ERROR, "UpdateCredentials: wrong number of Reference");
00045     Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Can update credentials only for single Activity");
00046     InvalidRequestMessageFault(fault,"deleg:Reference","Wrong multiplicity");
00047     out.Destroy();
00048     return Arc::MCC_Status();
00049   };
00050   if(refnode.Size() != 1) {
00051     // Expecting single job EPR in Reference
00052     logger_.msg(Arc::ERROR, "UpdateCredentials: wrong number of elements inside Reference");
00053     Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Can update credentials only for single Activity");
00054     InvalidRequestMessageFault(fault,"deleg:Reference","Wrong content");
00055     out.Destroy();
00056     return Arc::MCC_Status();
00057   }
00058   std::string jobid = Arc::WSAEndpointReference(refnode.Child()).ReferenceParameters()["a-rex:JobID"];
00059   if(jobid.empty()) {
00060     // EPR is wrongly formated or not an A-REX EPR
00061     logger_.msg(Arc::ERROR, "UpdateCredentials: EPR contains no JobID");
00062     Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Can't find JobID element in ActivityIdentifier");
00063     InvalidRequestMessageFault(fault,"deleg:Reference","Wrong content");
00064     out.Destroy();
00065     return Arc::MCC_Status();
00066   };
00067   ARexJob job(jobid,config,logger_);
00068   if(!job) {
00069     // There is no such job
00070     std::string failure = job.Failure();
00071     logger_.msg(Arc::ERROR, "UpdateCredentials: no job found: %s",failure);
00072     Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Can't find requested Activity");
00073     UnknownActivityIdentifierFault(fault,"No corresponding Activity found");
00074     out.Destroy();
00075     return Arc::MCC_Status();
00076   };
00077   if(!job.UpdateCredentials(credentials)) {
00078     logger_.msg(Arc::ERROR, "UpdateCredentials: failed to update credentials");
00079     Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Internal error: Failed to update credentials");
00080     out.Destroy();
00081     return Arc::MCC_Status();
00082   };
00083   {
00084     std::string s;
00085     out.GetXML(s);
00086     logger_.msg(Arc::VERBOSE, "UpdateCredentials: response = \n%s", s);
00087   };
00088   return Arc::MCC_Status(Arc::STATUS_OK);
00089 }
00090 
00091 } // namespace ARex
00092