Back to index

nordugrid-arc-nox  1.1.0~rc6
PolicyParser.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <fstream>
00006 #include <iostream>
00007 
00008 #include <arc/loader/Loader.h>
00009 #include <arc/message/PayloadRaw.h>
00010 #include <arc/ArcConfig.h>
00011 #include <arc/StringConv.h>
00012 #include <arc/URL.h>
00013 #include <arc/security/ClassLoader.h>
00014 
00015 #include "PolicyParser.h"
00016 
00017 using namespace Arc;
00018 using namespace ArcSec;
00019 
00020 static Arc::Logger logger(Arc::Logger::rootLogger, "PolicyParser");
00021 
00022 PolicyParser::PolicyParser(){
00023 }
00024 
00025 /*
00027 void getfromFile(const char* name, std::string& xml_policy){
00028   std::string str;
00029   std::ifstream f(name);
00030   if(!f) logger.msg(ERROR,"Failed to read policy file %s",name);
00031 
00032   while (f >> str) {
00033     xml_policy.append(str);
00034     xml_policy.append(" ");
00035   }
00036   f.close();
00037 }
00038 
00040 void getfromURL(const char* name, std::string& xml_policy){
00041   Arc::URL url(name);
00042 
00043   // TODO: IMPORTANT: Use client interface.
00044   Arc::NS ns;
00045   Arc::Config c(ns);
00046   Arc::XMLNode cfg = c;
00047   Arc::XMLNode mgr = cfg.NewChild("ModuleManager");
00048   Arc::XMLNode pth1 = mgr.NewChild("Path");
00049   pth1 = "../../../mcc/tcp/.libs";
00050   Arc::XMLNode pth2 = mgr.NewChild("Path");
00051   pth2 = "../../../mcc/http/.libs";
00052   Arc::XMLNode plg1 = cfg.NewChild("Plugins");
00053   Arc::XMLNode mcctcp = plg1.NewChild("Name");
00054   mcctcp = "mcctcp";
00055   Arc::XMLNode plg2 = cfg.NewChild("Plugins");
00056   Arc::XMLNode mcchttp = plg2.NewChild("Name");
00057   mcchttp = "mcchttp";
00058   Arc::XMLNode chn = cfg.NewChild("Chain");
00059 
00060   Arc::XMLNode tcp = chn.NewChild("Component");
00061   Arc::XMLNode tcpname = tcp.NewAttribute("name");
00062   tcpname = "tcp.client";
00063   Arc::XMLNode tcpid = tcp.NewAttribute("id");
00064   tcpid = "tcp";
00065   Arc::XMLNode tcpcnt = tcp.NewChild("Connect");
00066   Arc::XMLNode tcphost = tcpcnt.NewChild("Host");
00067   tcphost = url.Host();
00068   Arc::XMLNode tcpport = tcpcnt.NewChild("Port");
00069   tcpport = Arc::tostring(url.Port());
00070 
00071   Arc::XMLNode http = chn.NewChild("Component");
00072   Arc::XMLNode httpname = http.NewAttribute("name");
00073   httpname = "http.client";
00074   Arc::XMLNode httpid = http.NewAttribute("id");
00075   httpid = "http";
00076   Arc::XMLNode httpentry = http.NewAttribute("entry");
00077   httpentry = "http";
00078   Arc::XMLNode httpnext = http.NewChild("next");
00079   Arc::XMLNode httpnextid = httpnext.NewAttribute("id");
00080   httpnextid = "tcp";
00081   Arc::XMLNode httpmeth = http.NewChild("Method");
00082   httpmeth = "GET";
00083   Arc::XMLNode httpep = http.NewChild("Endpoint");
00084   httpep = url.str();
00085 
00086   //std::cout<<"------ Configuration ------"<<std::endl;
00087   //std::string cfgstr;
00088   //c.GetDoc(cfgstr);
00089   //std::cerr << cfgstr << std::endl;
00090 
00091   Arc::Loader l(&c);
00092 
00093   Arc::Message request;
00094   Arc::PayloadRaw msg;
00095   Arc::MessageAttributes attributes;
00096   Arc::MessageContext context;
00097   request.Payload(&msg);
00098   request.Attributes(&attributes);
00099   request.Context(&context);
00100   Arc::Message response;
00101 
00102   if(!(l["http"]->process(request,response)))
00103     logger.msg(ERROR,"Failed to read policy from URL %s",name);
00104 
00105   try {
00106     Arc::PayloadRaw& payload =
00107       dynamic_cast<Arc::PayloadRaw&>(*response.Payload());
00108     xml_policy.append(payload.Content());
00109     xml_policy.append(" ");
00110   } catch(std::exception&) { };
00111 }
00112 */
00113 
00114 Policy* PolicyParser::parsePolicy(const Source& source, std::string policyclassname, EvaluatorContext* ctx){
00115   Arc::XMLNode node = source.Get();  
00116   Arc::ClassLoader* classloader = NULL;
00117   classloader=Arc::ClassLoader::getClassLoader();
00118   ArcSec::Policy * policy = (ArcSec::Policy*)(classloader->Instance(policyclassname, &node));
00119   if(policy == NULL) { logger.msg(ERROR, "Can not generate policy object"); return NULL; }
00120   policy->setEvaluatorContext(ctx);
00121   policy->make_policy();
00122 
00123   return policy;
00124 }
00125