[cpp-sp] branch main updated: Promote various remoting options to base class.

Scott Cantor cantor.2 at osu.edu
Wed Jan 22 20:36:52 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=1abf61a2286fcb0320dbd82606f5484ef6d5099b

The following commit(s) were added to refs/heads/main by this push:
     new 1abf61a2 Promote various remoting options to base class.
1abf61a2 is described below

commit 1abf61a2286fcb0320dbd82606f5484ef6d5099b
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Jan 22 15:36:43 2025 -0500

    Promote various remoting options to base class.
---
 .../remoting/impl/AbstractHTTPRemotingService.cpp  | 35 +++++++++++++++++++++-
 shibsp/remoting/impl/AbstractHTTPRemotingService.h | 12 ++++++++
 shibsp/remoting/impl/CurlHTTPRemotingService.cpp   | 30 +++++--------------
 3 files changed, 54 insertions(+), 23 deletions(-)

diff --git a/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp b/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp
index 65879a53..82c3cbf6 100644
--- a/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp
+++ b/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp
@@ -24,6 +24,7 @@
 #include "remoting/SecretSource.h"
 #include "remoting/impl/AbstractHTTPRemotingService.h"
 #include "util/BoostPropertySet.h"
+#include "util/PathResolver.h"
 
 #include <stdexcept>
 #include <boost/property_tree/ptree.hpp>
@@ -34,16 +35,21 @@ using namespace std;
 
 const char AbstractHTTPRemotingService::SECRET_SOURCE_TYPE_PROP_NAME[] = "secretSourceType";
 const char AbstractHTTPRemotingService::BASE_URL_PROP_NAME[] = "baseURL";
+const char AbstractHTTPRemotingService::USER_AGENT_PROP_NAME[] = "userAgent";
 const char AbstractHTTPRemotingService::AGENT_ID_PROP_NAME[] = "agentID";
 const char AbstractHTTPRemotingService::AUTH_METHOD_PROP_NAME[] = "authMethod";
+const char AbstractHTTPRemotingService::AUTH_CACHING_COOKIE_PROP_NAME[] = "authCachingCookie";
 const char AbstractHTTPRemotingService::CONNECT_TIMEOUT_PROP_NAME[] = "connectTimeout";
 const char AbstractHTTPRemotingService::TIMEOUT_PROP_NAME[] = "timeout";
+const char AbstractHTTPRemotingService::CA_FILE_PROP_NAME[] = "tlsCAFile";
 
 const char AbstractHTTPRemotingService::SECRET_SOURCE_TYPE_PROP_DEFAULT[] = "File";
 const char AbstractHTTPRemotingService::BASE_URL_PROP_DEFAULT[] = "http://localhost/idp/profile";
 const char AbstractHTTPRemotingService::AUTH_METHOD_PROP_DEFAULT[] = "basic";
+const char AbstractHTTPRemotingService::AUTH_CACHING_COOKIE_PROP_DEFAULT[] = "JSESSIONID";
 unsigned int AbstractHTTPRemotingService::CONNECT_TIMEOUT_PROP_DEFAULT = 3;
 unsigned int AbstractHTTPRemotingService::TIMEOUT_PROP_DEFAULT = 10;
+const char AbstractHTTPRemotingService::CA_FILE_PROP_DEFAULT[] = "trustlist.pem";
 
 AbstractHTTPRemotingService::AbstractHTTPRemotingService(ptree& pt)
     : AbstractRemotingService(pt), m_authMethod(agent_auth_none)
@@ -60,10 +66,17 @@ AbstractHTTPRemotingService::AbstractHTTPRemotingService(ptree& pt)
         props.getString(SECRET_SOURCE_TYPE_PROP_NAME, SECRET_SOURCE_TYPE_PROP_DEFAULT), pt, false)
         );
 
-    m_baseURL = props.getString(BASE_URL_PROP_NAME, BASE_URL_PROP_DEFAULT);
+    m_userAgent = props.getString(USER_AGENT_PROP_NAME, "");
+    m_baseURL = props.getString(BASE_URL_PROP_NAME, BASE_URL_PROP_DEFAULT);    
     m_authMethod = getAuthMethod(props.getString(AUTH_METHOD_PROP_NAME, AUTH_METHOD_PROP_DEFAULT));
+    m_authCachingCookie = props.getString(AUTH_CACHING_COOKIE_PROP_NAME, AUTH_CACHING_COOKIE_PROP_DEFAULT);
     m_connectTimeout = props.getUnsignedInt(CONNECT_TIMEOUT_PROP_NAME, CONNECT_TIMEOUT_PROP_DEFAULT);
     m_timeout = props.getUnsignedInt(TIMEOUT_PROP_NAME, TIMEOUT_PROP_DEFAULT);
+
+    m_caFile = props.getString(CA_FILE_PROP_NAME, CA_FILE_PROP_DEFAULT);
+    if (!m_caFile.empty()) {
+        AgentConfig::getConfig().getPathResolver().resolve(m_caFile, PathResolver::SHIBSP_CFG_FILE);
+    }
 }
 
 const SecretSource* AbstractHTTPRemotingService::getSecretSource(bool required) const
@@ -85,6 +98,21 @@ const char* AbstractHTTPRemotingService::getAgentID() const
     return m_agentID.c_str();
 }
 
+const char* AbstractHTTPRemotingService::getUserAgent() const
+{
+    return m_userAgent.c_str();
+}
+
+void AbstractHTTPRemotingService::setUserAgent(const char* ua)
+{
+    m_userAgent = ua ? ua : "";
+}
+
+const char* AbstractHTTPRemotingService::getAuthCachingCookie() const
+{
+    return m_authCachingCookie.c_str();
+}
+
 AbstractHTTPRemotingService::auth_t AbstractHTTPRemotingService::getAuthMethod() const
 {
     return m_authMethod;
@@ -100,6 +128,11 @@ unsigned int AbstractHTTPRemotingService::getTimeout() const
     return m_timeout;
 }
 
+const char* AbstractHTTPRemotingService::getCAFile() const
+{
+    return m_caFile.c_str();
+}
+
 AbstractHTTPRemotingService::auth_t AbstractHTTPRemotingService::getAuthMethod(const char* method)
 {
     if (method) {
diff --git a/shibsp/remoting/impl/AbstractHTTPRemotingService.h b/shibsp/remoting/impl/AbstractHTTPRemotingService.h
index 7f5737de..272a460e 100644
--- a/shibsp/remoting/impl/AbstractHTTPRemotingService.h
+++ b/shibsp/remoting/impl/AbstractHTTPRemotingService.h
@@ -51,23 +51,32 @@ namespace shibsp {
         const SecretSource* getSecretSource(bool required=true) const;
         const char* getBaseURL() const;
         const char* getAgentID() const;
+        const char* getUserAgent() const;
+        void setUserAgent(const char* ua);
         auth_t getAuthMethod() const;
+        const char* getAuthCachingCookie() const;
         unsigned int getConnectTimeout() const;
         unsigned int getTimeout() const;
+        const char* getCAFile() const;
 
         // Property names and defaults.
         static const char SECRET_SOURCE_TYPE_PROP_NAME[];
         static const char BASE_URL_PROP_NAME[];
         static const char AGENT_ID_PROP_NAME[];
+        static const char USER_AGENT_PROP_NAME[];
         static const char AUTH_METHOD_PROP_NAME[];
+        static const char AUTH_CACHING_COOKIE_PROP_NAME[];
         static const char CONNECT_TIMEOUT_PROP_NAME[];
         static const char TIMEOUT_PROP_NAME[];
+        static const char CA_FILE_PROP_NAME[];
 
         static const char SECRET_SOURCE_TYPE_PROP_DEFAULT[];
         static const char BASE_URL_PROP_DEFAULT[];
         static const char AUTH_METHOD_PROP_DEFAULT[];
+        static const char AUTH_CACHING_COOKIE_PROP_DEFAULT[];
         static unsigned int CONNECT_TIMEOUT_PROP_DEFAULT;
         static unsigned int TIMEOUT_PROP_DEFAULT;
+        static const char CA_FILE_PROP_DEFAULT[];
 
     protected:
         AbstractHTTPRemotingService(boost::property_tree::ptree& pt);
@@ -78,6 +87,9 @@ namespace shibsp {
         std::unique_ptr<SecretSource> m_secretSource;
         std::string m_baseURL;
         std::string m_agentID;
+        std::string m_userAgent;
+        std::string m_authCachingCookie;
+        std::string m_caFile;
         auth_t m_authMethod;
         unsigned int m_connectTimeout;
         unsigned int m_timeout;
diff --git a/shibsp/remoting/impl/CurlHTTPRemotingService.cpp b/shibsp/remoting/impl/CurlHTTPRemotingService.cpp
index dfdb11a2..84db6cb1 100644
--- a/shibsp/remoting/impl/CurlHTTPRemotingService.cpp
+++ b/shibsp/remoting/impl/CurlHTTPRemotingService.cpp
@@ -21,12 +21,10 @@
 #include "internal.h"
 #include "exceptions.h"
 
-#include "AgentConfig.h"
 #include "logging/Category.h"
 #include "remoting/SecretSource.h"
 #include "remoting/impl/AbstractHTTPRemotingService.h"
 #include "util/BoostPropertySet.h"
-#include "util/PathResolver.h"
 
 #include <stdexcept>
 #include <boost/property_tree/ptree.hpp>
@@ -78,11 +76,8 @@ namespace {
         mutable list<CURL*> m_pool;
         mutable int m_poolsize;
         mutable mutex m_lock;
-        string m_useragent;
         string m_ciphers;
-        string m_cafile;
         bool m_chunked;
-        bool m_authCaching;
     };
 
     class SHIBSP_DLLLOCAL CurlOperation
@@ -179,33 +174,24 @@ CurlHTTPRemotingService::CurlHTTPRemotingService(ptree& pt)
     : AbstractHTTPRemotingService(pt), AbstractRemotingService(pt),
         m_log(Category::getInstance(SHIBSP_LOGCAT ".RemotingService.CurlHTTP")),
             m_curllog(Category::getInstance(SHIBSP_LOGCAT ".libcurl")),
-                m_poolsize(20), m_chunked(true), m_authCaching(true)
+                m_poolsize(20), m_chunked(true)
 {
-    static const char USER_AGENT_PROP_NAME[] = "userAgentString";
     static const char CIPHER_LIST_PROP_NAME[] = "tlsCipherList";
     static const char CHUNKED_PROP_NAME[] = "chunkedEncoding";
-    static const char ENABLE_AUTH_CACHING[] = "enableAuthCaching";
-    static const char CA_FILE_PROP_NAME[] = "tlsCAFile";
-    static const char CA_FILE_PROP_DEFAULT[] = "trustlist.pem";
 
     BoostPropertySet props;
     props.load(pt);
 
-    m_useragent = props.getString(USER_AGENT_PROP_NAME, "");
     m_chunked = props.getBool(CHUNKED_PROP_NAME, true);
-    m_authCaching = props.getBool(ENABLE_AUTH_CACHING, true);
     m_ciphers = props.getString(CIPHER_LIST_PROP_NAME, "");
-    m_cafile = props.getString(CA_FILE_PROP_NAME, CA_FILE_PROP_DEFAULT);
-    if (!m_cafile.empty()) {
-        AgentConfig::getConfig().getPathResolver().resolve(m_cafile, PathResolver::SHIBSP_CFG_FILE);
-    }
 
-    if (m_useragent.empty()) {
-        m_useragent = m_useragent + PACKAGE_NAME + '/' + PACKAGE_VERSION;
+    if (getUserAgent() == nullptr) {
+        string useragent = string(PACKAGE_NAME) + '/' + PACKAGE_VERSION;
         curl_version_info_data* curlver = curl_version_info(CURLVERSION_NOW);
         if (curlver) {
-            m_useragent = m_useragent + " libcurl/" + curlver->version + ' ' + curlver->ssl_version;
+            useragent = useragent + " libcurl/" + curlver->version + ' ' + curlver->ssl_version;
         }
+        setUserAgent(useragent.c_str());
     }
 }
 
@@ -258,7 +244,7 @@ CURL* CurlHTTPRemotingService::checkout() const
 #else
     SHIB_CURL_SET(CURLOPT_ENCODING, "");
 #endif
-    SHIB_CURL_SET(CURLOPT_USERAGENT, m_useragent.c_str());
+    SHIB_CURL_SET(CURLOPT_USERAGENT, getUserAgent());
 
     // This may (but probably won't) help with < 7.20 bug in DNS caching.
     SHIB_CURL_SET(CURLOPT_DNS_CACHE_TIMEOUT, 120);
@@ -268,8 +254,8 @@ CURL* CurlHTTPRemotingService::checkout() const
     if (!m_ciphers.empty()) {
         SHIB_CURL_SET(CURLOPT_SSL_CIPHER_LIST, m_ciphers.c_str());
     }
-    if (!m_cafile.empty()) {
-        SHIB_CURL_SET(CURLOPT_CAINFO, m_cafile.c_str());
+    if (getCAFile()) {
+        SHIB_CURL_SET(CURLOPT_CAINFO, getCAFile());
     }
 
     SHIB_CURL_SET(CURLOPT_CONNECTTIMEOUT, getConnectTimeout());

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


More information about the commits mailing list