Back to index

nordugrid-arc-nox  1.1.0~rc6
XACMLAttributeFactory.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <arc/security/ClassLoader.h>
00006 
00007 #include <arc/security/ArcPDP/attr/AttributeProxy.h>
00008 #include <arc/security/ArcPDP/attr/StringAttribute.h>
00009 #include <arc/security/ArcPDP/attr/DateTimeAttribute.h>
00010 #include <arc/security/ArcPDP/attr/X500NameAttribute.h>
00011 #include <arc/security/ArcPDP/attr/AnyURIAttribute.h>
00012 #include <arc/security/ArcPDP/attr/GenericAttribute.h>
00013 
00014 #include "XACMLAttributeProxy.h"
00015 #include "XACMLAttributeFactory.h"
00016 
00017 using namespace Arc;
00018 namespace ArcSec {
00019 
00020 Arc::Plugin* get_xacmlpdp_attr_factory (Arc::PluginArgument*) {
00021     return new ArcSec::XACMLAttributeFactory();
00022 }
00023 
00024 void XACMLAttributeFactory::initDatatypes(){
00025   //Some XACML specified attribute types
00026   apmap.insert(std::pair<std::string, AttributeProxy*>(StringAttribute::getIdentifier(), new XACMLAttributeProxy<StringAttribute>));
00027   apmap.insert(std::pair<std::string, AttributeProxy*>(DateTimeAttribute::getIdentifier(), new XACMLAttributeProxy<DateTimeAttribute>));
00028   apmap.insert(std::pair<std::string, AttributeProxy*>(DateAttribute::getIdentifier(), new XACMLAttributeProxy<DateAttribute>));
00029   apmap.insert(std::pair<std::string, AttributeProxy*>(TimeAttribute::getIdentifier(), new XACMLAttributeProxy<TimeAttribute>));
00030   apmap.insert(std::pair<std::string, AttributeProxy*>(DurationAttribute::getIdentifier(), new XACMLAttributeProxy<DurationAttribute>));
00031   apmap.insert(std::pair<std::string, AttributeProxy*>(PeriodAttribute::getIdentifier(), new XACMLAttributeProxy<PeriodAttribute>));
00032   apmap.insert(std::pair<std::string, AttributeProxy*>(X500NameAttribute::getIdentifier(), new XACMLAttributeProxy<X500NameAttribute>));
00033   apmap.insert(std::pair<std::string, AttributeProxy*>(AnyURIAttribute::getIdentifier(), new XACMLAttributeProxy<AnyURIAttribute>));
00034   apmap.insert(std::pair<std::string, AttributeProxy*>(GenericAttribute::getIdentifier(), new XACMLAttributeProxy<GenericAttribute>));
00035 
00038 }
00039 
00040 XACMLAttributeFactory::XACMLAttributeFactory(){
00041   initDatatypes();
00042 }
00043 
00044 AttributeValue* XACMLAttributeFactory::createValue(const XMLNode& node, const std::string& type){
00045   AttrProxyMap::iterator it;
00046   if((it=apmap.find(type)) != apmap.end())
00047     return ((*it).second)->getAttribute(node);
00048 #if 0
00049   // This may look like hack, but generic attribute needs special treatment
00050   std::string value;
00051   if((bool)(const_cast<XMLNode&>(node).Child())) {
00052     value = (std::string)(const_cast<XMLNode&>(node).Child());
00053   //<Attribute AttributeId="" DataType=""><AttributeValue>abc</AttributeValue></Attribute>
00054   } else {
00055     value = (std::string)node; 
00056   }
00057   //<AttributeValue DataType="">abc</AttributeValue>
00058 
00059   std::size_t start;
00060   start = value.find_first_not_of(" \n\r\t");
00061   value = value.substr(start);
00062   std::size_t end;
00063   end = value.find_last_not_of(" \n\r\t");
00064   value = value.substr(0, end+1);
00065 
00066   GenericAttribute* attr = new GenericAttribute(value,
00067             (std::string)(const_cast<XMLNode&>(node).Attribute("AttributeId")));
00068   attr->setType(type);
00069   return attr;
00070 #endif
00071 
00072   //For generic attributes, treat them as string
00073   if((it=apmap.find("string")) != apmap.end())
00074     return ((*it).second)->getAttribute(node);
00075   return NULL;
00076 }
00077 
00078 XACMLAttributeFactory::~XACMLAttributeFactory(){
00079   AttrProxyMap::iterator it;
00080   for(it = apmap.begin(); it != apmap.end(); it = apmap.begin()){
00081     AttributeProxy* attrproxy = (*it).second;
00082     apmap.erase(it);
00083     if(attrproxy) delete attrproxy;
00084   }
00085 }
00086 
00087 } // namespace ArcSec
00088