Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Attributes
ArcSec::XACMLApply Class Reference

#include <XACMLApply.h>

Collaboration diagram for ArcSec::XACMLApply:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 XACMLApply (Arc::XMLNode &node, EvaluatorContext *ctx)
virtual ~XACMLApply ()
virtual std::list
< AttributeValue * > 
evaluate (EvaluationCtx *ctx)

Private Attributes

Arc::XMLNode applynode
std::string functionId
AttributeFactoryattrfactory
FnFactoryfnfactory
Functionfunction
std::map< int, AttributeValue * > attrval_list
 Sub <Expression>*, the first value of map is the apperance sequence *in this <Apply>, because sequance should be counted in case of function *such as "less-or-equal".
std::map< int, XACMLApply * > sub_apply_list
std::map< int,
AttributeDesignator * > 
designator_list
std::map< int,
AttributeSelector * > 
selector_list

Detailed Description

Definition at line 18 of file XACMLApply.h.


Constructor & Destructor Documentation

Definition at line 18 of file XACMLApply.cpp.

                                                           : applynode(node), function(NULL) {
  attrfactory = (AttributeFactory*)(*ctx);
  fnfactory = (FnFactory*)(*ctx); 

  functionId = (std::string)(node.Attribute("FunctionId"));
  //get the suffix of xacml-formated FunctionId, like
  //"urn:oasis:names:tc:xacml:1.0:function:and",
  //and use it as the function name
  std::size_t found = functionId.find_last_of(":");
  std::string funcname = functionId.substr(found+1);

  if(funcname.empty()) { logger.msg(ERROR, "Can not create function: FunctionId does not exist"); return; }; 
  
  //create the Function based on the function name
  function = fnfactory->createFn(funcname);
  if(!function) { logger.msg(ERROR, "Can not create function %s", funcname); return; }

  //create the AttributeValue, AttributeDesignator and AttributeSelector
  XMLNode cnd;

  XMLNode attrval_nd;
  std::string attrval_id;
  std::string attrval_type;
  for(int i = 0;;i++ ) {
    cnd = node.Child(i);
    if(!cnd) break;
    std::string name = cnd.Name();
    if(name.find("AttributeValue") != std::string::npos) {
      std::string data_type = cnd.Attribute("DataType");
      //<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">
      //  http://www.med.example.com/schemas/record.xsd
      //</AttributeValue>
      attrval_nd = cnd;
      std::size_t f = data_type.find_last_of("#"); //http://www.w3.org/2001/XMLSchema#string
      if(f!=std::string::npos) {
        attrval_type = data_type.substr(f+1);
      }
      else {
        f=data_type.find_last_of(":"); //urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name
        attrval_type = data_type.substr(f+1);
      }
      AttributeValue* attrval = attrfactory->createValue(attrval_nd, attrval_type);
      attrval_list[i] = attrval;
    }
    else if(name.find("AttributeSelector") != std::string::npos) {
      AttributeSelector* selector = new AttributeSelector(cnd, attrfactory);
      selector_list[i] = selector;
    }
    else if(name.find("AttributeDesignator") != std::string::npos) {
      AttributeDesignator* designator = new AttributeDesignator(cnd, attrfactory);
      designator_list[i] = designator;
    }
    else if(name == "Apply") {
      XACMLApply* apply = new XACMLApply(cnd, ctx);
      sub_apply_list[i] = apply;
    }
  }
}

Here is the call graph for this function:

XACMLApply::~XACMLApply ( ) [virtual]

Definition at line 77 of file XACMLApply.cpp.

                        {
  std::map<int, AttributeValue*>::iterator attrval_it;
  std::map<int, AttributeSelector*>::iterator selector_it;
  std::map<int, AttributeDesignator*>::iterator designator_it;
  std::map<int, XACMLApply*>::iterator apply_it;
  attrval_it = attrval_list.begin();
  selector_it = selector_list.begin();
  designator_it = designator_list.begin();
  apply_it = sub_apply_list.begin();
 
  for(;attrval_it != attrval_list.end(); attrval_it++) { 
    AttributeValue* attrval = (*attrval_it).second;
    attrval_list.erase(attrval_it);
    delete attrval;
  }
  for(;selector_it != selector_list.end(); selector_it++) {  
    AttributeSelector* selector = (*selector_it).second;
    selector_list.erase(selector_it);
    delete selector;
  }
  for(;designator_it != designator_list.end(); designator_it++) {
    AttributeDesignator* designator = (*designator_it).second;
    designator_list.erase(designator_it);
    delete designator;
  }
  for(;apply_it != sub_apply_list.end(); apply_it++) {
    XACMLApply* apply = (*apply_it).second;
    sub_apply_list.erase(apply_it);
    delete apply;
  }
}

Member Function Documentation

std::list< AttributeValue * > XACMLApply::evaluate ( EvaluationCtx ctx) [virtual]

Definition at line 109 of file XACMLApply.cpp.

                                                                {
  std::list<AttributeValue*> list;
  std::list<AttributeValue*> attrlist;
  std::list<AttributeValue*> attrlist_to_remove;

  AttributeValue* attrval = NULL;
  AttributeSelector* selector = NULL;
  AttributeDesignator* designator = NULL;
  XACMLApply* apply = NULL;
  std::map<int, AttributeValue*>::iterator attrval_it;
  std::map<int, AttributeSelector*>::iterator selector_it;
  std::map<int, AttributeDesignator*>::iterator designator_it;
  std::map<int, XACMLApply*>::iterator apply_it;
  for(int i=0;;i++) {
    attrval_it = attrval_list.find(i);
    selector_it = selector_list.find(i);
    designator_it = designator_list.find(i);
    apply_it = sub_apply_list.find(i);

    if((attrval_it == attrval_list.end()) &&
       (selector_it == selector_list.end()) && 
       (designator_it == designator_list.end()) &&
       (apply_it == sub_apply_list.end()))
      break;

    if(attrval_it != attrval_list.end()) {
      attrlist.push_back((*attrval_it).second);
    }
    if(selector_it != selector_list.end()) {
      list = (*selector_it).second->evaluate(ctx);
      attrlist.insert(attrlist.end(), list.begin(), list.end());
      attrlist_to_remove.insert(attrlist_to_remove.end(), list.begin(), list.end());
    }
    if(designator_it != designator_list.end()) {
      list = (*designator_it).second->evaluate(ctx);
      attrlist.insert(attrlist.end(), list.begin(), list.end());
      attrlist_to_remove.insert(attrlist_to_remove.end(), list.begin(), list.end());
    }
    if(apply_it != sub_apply_list.end()) {
      list = (*apply_it).second->evaluate(ctx);
      attrlist.insert(attrlist.end(), list.begin(), list.end());
      attrlist_to_remove.insert(attrlist_to_remove.end(), list.begin(), list.end());
    }
  }

  //Evaluate
  std::list<AttributeValue*> res;
  try{
    std::cout<<"There are "<<attrlist.size()<<" attribute values to be evaluated"<<std::endl;
    res = function->evaluate(attrlist, false);
  } catch(std::exception&) { };

  while(!(attrlist_to_remove.empty())) {
    //Note that the attributes which are directly parsed 
    //from policy should not be deleted here.
    //Instead, they should be deleted by deconstructor of XACMLApply
    AttributeValue* val = attrlist_to_remove.back();
    attrlist_to_remove.pop_back();
    delete val;
  }

  return res;
}

Member Data Documentation

Definition at line 25 of file XACMLApply.h.

Definition at line 28 of file XACMLApply.h.

Sub <Expression>*, the first value of map is the apperance sequence *in this <Apply>, because sequance should be counted in case of function *such as "less-or-equal".

Definition at line 37 of file XACMLApply.h.

Definition at line 39 of file XACMLApply.h.

Definition at line 29 of file XACMLApply.h.

Definition at line 31 of file XACMLApply.h.

std::string ArcSec::XACMLApply::functionId [private]

Definition at line 26 of file XACMLApply.h.

Definition at line 40 of file XACMLApply.h.

Definition at line 38 of file XACMLApply.h.


The documentation for this class was generated from the following files: