[cpp-sp] branch main updated: Update doHandler machinery with new APIs.

Scott Cantor cantor.2 at osu.edu
Wed Jan 29 16:51:37 UTC 2025


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository cpp-sp.

View the commit online:
http://git.shibboleth.net/view/?p=cpp-sp.git;a=commit;h=b85abb7fab47a2283a06cc3b16a564324371bbb9

The following commit(s) were added to refs/heads/main by this push:
     new b85abb7f Update doHandler machinery with new APIs.
b85abb7f is described below

commit b85abb7fab47a2283a06cc3b16a564324371bbb9
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Jan 29 11:51:31 2025 -0500

    Update doHandler machinery with new APIs.
---
 shibsp/AbstractSPRequest.cpp |  9 +++------
 shibsp/Agent.cpp             | 25 ++++++++++++++++---------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/shibsp/AbstractSPRequest.cpp b/shibsp/AbstractSPRequest.cpp
index 0b1e343f..8abdf5ff 100644
--- a/shibsp/AbstractSPRequest.cpp
+++ b/shibsp/AbstractSPRequest.cpp
@@ -231,17 +231,14 @@ const char* AbstractSPRequest::getHandlerURL(const char* resource) const
         resource = stackresource.c_str();
     }
 
-#ifdef HAVE_STRCASECMP
-    if (!resource || (strncasecmp(resource,"http://",7) && strncasecmp(resource,"https://",8)))
-#else
-    if (!resource || (strnicmp(resource,"http://",7) && strnicmp(resource,"https://",8)))
-#endif
+    if (!resource || (strncasecmp(resource,"http://",7) && strncasecmp(resource,"https://",8))) {
         throw ConfigurationException("Target resource was not an absolute URL.");
+    }
 
     bool ssl_only = getRequestSettings().first->getBool("handlerSSL", true);
     const char* handler = getRequestSettings().first->getString("handlerURL", "/Shibboleth.sso");
 
-    if (*handler!='/' && strncmp(handler,"http:",5) && strncmp(handler,"https:",6)) {
+    if (*handler != '/' && strncmp(handler,"http:",5) && strncmp(handler,"https:",6)) {
         throw ConfigurationException(string("Invalid handlerURL property: ") + handler);
     }
 
diff --git a/shibsp/Agent.cpp b/shibsp/Agent.cpp
index f5e087d2..f8781c10 100644
--- a/shibsp/Agent.cpp
+++ b/shibsp/Agent.cpp
@@ -25,6 +25,7 @@
 #include "AccessControl.h"
 #include "SPRequest.h"
 #include "attribute/Attribute.h"
+#include "handler/HandlerConfiguration.h"
 #include "handler/SessionInitiator.h"
 #include "logging/Category.h"
 #include "session/SessionCache.h"
@@ -266,7 +267,7 @@ pair<bool,long> Agent::doAuthentication(SPRequest& request, bool handler) const
             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.
+        // directly or just pass back control based on parameter to this method.
         if (boost::contains(targetURL, handlerURL)) {
             if (handler)
                 return doHandler(request);
@@ -528,7 +529,7 @@ pair<bool,long> Agent::doHandler(SPRequest& request) const
     Category& log = Category::getInstance(SHIBSP_LOGCAT ".ServiceProvider");
 
     const Application* app = nullptr;
-    string targetURL = request.getRequestURL();
+    const char* targetURL = request.getRequestURL();
 
     try {
         RequestMapper::Settings settings = request.getRequestSettings();
@@ -552,23 +553,25 @@ pair<bool,long> Agent::doHandler(SPRequest& request) const
             }
         }
 
-        const char* handlerURL = request.getHandlerURL(targetURL.c_str());
+        const char* handlerURL = request.getHandlerURL(targetURL);
         if (!handlerURL)
             throw ConfigurationException("Cannot determine handler from resource URL, check configuration.");
 
-        // Make sure we only process handler requests.
+        // Make sure we only process handler requests and advance into the URL to find the handler's path.
         if (!boost::contains(targetURL, handlerURL))
             return make_pair(true, request.returnDecline());
 
         // We dispatch based on our path info. We know the request URL begins with or equals the handler URL,
         // so the path info is the next character (or null).
 
-        // TODO: replace with new handler infra
-        const Handler* handler = nullptr; // app->getHandler(targetURL.c_str() + strlen(handlerURL));
+        const HandlerConfiguration* handlerConfig = request.getAgent().getHandlerConfiguration(
+            request.getRequestSettings().first->getString("handlerConfigID"));
+        const Handler* handler = handlerConfig ? handlerConfig->getHandler(targetURL + strlen(handlerURL)) : nullptr;
         if (!handler)
             throw ConfigurationException("Shibboleth handler invoked at an unconfigured location.");
 
-        pair<bool, long> hret = handler->run(request);
+        pair<bool,long> hret = handler->run(request);
+
         // Did the handler run successfully?
         if (hret.first)
             return hret;
@@ -582,7 +585,11 @@ pair<bool,long> Agent::doHandler(SPRequest& request) const
         }
         catch (const exception&) {
         }
-        lock_guard<Session> slocker(*session, adopt_lock); // pop existing lock on exit
-        return make_pair(true, handleError(log, request, session, &e));
+        if (session) {
+            lock_guard<Session> slocker(*session, adopt_lock); // pop existing lock on exit
+            return make_pair(true, handleError(log, request, session, &e));
+        } else {
+            return make_pair(true, handleError(log, request, nullptr, &e));
+        }
     }
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list