Back to index

nordugrid-arc-nox  1.1.0~rc6
XACMLFnFactory.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 #include <arc/security/ArcPDP/fn/EqualFunction.h>
00007 #include <arc/security/ArcPDP/fn/MatchFunction.h>
00008 #include <arc/security/ArcPDP/fn/InRangeFunction.h>
00009 #include <arc/security/ArcPDP/attr/StringAttribute.h>
00010 #include <arc/security/ArcPDP/attr/DateTimeAttribute.h>
00011 #include <arc/security/ArcPDP/attr/X500NameAttribute.h>
00012 #include <arc/security/ArcPDP/attr/AnyURIAttribute.h>
00013 
00014 #include "XACMLFnFactory.h"
00015 
00016 using namespace Arc;
00017 
00018 namespace ArcSec {
00019 
00020 Arc::Plugin* get_xacmlpdp_fn_factory (Arc::PluginArgument*) {
00021     return new ArcSec::XACMLFnFactory();
00022 }
00023 
00024 void XACMLFnFactory::initFunctions(){
00025   //EqualFunctions
00026   std::string fnName = EqualFunction::getFunctionName(StringAttribute::getIdentifier());
00027   std::string argType = StringAttribute::getIdentifier();
00028   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00029 
00030   fnName = EqualFunction::getFunctionName(DateTimeAttribute::getIdentifier());
00031   argType = DateTimeAttribute::getIdentifier();
00032   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00033 
00034   fnName = EqualFunction::getFunctionName(DateAttribute::getIdentifier());
00035   argType = DateAttribute::getIdentifier();
00036   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00037 
00038   fnName = EqualFunction::getFunctionName(TimeAttribute::getIdentifier());
00039   argType = TimeAttribute::getIdentifier();
00040   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00041 
00042   fnName = EqualFunction::getFunctionName(DurationAttribute::getIdentifier());
00043   argType = DurationAttribute::getIdentifier();
00044   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00045 
00046   fnName = EqualFunction::getFunctionName(PeriodAttribute::getIdentifier());
00047   argType = PeriodAttribute::getIdentifier();
00048   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00049 
00050   fnName = EqualFunction::getFunctionName(X500NameAttribute::getIdentifier());
00051   argType = X500NameAttribute::getIdentifier();
00052   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00053 
00054   fnName = EqualFunction::getFunctionName(AnyURIAttribute::getIdentifier());
00055   argType = AnyURIAttribute::getIdentifier();
00056   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00057 
00058   //MatchFunctions
00059   fnName = MatchFunction::getFunctionName(StringAttribute::getIdentifier());
00060   argType = StringAttribute::getIdentifier();
00061   fnmap.insert(std::pair<std::string, Function*>(fnName, new MatchFunction(fnName, argType)));
00062 
00063   fnName = MatchFunction::getFunctionName(X500NameAttribute::getIdentifier());
00064   argType = X500NameAttribute::getIdentifier();
00065   fnmap.insert(std::pair<std::string, Function*>(fnName, new MatchFunction(fnName, argType)));
00066 
00067   fnName = MatchFunction::getFunctionName(AnyURIAttribute::getIdentifier());
00068   argType = AnyURIAttribute::getIdentifier();
00069   fnmap.insert(std::pair<std::string, Function*>(fnName, new MatchFunction(fnName, argType)));
00070 
00071   //InRangeFunctions
00072   fnName = InRangeFunction::getFunctionName(StringAttribute::getIdentifier());
00073   argType = StringAttribute::getIdentifier();
00074   fnmap.insert(std::pair<std::string, Function*>(fnName, new InRangeFunction(fnName, argType)));
00075 
00076   fnName = InRangeFunction::getFunctionName(PeriodAttribute::getIdentifier());
00077   argType = PeriodAttribute::getIdentifier();
00078   fnmap.insert(std::pair<std::string, Function*>(fnName, new InRangeFunction(fnName, argType)));
00079 
00081 }
00082 
00083 XACMLFnFactory::XACMLFnFactory(){
00084   initFunctions();
00085 }
00086 
00087 Function* XACMLFnFactory::createFn(const std::string& type){
00088   FnMap::iterator it; 
00089   if((it=fnmap.find(type)) != fnmap.end()) 
00090     return (*it).second;
00091   else { //Default: string-equal
00092     std::string tp("string-equal");
00093     if((it=fnmap.find(tp)) != fnmap.end())
00094       return (*it).second;
00095   }
00096   return NULL;
00097 }
00098 
00099 XACMLFnFactory::~XACMLFnFactory(){
00100   FnMap::iterator it;
00101   for(it = fnmap.begin(); it != fnmap.end(); it = fnmap.begin()){
00102     Function* fn = (*it).second;
00103     fnmap.erase(it);
00104     if(fn) delete fn;
00105   }
00106 }
00107 
00108 } // namespace ArcSec
00109