Back to index

nordugrid-arc-nox  1.1.0~rc6
XACMLRequest.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 <arc/security/ClassLoader.h>
00007 
00008 #include "XACMLRequest.h"
00009 
00010 Arc::Logger ArcSec::XACMLRequest::logger(Arc::Logger::rootLogger, "XACMLRequest");
00011 
00012 static Arc::NS reqns("request", "urn:oasis:names:tc:xacml:2.0:context:schema:os");
00013 
00015 Arc::Plugin* ArcSec::XACMLRequest::get_request(Arc::PluginArgument* arg) {
00016   if(arg==NULL) return NULL;
00017   else {
00018     Arc::ClassLoaderPluginArgument* clarg =
00019             arg?dynamic_cast<Arc::ClassLoaderPluginArgument*>(arg):NULL;
00020     if(!clarg) return NULL;
00021     Arc::XMLNode* xarg = (Arc::XMLNode*)(*clarg);
00022     if(xarg==NULL) { return new ArcSec::XACMLRequest(); } // ???
00023     ArcSec::Source source(*xarg);
00024     return new ArcSec::XACMLRequest(source);
00025   }
00026 }
00027 
00028 using namespace Arc;
00029 using namespace ArcSec;
00030 
00031 void XACMLRequest::make_request(){
00032   //Parse the XMLNode structure, and generate the RequestAttribute object
00033   if((!reqnode) || (reqnode.Size() == 0)) {
00034     logger.msg(ERROR,"Request is empty");
00035     return;
00036   }
00037   std::list<XMLNode> r = reqnode.XPathLookup("//request:Request", reqns);
00038   if(r.empty()) {
00039     logger.msg(ERROR,"Can not find <Request/> element with proper namespace");
00040     return;
00041   }
00042   XMLNode node = *(r.begin());
00043 
00044   XMLNode nd, cnd;
00045 
00046   //Parse the <Subject> part
00047   //"Catagory" need to be processed
00048   std::string type;
00049   int i;
00050   nd = node["Subject"];
00051   if(!nd) {std::cerr<<"There is no subject element in request"<<std::endl; exit(0); }
00052   Subject sub;
00053   for(i = 0;; i++) {
00054     cnd = nd["Attribute"][i];
00055     if(!cnd) break;
00056     sub.push_back(new RequestAttribute(cnd, attrfactory));
00057   }
00058 
00059   //Parse the <Resource> part
00060   nd = node["Resource"];
00061   Resource res;
00062   for(i = 0;; i++) {
00063     cnd = nd["Attribute"][i];
00064     if(!cnd) break;
00065     res.push_back(new RequestAttribute(cnd, attrfactory));
00066   }
00067 
00068   //Parse the <Action> part
00069   nd = node["Action"];
00070   Action act;
00071   for(i = 0;; i++) {
00072     cnd = nd["Attribute"][i];
00073     if(!cnd) break;
00074     act.push_back(new RequestAttribute(cnd, attrfactory));
00075   }
00076 
00077   //Parse the <Environment> part
00078   nd = node["Environment"];
00079   Context env;
00080   for(i = 0;; i++) {
00081     cnd = nd["Attribute"][i];
00082     if(!cnd) break;
00083     env.push_back(new RequestAttribute(cnd, attrfactory));
00084   }
00085 
00086 }
00087 
00088 XACMLRequest::XACMLRequest (const Source& req) : Request(req) {
00089   req.Get().New(reqnode);
00090   NS ns;
00091   ns["ra"]="urn:oasis:names:tc:xacml:2.0:context:schema:os";
00092   reqnode.Namespaces(ns);
00093 }
00094 
00095 XACMLRequest::XACMLRequest () {
00096   NS ns;
00097   ns["ra"]="urn:oasis:names:tc:xacml:2.0:context:schema:os";
00098   XMLNode request(ns,"ra:Request");
00099   request.New(reqnode);
00100 }
00101 
00102 XACMLRequest::~XACMLRequest(){
00103 }