Back to index

nordugrid-arc-nox  1.1.0~rc6
arcpolicy.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 <arc/XMLNode.h>
00008 #include <arc/ArcLocation.h>
00009 #include <arc/security/ArcPDP/Response.h>
00010 #include <arc/security/ArcPDP/attr/AttributeValue.h>
00011 #include <arc/security/ArcPDP/EvaluatorLoader.h>
00012 
00013 using namespace ArcSec;
00014 
00015 int main(int argc,char* argv[]) {
00016   if(argc != 3) {
00017     std::cerr<<"Wrong number of arguments. Expecting policy and request."<<std::endl;
00018     return -1;
00019   };
00020   Arc::LogStream logcerr(std::cerr);
00021   Arc::Logger::getRootLogger().addDestination(logcerr);
00022   Arc::Logger::getRootLogger().setThreshold(Arc::WARNING);
00023 
00024   Evaluator* eval;
00025   std::string evaluator = "arc.evaluator";
00026   EvaluatorLoader eval_loader;
00027   eval = eval_loader.getEvaluator(evaluator);
00028   if(!eval) {
00029     std::cerr<<"Failed to create policy evaluator"<<std::endl;
00030   };
00031   eval->addPolicy(SourceFile(argv[1]));
00032   Response *resp = eval->evaluate(SourceFile(argv[2]));
00033   ResponseList rlist = resp->getResponseItems();
00034   int size = rlist.size();
00035   for(int i = 0; i < size; i++) {
00036     ResponseItem* item = rlist[i];
00037     RequestTuple* tp = item->reqtp;
00038     Subject subject = tp->sub;
00039     std::cout<<"Subject: ";
00040     for(Subject::iterator it = subject.begin(); it!= subject.end(); it++){
00041       AttributeValue *attrval;
00042       RequestAttribute *attr;
00043       attr = dynamic_cast<RequestAttribute*>(*it);
00044       if(attr){
00045         attrval = (*it)->getAttributeValue();
00046         if(attrval) std::cout<<attrval->encode();
00047       }
00048     };
00049     std::cout<<", Result: "<<item->res<<std::endl;
00050   }
00051   return 0;
00052 }