-#ifdef _DEBUG\r
- xmltooling::NDC ndc("doAuthentication");\r
-#endif\r
-\r
- const Application* app=NULL;\r
- const char* procState = "Request Processing Error";\r
- string targetURL = request.getRequestURL();\r
-\r
- try {\r
- RequestMapper::Settings settings = request.getRequestSettings();\r
- app = &(request.getApplication());\r
-\r
- // If not SSL, check to see if we should block or redirect it.\r
- if (!request.isSecure()) {\r
- pair<bool,const char*> redirectToSSL = settings.first->getString("redirectToSSL");\r
- if (redirectToSSL.first) {\r
-#ifdef HAVE_STRCASECMP\r
- if (!strcasecmp("GET",request.getMethod()) || !strcasecmp("HEAD",request.getMethod())) {\r
-#else\r
- if (!stricmp("GET",request.getMethod()) || !stricmp("HEAD",request.getMethod())) {\r
-#endif\r
- // Compute the new target URL\r
- string redirectURL = string("https://") + request.getHostname();\r
- if (strcmp(redirectToSSL.second,"443")) {\r
- redirectURL = redirectURL + ':' + redirectToSSL.second;\r
- }\r
- redirectURL += request.getRequestURI();\r
- return make_pair(true, request.sendRedirect(redirectURL.c_str()));\r
- }\r
- else {\r
- TemplateParameters tp;\r
- tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));\r
- return make_pair(true,sendError(request, app, "ssl", tp));\r
- }\r
- }\r
- }\r
- \r
- const char* handlerURL=request.getHandlerURL(targetURL.c_str());\r
- if (!handlerURL)\r
- throw ConfigurationException("Cannot determine handler from resource URL, check configuration.");\r
-\r
- // If the request URL contains the handler base URL for this application, either dispatch\r
- // directly (mainly Apache 2.0) or just pass back control.\r
- if (strstr(targetURL.c_str(),handlerURL)) {\r
- if (handler)\r
- return doHandler(request);\r
- else\r
- return make_pair(true, request.returnOK());\r
- }\r
-\r
- // Three settings dictate how to proceed.\r
- pair<bool,const char*> authType = settings.first->getString("authType");\r
- pair<bool,bool> requireSession = settings.first->getBool("requireSession");\r
- pair<bool,const char*> requireSessionWith = settings.first->getString("requireSessionWith");\r
-\r
- // If no session is required AND the AuthType (an Apache-derived concept) isn't shibboleth,\r
- // then we ignore this request and consider it unprotected. Apache might lie to us if\r
- // ShibBasicHijack is on, but that's up to it.\r
- if ((!requireSession.first || !requireSession.second) && !requireSessionWith.first &&\r
-#ifdef HAVE_STRCASECMP\r
- (!authType.first || strcasecmp(authType.second,"shibboleth")))\r
-#else\r
- (!authType.first || _stricmp(authType.second,"shibboleth")))\r
-#endif\r
- return make_pair(true,request.returnDecline());\r
-\r
- // Fix for secadv 20050901\r
- clearHeaders(request);\r
-\r
- pair<string,const char*> shib_cookie = app->getCookieNameProps("_shibsession_");\r
- const char* session_id = request.getCookie(shib_cookie.first.c_str());\r
- if (!session_id || !*session_id) {\r
- // No session. Maybe that's acceptable?\r
- if ((!requireSession.first || !requireSession.second) && !requireSessionWith.first)\r
- return make_pair(true,request.returnOK());\r
-\r
- // No cookie, but we require a session. Initiate a new session using the indicated method.\r
- procState = "Session Initiator Error";\r
- const Handler* initiator=NULL;\r
- if (requireSessionWith.first) {\r
- initiator=app->getSessionInitiatorById(requireSessionWith.second);\r
- if (!initiator)\r
- throw ConfigurationException(\r
- "No session initiator found with id ($1), check requireSessionWith command.",\r
- params(1,requireSessionWith.second)\r
- );\r
- }\r
- else {\r
- initiator=app->getDefaultSessionInitiator();\r
- if (!initiator)\r
- throw ConfigurationException("No default session initiator found, check configuration.");\r
- }\r
-\r
- return initiator->run(request,false);\r
- }\r
-\r
- procState = "Session Processing Error";\r
- const Session* session=NULL;\r
- try {\r
- session=request.getSession();\r
- // Make a localized exception throw if the session isn't valid.\r
- if (!session)\r
- throw RetryableProfileException("Session no longer valid.");\r
- }\r
- catch (exception& e) {\r
- request.log(SPRequest::SPWarn, string("session processing failed: ") + e.what());\r
-\r
- // If no session is required, bail now.\r
- if ((!requireSession.first || !requireSession.second) && !requireSessionWith.first)\r
- // Has to be OK because DECLINED will just cause Apache\r
- // to fail when it can't locate anything to process the\r
- // AuthType. No session plus requireSession false means\r
- // do not authenticate the user at this time.\r
- return make_pair(true, request.returnOK());\r
-\r
- // Try and cast down.\r
- exception* base = &e;\r
- RetryableProfileException* trycast=dynamic_cast<RetryableProfileException*>(base);\r
- if (trycast) {\r
- // Session is invalid but we can retry -- initiate a new session.\r
- procState = "Session Initiator Error";\r
- const Handler* initiator=NULL;\r
- if (requireSessionWith.first) {\r
- initiator=app->getSessionInitiatorById(requireSessionWith.second);\r
- if (!initiator)\r
- throw ConfigurationException(\r
- "No session initiator found with id ($1), check requireSessionWith command.",\r
- params(1,requireSessionWith.second)\r
- );\r
- }\r
- else {\r
- initiator=app->getDefaultSessionInitiator();\r
- if (!initiator)\r
- throw ConfigurationException("No default session initiator found, check configuration.");\r
- }\r
- return initiator->run(request,false);\r
- }\r
- throw; // send it to the outer handler\r
- }\r
-\r
- // We're done. Everything is okay. Nothing to report. Nothing to do..\r
- // Let the caller decide how to proceed.\r
- request.log(SPRequest::SPDebug, "doAuthentication succeeded");\r
- return make_pair(false,0);\r
- }\r
- catch (XMLToolingException& e) {\r
- TemplateParameters tp;\r
- tp.m_map["errorType"] = procState;\r
- tp.m_map["errorText"] = e.what();\r
- tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));\r
- return make_pair(true,sendError(request, app, "session", tp, &e));\r
- }\r
- catch (exception& e) {\r
- TemplateParameters tp;\r
- tp.m_map["errorType"] = procState;\r
- tp.m_map["errorText"] = e.what();\r
- tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));\r
- return make_pair(true,sendError(request, app, "session", tp));\r
- }\r
-#ifndef _DEBUG\r
- catch (...) {\r
- TemplateParameters tp;\r
- tp.m_map["errorType"] = procState;\r
- tp.m_map["errorText"] = "Caught an unknown exception.";\r
- tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));\r
- return make_pair(true,sendError(request, app, "session", tp));\r
- }\r
-#endif\r
+#ifdef _DEBUG
+ xmltooling::NDC ndc("doAuthentication");
+#endif
+
+ const Application* app=NULL;
+ const char* procState = "Request Processing Error";
+ string targetURL = request.getRequestURL();
+
+ try {
+ RequestMapper::Settings settings = request.getRequestSettings();
+ app = &(request.getApplication());
+
+ // If not SSL, check to see if we should block or redirect it.
+ if (!request.isSecure()) {
+ pair<bool,const char*> redirectToSSL = settings.first->getString("redirectToSSL");
+ if (redirectToSSL.first) {
+#ifdef HAVE_STRCASECMP
+ if (!strcasecmp("GET",request.getMethod()) || !strcasecmp("HEAD",request.getMethod())) {
+#else
+ if (!stricmp("GET",request.getMethod()) || !stricmp("HEAD",request.getMethod())) {
+#endif
+ // Compute the new target URL
+ string redirectURL = string("https://") + request.getHostname();
+ if (strcmp(redirectToSSL.second,"443")) {
+ redirectURL = redirectURL + ':' + redirectToSSL.second;
+ }
+ redirectURL += request.getRequestURI();
+ return make_pair(true, request.sendRedirect(redirectURL.c_str()));
+ }
+ else {
+ TemplateParameters tp;
+ tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
+ return make_pair(true,sendError(request, app, "ssl", tp));
+ }
+ }
+ }
+
+ const char* handlerURL=request.getHandlerURL(targetURL.c_str());
+ if (!handlerURL)
+ throw ConfigurationException("Cannot determine handler from resource URL, check configuration.");
+
+ // If the request URL contains the handler base URL for this application, either dispatch
+ // directly (mainly Apache 2.0) or just pass back control.
+ if (strstr(targetURL.c_str(),handlerURL)) {
+ if (handler)
+ return doHandler(request);
+ else
+ return make_pair(true, request.returnOK());
+ }
+
+ // Three settings dictate how to proceed.
+ pair<bool,const char*> authType = settings.first->getString("authType");
+ pair<bool,bool> requireSession = settings.first->getBool("requireSession");
+ pair<bool,const char*> requireSessionWith = settings.first->getString("requireSessionWith");
+
+ // If no session is required AND the AuthType (an Apache-derived concept) isn't shibboleth,
+ // then we ignore this request and consider it unprotected. Apache might lie to us if
+ // ShibBasicHijack is on, but that's up to it.
+ if ((!requireSession.first || !requireSession.second) && !requireSessionWith.first &&
+#ifdef HAVE_STRCASECMP
+ (!authType.first || strcasecmp(authType.second,"shibboleth")))
+#else
+ (!authType.first || _stricmp(authType.second,"shibboleth")))
+#endif
+ return make_pair(true,request.returnDecline());
+
+ // Fix for secadv 20050901
+ clearHeaders(request);
+
+ procState = "Session Processing Error";
+
+ Session* session = NULL;
+ try {
+ session = request.getSession();
+ }
+ catch (exception& e) {
+ request.log(SPRequest::SPWarn, string("error during session lookup: ") + e.what());
+ // If it's not a retryable session failure, we throw to the outer handler for reporting.
+ if (dynamic_cast<RetryableProfileException*>(&e)==NULL)
+ throw;
+ }
+
+ if (!session) {
+ // No session. Maybe that's acceptable?
+ if ((!requireSession.first || !requireSession.second) && !requireSessionWith.first)
+ return make_pair(true,request.returnOK());
+
+ // No session, but we require one. Initiate a new session using the indicated method.
+ procState = "Session Initiator Error";
+ const Handler* initiator=NULL;
+ if (requireSessionWith.first) {
+ initiator=app->getSessionInitiatorById(requireSessionWith.second);
+ if (!initiator)
+ throw ConfigurationException(
+ "No session initiator found with id ($1), check requireSessionWith command.",
+ params(1,requireSessionWith.second)
+ );
+ }
+ else {
+ initiator=app->getDefaultSessionInitiator();
+ if (!initiator)
+ throw ConfigurationException("No default session initiator found, check configuration.");
+ }
+
+ return initiator->run(request,false);
+ }
+
+ // We're done. Everything is okay. Nothing to report. Nothing to do..
+ // Let the caller decide how to proceed.
+ request.log(SPRequest::SPDebug, "doAuthentication succeeded");
+ return make_pair(false,0);
+ }
+ catch (XMLToolingException& e) {
+ TemplateParameters tp;
+ tp.m_map["errorType"] = procState;
+ tp.m_map["errorText"] = e.what();
+ tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
+ return make_pair(true,sendError(request, app, "session", tp, &e));
+ }
+ catch (exception& e) {
+ TemplateParameters tp;
+ tp.m_map["errorType"] = procState;
+ tp.m_map["errorText"] = e.what();
+ tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
+ return make_pair(true,sendError(request, app, "session", tp));
+ }
+#ifndef _DEBUG
+ catch (...) {
+ TemplateParameters tp;
+ tp.m_map["errorType"] = procState;
+ tp.m_map["errorText"] = "Caught an unknown exception.";
+ tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
+ return make_pair(true,sendError(request, app, "session", tp));
+ }
+#endif