23 #include "AuthHandler.h"
25 AuthHandler::AuthHandler() {
30 AuthHandler::~AuthHandler() {
34 string AuthHandler::getFileExtension(
const string& file)
38 for(
unsigned int i=0; i<str.length(); i++)
42 for(
unsigned int j = i; j<str.length(); j++)
52 bool AuthHandler::handle(map<string, string> autMap, map<string, string> autpattMap,
HttpRequest* req,
HttpResponse& res, map<
string, vector<string> > filterMap,
void* dlib,
55 Logger logger = Logger::getLogger(
"AuthHandler");
56 bool isContrl =
false;
58 if(autpattMap[req->getCntxt_name()+
"*.*"]!=
"" || autMap[req->getCntxt_name()+ext]!=
"")
60 if(autpattMap[req->getCntxt_name()+
"*.*"]!=
"")
62 claz = autpattMap[req->getCntxt_name()+
"*.*"];
66 claz = autMap[req->getCntxt_name()+ext];
69 logger << (
"OAUTH/HTTP Authorization requested " + claz) << endl;
70 map<string,string>::iterator it;
71 map<string,string> tempmap = req->getAuthinfo();
72 for(it=tempmap.begin();it!=tempmap.end();it++)
74 logger << it->first <<
" = " << it->second << endl;
76 map<string,string> tempmap1 = req->getAllParams();
77 for(it=tempmap1.begin();it!=tempmap1.end();it++)
79 logger << it->first <<
" = " << it->second << endl;
81 if(claz.find(
"file:")!=string::npos)
83 claz = req->getCntxt_root()+
"/"+claz.substr(claz.find(
":")+1);
84 logger << (
"Auth handled by file " + claz) << endl;
86 if(authc->isInitialized())
88 if(authc->authenticate(req->getAuthinfo()[
"Username"],req->getAuthinfo()[
"Password"]))
90 logger <<
"Valid user" << endl;
94 logger <<
"Invalid user" << endl;
95 res.setHTTPResponseStatus(HTTPResponseStatus::AccessDenied);
97 logger <<
"Verified request token signature is invalid" << endl;
102 logger <<
"Invalid user repo defined" << endl;
105 else if(claz.find(
"class:")!=string::npos)
107 claz = claz.substr(claz.find(
":")+1);
108 claz =
"getReflectionCIFor" + claz;
109 logger << (
"Auth handled by class " + claz) << endl;
112 cerr << dlerror() << endl;
115 void *mkr = dlsym(dlib, claz.c_str());
118 FunPtr f = (FunPtr)mkr;
123 void *_temp = ref.newInstanceGVP(ctor);
125 authc->handle(req,&res);
126 if(res.getStatusCode()!=
"")
128 logger <<
"Authhandler called" << endl;
129 ext = getFileExtension(req->getUrl());