[cpp-sp] branch main updated: Session API tweaking.
Scott Cantor
cantor.2 at osu.edu
Thu May 29 17:39:12 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=440f382cb0b544b379b9892ef14dddf2094ecbf6
The following commit(s) were added to refs/heads/main by this push:
new 440f382c Session API tweaking.
440f382c is described below
commit 440f382cb0b544b379b9892ef14dddf2094ecbf6
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu May 29 13:38:53 2025 -0400
Session API tweaking.
---
shibsp/handler/impl/AdminLogoutInitiator.cpp | 9 ++--
shibsp/handler/impl/AttributeCheckerHandler.cpp | 7 ++-
shibsp/handler/impl/LocalLogoutInitiator.cpp | 3 +-
shibsp/session/AbstractSessionCache.h | 17 +++++--
shibsp/session/SessionCache.h | 67 ++-----------------------
shibsp/session/SessionCacheSPI.h | 14 +++---
shibsp/session/impl/AbstractSessionCache.cpp | 6 +--
shibsp/session/impl/FilesystemSessionCache.cpp | 2 -
8 files changed, 33 insertions(+), 92 deletions(-)
diff --git a/shibsp/handler/impl/AdminLogoutInitiator.cpp b/shibsp/handler/impl/AdminLogoutInitiator.cpp
index 83062326..9b9b1d03 100644
--- a/shibsp/handler/impl/AdminLogoutInitiator.cpp
+++ b/shibsp/handler/impl/AdminLogoutInitiator.cpp
@@ -96,21 +96,18 @@ pair<bool,long> AdminLogoutInitiator::run(SPRequest& request, bool isHandler) co
// With no session, we return a 404 after "revoking" the session just to be safe.
if (!session) {
- AgentConfig::getConfig().getAgent().getSessionCache()->remove(applicationId, sessionId);
+ AgentConfig::getConfig().getAgent().getSessionCache()->remove(sessionId);
istringstream msg("NOT FOUND");
return make_pair(true, request.sendResponse(msg, HTTPResponse::SHIBSP_HTTP_STATUS_NOTFOUND));
}
- time_t revocationExp = session.mutex()->getCreation() + request.getRequestSettings().first->getUnsignedInt("lifetime", 28800);
-
bool doSAML = false;
// Do back channel notification.
vector<string> sessions(1, session.mutex()->getID());
if (!notifyBackChannel(request, sessions, true)) {
session.unlock();
- AgentConfig::getConfig().getAgent().getSessionCache()->remove(
- request.getRequestSettings().first->getString("applicationId", "default"), sessionId, revocationExp);
+ AgentConfig::getConfig().getAgent().getSessionCache()->remove(sessionId);
istringstream msg("PARTIAL");
return make_pair(true, request.sendResponse(msg, 206)); // misuse of an HTTP code, but whatever
@@ -118,7 +115,7 @@ pair<bool,long> AdminLogoutInitiator::run(SPRequest& request, bool isHandler) co
if (!doSAML) {
session.unlock();
- AgentConfig::getConfig().getAgent().getSessionCache()->remove(applicationId, sessionId, revocationExp);
+ AgentConfig::getConfig().getAgent().getSessionCache()->remove(sessionId);
istringstream msg("OK");
return make_pair(true, request.sendResponse(msg, HTTPResponse::SHIBSP_HTTP_STATUS_OK));
diff --git a/shibsp/handler/impl/AttributeCheckerHandler.cpp b/shibsp/handler/impl/AttributeCheckerHandler.cpp
index b51dc514..41177d62 100644
--- a/shibsp/handler/impl/AttributeCheckerHandler.cpp
+++ b/shibsp/handler/impl/AttributeCheckerHandler.cpp
@@ -52,9 +52,9 @@ namespace shibsp {
pair<bool,long> run(SPRequest& request, bool isHandler=true) const;
private:
- void flushSession(SPRequest& request, time_t exp) const {
+ void flushSession(SPRequest& request) const {
try {
- request.getAgent().getSessionCache()->remove(request, exp);
+ request.getAgent().getSessionCache()->remove(request);
}
catch (const std::exception&) {
}
@@ -150,9 +150,8 @@ pair<bool,long> AttributeCheckerHandler::run(SPRequest& request, bool isHandler)
}
if (m_flushSession && session) {
- time_t revocationExp = session.mutex()->getCreation() + request.getRequestSettings().first->getUnsignedInt("lifetime", 28800);
session.unlock();
- flushSession(request, revocationExp);
+ flushSession(request);
}
return make_pair(true, request.sendRedirect(m_redirectOnFailure.c_str()));
diff --git a/shibsp/handler/impl/LocalLogoutInitiator.cpp b/shibsp/handler/impl/LocalLogoutInitiator.cpp
index f447e934..16e5b488 100644
--- a/shibsp/handler/impl/LocalLogoutInitiator.cpp
+++ b/shibsp/handler/impl/LocalLogoutInitiator.cpp
@@ -85,9 +85,8 @@ pair<bool,long> LocalLogoutInitiator::run(SPRequest& request, bool isHandler) co
bool result;
vector<string> sessions(1, session.mutex()->getID());
result = notifyBackChannel(request, sessions, true);
- time_t revocationExp = session.mutex()->getCreation() + request.getRequestSettings().first->getUnsignedInt("lifetime", 28800);
session.unlock();
- request.getAgent().getSessionCache()->remove(request, revocationExp);
+ request.getAgent().getSessionCache()->remove(request);
if (!result) {
//return sendLogoutPage(request, "partial");
}
diff --git a/shibsp/session/AbstractSessionCache.h b/shibsp/session/AbstractSessionCache.h
index b5b256c8..79354887 100644
--- a/shibsp/session/AbstractSessionCache.h
+++ b/shibsp/session/AbstractSessionCache.h
@@ -41,6 +41,11 @@ namespace shibsp {
class SHIBSP_API Attribute;
class SHIBSP_API CookieManager;
+#if defined (_MSC_VER)
+ #pragma warning( push )
+ #pragma warning( disable : 4251 )
+#endif
+
class SHIBSP_API BasicSession : public virtual Session
{
public:
@@ -73,7 +78,7 @@ namespace shibsp {
std::mutex m_lock;
};
- class SHIBSP_API AbstractSessionCache : public virtual SessionCache, public virtual SessionCacheSPI, public virtual BoostPropertySet {
+ class SHIBSP_API AbstractSessionCache : public virtual SessionCache, public SessionCacheSPI, public virtual BoostPropertySet {
public:
/**
* Starts background cleanup thread for in-memory hashtable of sessions.
@@ -89,9 +94,6 @@ namespace shibsp {
void remove(SPRequest& request, time_t revocationExp=0);
void remove(const char* applicationId, const char* key, time_t revocationExp=0);
- // SessionCacheSPI API;
- virtual std::string create(DDF& sessionData) = 0;
-
protected:
/**
* Constructor.
@@ -132,7 +134,12 @@ namespace shibsp {
std::thread m_cleanup_thread;
std::string m_issuerAttribute;
bool m_shutdown;
- };
+ };
+
+#if defined (_MSC_VER)
+ #pragma warning( pop )
+#endif
+
};
#endif /** __shibsp_abssessioncache_h__ */
\ No newline at end of file
diff --git a/shibsp/session/SessionCache.h b/shibsp/session/SessionCache.h
index 74362a68..c7cd1494 100644
--- a/shibsp/session/SessionCache.h
+++ b/shibsp/session/SessionCache.h
@@ -153,75 +153,16 @@ namespace shibsp {
/**
* Removes an existing session bound to a request.
*
- * <p>Revocation may be supported by some implementations.</p>
- *
- * @param request request from client containing session
- * @param revocationExp optional indicator for length of time to track revocation of this session
+ * @param request request from client containing session
*/
- virtual void remove(SPRequest& request, time_t revocationExp=0)=0;
+ virtual void remove(SPRequest& request)=0;
/**
* Removes an existing session identified by its application and ID.
*
- * <p>Revocation may be supported by some implementations.</p>
- *
- * @param bucketID application associated with session
- * @param key session key/ID
- * @param revocationExp optional indicator for length of time to track revocation of this session
- */
- virtual void remove(const char* applicationId, const char* key, time_t revocationExp=0)=0;
-
-#ifndef SHIBSP_LITE
- // TODO: legacy API to be removed, keeping for reference during rewrite...
-
- /**
- * Returns active sessions that match particular parameters and records the logout
- * to prevent race conditions.
- *
- * <p>On exit, the mapping between these sessions and the associated information MAY be
- * removed by the cache, so subsequent calls to this method may not return anything.
- *
- * <p>Until logout expiration, any attempt to create a session with the same parameters
- * will be blocked by the cache.
- *
- * @param bucketID bucket for session
- * @param issuer source of session(s)
- * @param nameid name identifier associated with the session(s) to terminate
- * @param indexes indexes of sessions, or nullptr for all sessions associated with other parameters
- * @param expires logout expiration
- * @param sessions on exit, contains the IDs of the matching sessions found
- */
- virtual std::vector<std::string>::size_type logout(
- const char* bucketID,
- const opensaml::saml2md::EntityDescriptor* issuer,
- const opensaml::saml2::NameID& nameid,
- const std::set<std::string>* indexes,
- time_t expires,
- std::vector<std::string>& sessions
- )=0;
-
- /**
- * Executes a test of the cache's general health.
- */
- virtual void test()=0;
-
- /**
- * Returns the ID of the session bound to the specified client request, if possible.
- *
- * @param request request from client containing session
- * @return ID of session, if any known, or an empty string
- */
- virtual std::string active(const SPRequest& request)=0;
-
- /**
- * Locates an existing session by ID.
- *
- * @param bucketID bucket for session
- * @param key session key
- * @return pointer to locked Session, or nullptr
+ * @param key session key/ID
*/
- virtual Session* find(const char* bucketID, const char* key)=0;
-#endif
+ virtual void remove(const char* key)=0;
};
/** SessionCache implementation backed by the file system. */
diff --git a/shibsp/session/SessionCacheSPI.h b/shibsp/session/SessionCacheSPI.h
index 77a5ac21..07f33905 100644
--- a/shibsp/session/SessionCacheSPI.h
+++ b/shibsp/session/SessionCacheSPI.h
@@ -51,7 +51,7 @@ namespace shibsp {
*
* @return session key/ID created, this MUST be URL-safe
*/
- virtual std::string create(DDF& sessionData)=0;
+ virtual std::string cache_create(DDF& sessionData)=0;
/**
* Read a session record from the underlying storage medium and return its data.
@@ -61,9 +61,9 @@ namespace shibsp {
* to the caller.</p>
*
* <p>To the extent possible, the implementation SHOULD ensure that the underlying
- * storage of the session (if returned) reflects its use as of the time of this call
- * such that subsequent calls to this method will be actioned based on a time of last
- * use that is no older than the current time.</p>
+ * storage of the session (if returned) is updated such that subsequent calls to this
+ * method will be actioned based on a time of last use that is no older than the current
+ * time.</p>
*
* <p>The caller owns the resulting data object.</p>
*
@@ -75,7 +75,7 @@ namespace shibsp {
*
* @return reconstituted session data or a null object if the session was absent or invalid
*/
- virtual DDF read(
+ virtual DDF cache_read(
const char* applicationId,
const char* key,
unsigned int lifetime=0,
@@ -90,14 +90,14 @@ namespace shibsp {
*
* @return true iff the storage medium believes the information has been updated
*/
- virtual bool touch(const char* key) const=0;
+ virtual bool cache_touch(const char* key) const=0;
/**
* Delete a session record from the underlying storage medium.
*
* @param key/ID of session to delete
*/
- virtual void remove(const char* key)=0;
+ virtual void cache_remove(const char* key)=0;
};
};
diff --git a/shibsp/session/impl/AbstractSessionCache.cpp b/shibsp/session/impl/AbstractSessionCache.cpp
index b4653ba4..6b29c465 100644
--- a/shibsp/session/impl/AbstractSessionCache.cpp
+++ b/shibsp/session/impl/AbstractSessionCache.cpp
@@ -150,7 +150,7 @@ string AbstractSessionCache::create(SPRequest& request, DDF& session)
string key;
try {
m_log.debug("writing new session to persistent store");
- key = SessionCacheSPI::create(session);
+ key = cache_create(session);
}
catch (const IOException& ex) {
m_log.error("IOException writing new session to persistent store: %s", ex.what());
@@ -263,7 +263,7 @@ unique_lock<Session> AbstractSessionCache::_find(
DDF obj;
try {
// Note this performs the relevant enforcement for us.
- obj = read(applicationId, key, lifetime, timeout, client_addr);
+ obj = cache_read(applicationId, key, lifetime, timeout, client_addr);
}
catch (const exception& ex) {
m_log.error("error reading session (%s) from persistent store: %s", key, ex.what());
@@ -297,7 +297,7 @@ unique_lock<Session> AbstractSessionCache::_find(
// new copy yet, but the old copy might be locked by somebody. However, once we acquire
// a lock on the old Session, we know nobody else is waiting for that lock because they
// would have to be inside the cache critical section to get to it.
- // This, this sequence transfers ownership out of the table, removes the entry, then
+ // Thus, this sequence transfers ownership out of the table, removes the entry, then
// locks, unlocks, and finally deletes the old session object.
m_log.debug("session (%s) already inserted by another thread, replacing with our copy", key);
unique_ptr<BasicSession> oldSession;
diff --git a/shibsp/session/impl/FilesystemSessionCache.cpp b/shibsp/session/impl/FilesystemSessionCache.cpp
index ef4488e8..259653e2 100644
--- a/shibsp/session/impl/FilesystemSessionCache.cpp
+++ b/shibsp/session/impl/FilesystemSessionCache.cpp
@@ -55,8 +55,6 @@ SessionCacheSPI::~SessionCacheSPI()
{
}
-std::string SessionCacheSPI::create(DDF& sessionData) { return std::string(""); }
-
FilesystemSessionCache::FilesystemSessionCache(const ptree& pt) : AbstractSessionCache(pt)
{
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list