Back to index

nordugrid-arc-nox  1.1.0~rc6
testinterface_xacml.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 <signal.h>
00007 #include <string>
00008 
00009 #include <arc/security/ArcPDP/Evaluator.h>
00010 #include <arc/security/ArcPDP/EvaluatorLoader.h>
00011 #include <arc/security/ArcPDP/Request.h>
00012 #include <arc/security/ArcPDP/Response.h>
00013 #include <arc/XMLNode.h>
00014 #include <arc/ArcConfig.h>
00015 //#include <arc/loader/ClassLoader.h>
00016 #include <arc/Logger.h>
00017 #include <arc/security/ArcPDP/attr/AttributeValue.h>
00018 #ifdef WIN32
00019 #include <arc/win32.h>
00020 #endif
00021 
00022 int main(void){
00023   signal(SIGTTOU,SIG_IGN);
00024   signal(SIGTTIN,SIG_IGN);
00025   signal(SIGPIPE,SIG_IGN);
00026   Arc::Logger logger(Arc::Logger::rootLogger, "PDPTest");
00027   Arc::LogStream logcerr(std::cerr);
00028   Arc::Logger::rootLogger.addDestination(logcerr);
00029   logger.msg(Arc::INFO, "Start test");
00030 
00031   ArcSec::EvaluatorLoader eval_loader;
00032 
00033   //TEST: XACMLEvaluator, XACMLPolicy, XACMLRequest
00034 
00035   //Load the Evaluator
00036   ArcSec::Evaluator* eval = NULL;
00037   std::string evaluator = "xacml.evaluator";
00038   eval = eval_loader.getEvaluator(evaluator);  
00039   if(eval == NULL) {
00040     logger.msg(Arc::ERROR, "Can not dynamically produce Evaluator");
00041     return 0;  
00042   }
00043 
00044   ArcSec::Policy* policy = NULL;
00045   std::string policyclassname = "xacml.policy";
00046   ArcSec::SourceFile policy_source("XACML_Policy.xml");
00047   policy = eval_loader.getPolicy(policyclassname, policy_source);
00048   if(policy == NULL)
00049     logger.msg(Arc::ERROR, "Can not dynamically produce Policy");
00050 
00051   ArcSec::Request* request = NULL;
00052   std::string requestclassname = "xacml.request";
00053   ArcSec::SourceFile request_source("XACML_Request.xml");
00054   request = eval_loader.getRequest(requestclassname, request_source);
00055 
00056   if(request == NULL)
00057     logger.msg(Arc::ERROR, "Can not dynamically produce Request");
00058 
00060   //eval->addPolicy(policy_source);
00061   eval->addPolicy(policy);
00062  
00063    ArcSec::Response *resp = NULL;
00064  
00066   resp = eval->evaluate(request_source);
00067   //resp = eval->evaluate(request_source, policy);
00068   //resp = eval->evaluate(request, policy_source);
00069   //resp = eval->evaluate(request_source, policy_source);  
00070   //resp = eval->evaluate(request, policy);
00071 
00073   ArcSec::ResponseList rlist = resp->getResponseItems();
00074   std::cout<<rlist[0]->res<<std::endl;
00075 
00076   if(resp){
00077     delete resp;
00078     resp = NULL;
00079   } 
00080   if(eval) delete eval;
00081   if(request) delete request;
00082 
00083   return 0;
00084 }