Back to index

nordugrid-arc-nox  1.1.0~rc6
AttributeDesignator.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include "AttributeDesignator.h"
00006 
00007 using namespace Arc;
00008 using namespace ArcSec;
00009 
00010 AttributeDesignator::AttributeDesignator(Arc::XMLNode& node, AttributeFactory* attr_factory) 
00011     : present(false), attrfactory(attr_factory) {
00012   std::string name = node.Name();
00013   size_t found = name.find("AttributeDesignator");
00014   target = name.substr(0, found);
00015 
00016   id = (std::string)(node.Attribute("AttributeId")); 
00017   if(id.empty()) {std::cerr<<"Required AttributeId does not exist in AttributeDesignator"<<std::endl; exit(0);}
00018 
00019   std::string tp = (std::string)(node.Attribute("DataType"));
00020   if(tp.empty()) {std::cerr<<"Required DataType does not exist in AttributeDesignator"<<std::endl; exit(0);}
00021 
00022   type = tp;
00023   
00024 #if 0
00025   found = tp.find_last_of("#");
00026   if(found!=std::string::npos) {
00027     type = tp.substr(found+1);
00028   }
00029   else {
00030     found=tp.find_last_of(":"); //urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name
00031     type = tp.substr(found+1);
00032   }
00033 #endif
00034 
00035   issuer = (std::string)(node.Attribute("Issuer"));
00036 
00037   if(target=="Subject") {
00038     category = (std::string)(node.Attribute("SubjectCategory"));
00039     if(category.empty()) category = "urn:oasis:names:tc:xacml:1.0:subject-category:access-subject";
00040   }
00041   
00042   std::string must = node.Attribute("MustBePresent");
00043   if(!must.empty()) present = true;
00044 }
00045 
00046 AttributeDesignator::~AttributeDesignator() {
00047 }
00048 
00049 std::list<AttributeValue*> AttributeDesignator::evaluate(EvaluationCtx* ctx) {
00050   std::list<AttributeValue*> res;
00051   if(target == "Subject") { res = ctx->getSubjectAttributes(id, type, issuer, category, attrfactory); } 
00052   else if(target == "Resource") { res = ctx->getResourceAttributes(id, type, issuer, attrfactory); }
00053   else if(target == "Action") { res = ctx->getActionAttributes(id, type, issuer, attrfactory); }
00054   else if(target == "Environment") { res = ctx->getContextAttributes(id, type, issuer, attrfactory); }
00055 
00056   if(present && (res.size() ==0)) {
00057     std::cerr<<"AttributeDesignator requires at least one attributes from request's"<<target<<std::endl;
00058   }
00059 
00060   return res;
00061 }
00062 
00063