2 * Copyright 2001-2010 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * StorageServiceSessionCache.cpp
20 * StorageService-based SessionCache implementation.
22 * Instead of optimizing this plugin with a buffering scheme that keeps objects around
23 * and avoids extra parsing steps, I'm assuming that systems that require such can
24 * layer their own cache plugin on top of this version either by delegating to it
25 * or using the remoting support. So this version will load sessions directly
26 * from the StorageService, instantiate enough to expose the Session API,
27 * and then delete everything when they're unlocked. All data in memory is always
28 * kept in sync with the StorageService (no lazy updates).
32 #include "Application.h"
33 #include "exceptions.h"
34 #include "ServiceProvider.h"
35 #include "SessionCacheEx.h"
36 #include "TransactionLog.h"
37 #include "attribute/Attribute.h"
38 #include "remoting/ListenerService.h"
39 #include "util/SPConstants.h"
42 #include <xmltooling/io/HTTPRequest.h>
43 #include <xmltooling/io/HTTPResponse.h>
44 #include <xmltooling/util/DateTime.h>
45 #include <xmltooling/util/NDC.h>
46 #include <xmltooling/util/ParserPool.h>
47 #include <xmltooling/util/Threads.h>
48 #include <xmltooling/util/XMLHelper.h>
49 #include <xercesc/util/XMLUniDefs.hpp>
52 # include <saml/exceptions.h>
53 # include <saml/SAMLConfig.h>
54 # include <saml/saml2/core/Assertions.h>
55 # include <saml/saml2/metadata/Metadata.h>
56 # include <xmltooling/XMLToolingConfig.h>
57 # include <xmltooling/util/StorageService.h>
58 using namespace opensaml::saml2md;
61 # include <xmltooling/util/DateTime.h>
64 using namespace shibsp;
65 using namespace opensaml;
66 using namespace xmltooling;
72 class SSCache : public SessionCacheEx
74 ,public virtual Remoted
78 SSCache(const DOMElement* e);
82 void receive(DDF& in, ostream& out);
85 const Application& application,
86 const HTTPRequest& httpRequest,
87 HTTPResponse& httpResponse,
89 const saml2md::EntityDescriptor* issuer=nullptr,
90 const XMLCh* protocol=nullptr,
91 const saml2::NameID* nameid=nullptr,
92 const XMLCh* authn_instant=nullptr,
93 const XMLCh* session_index=nullptr,
94 const XMLCh* authncontext_class=nullptr,
95 const XMLCh* authncontext_decl=nullptr,
96 const vector<const Assertion*>* tokens=nullptr,
97 const vector<Attribute*>* attributes=nullptr
99 vector<string>::size_type logout(
100 const Application& application,
101 const saml2md::EntityDescriptor* issuer,
102 const saml2::NameID& nameid,
103 const set<string>* indexes,
105 vector<string>& sessions
108 const Application& application,
109 const xmltooling::HTTPRequest& request,
110 const saml2md::EntityDescriptor* issuer,
111 const saml2::NameID& nameid,
112 const set<string>* indexes
115 Session* find(const Application& application, const char* key, const char* client_addr=nullptr, time_t* timeout=nullptr);
116 void remove(const Application& application, const char* key);
119 string active(const Application& application, const xmltooling::HTTPRequest& request) {
120 pair<string,const char*> shib_cookie = application.getCookieNameProps("_shibsession_");
121 const char* session_id = request.getCookie(shib_cookie.first.c_str());
122 return (session_id ? session_id : "");
125 Session* find(const Application& application, const HTTPRequest& request, const char* client_addr=nullptr, time_t* timeout=nullptr) {
126 string id = active(application, request);
128 return find(application, id.c_str(), client_addr, timeout);
132 Session* find(const Application& application, HTTPRequest& request, const char* client_addr=nullptr, time_t* timeout=nullptr) {
133 string id = active(application, request);
137 Session* session = find(application, id.c_str(), client_addr, timeout);
140 HTTPResponse* response = dynamic_cast<HTTPResponse*>(&request);
142 pair<string,const char*> shib_cookie = application.getCookieNameProps("_shibsession_");
143 string exp(shib_cookie.second);
144 exp += "; expires=Mon, 01 Jan 2001 00:00:00 GMT";
145 response->setCookie(shib_cookie.first.c_str(), exp.c_str());
149 HTTPResponse* response = dynamic_cast<HTTPResponse*>(&request);
151 pair<string,const char*> shib_cookie = application.getCookieNameProps("_shibsession_");
152 string exp(shib_cookie.second);
153 exp += "; expires=Mon, 01 Jan 2001 00:00:00 GMT";
154 response->setCookie(shib_cookie.first.c_str(), exp.c_str());
161 void remove(const Application& application, const HTTPRequest& request, HTTPResponse* response=nullptr) {
162 pair<string,const char*> shib_cookie = application.getCookieNameProps("_shibsession_");
163 const char* session_id = request.getCookie(shib_cookie.first.c_str());
164 if (session_id && *session_id) {
166 string exp(shib_cookie.second);
167 exp += "; expires=Mon, 01 Jan 2001 00:00:00 GMT";
168 response->setCookie(shib_cookie.first.c_str(), exp.c_str());
170 remove(application, session_id);
176 unsigned long m_cacheTimeout;
178 StorageService* m_storage;
179 StorageService* m_storage_lite;
184 // maintain back-mappings of NameID/SessionIndex -> session key
185 void insert(const char* key, time_t expires, const char* name, const char* index);
186 bool stronglyMatches(const XMLCh* idp, const XMLCh* sp, const saml2::NameID& n1, const saml2::NameID& n2) const;
188 bool m_cacheAssertions;
190 const DOMElement* m_root; // Only valid during initialization
191 unsigned long m_inprocTimeout;
193 // inproc means we buffer sessions in memory
195 map<string,StoredSession*> m_hashtable;
197 // management of buffered sessions
198 void dormant(const char* key);
199 static void* cleanup_fn(void*);
202 CondWait* shutdown_wait;
203 Thread* cleanup_thread;
206 class StoredSession : public virtual Session
209 StoredSession(SSCache* cache, DDF& obj) : m_obj(obj),
213 m_cache(cache), m_expires(0), m_lastAccess(time(nullptr)), m_lock(nullptr) {
214 auto_ptr_XMLCh exp(m_obj["expires"].string());
216 DateTime iso(exp.get());
218 m_expires = iso.getEpoch();
222 const char* nameid = obj["nameid"].string();
224 // Parse and bind the document into an XMLObject.
225 istringstream instr(nameid);
226 DOMDocument* doc = XMLToolingConfig::getConfig().getParser().parse(instr);
227 XercesJanitor<DOMDocument> janitor(doc);
228 auto_ptr<saml2::NameID> n(saml2::NameIDBuilder::buildNameID());
229 n->unmarshall(doc->getDocumentElement(), true);
231 m_nameid = n.release();
235 m_lock = Mutex::create();
241 for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());
244 for_each(m_tokens.begin(), m_tokens.end(), cleanup_pair<string,Assertion>());
260 const char* getID() const {
263 const char* getApplicationID() const {
264 return m_obj["application_id"].string();
266 const char* getClientAddress() const {
267 return m_obj["client_addr"].string();
269 const char* getEntityID() const {
270 return m_obj["entity_id"].string();
272 const char* getProtocol() const {
273 return m_obj["protocol"].string();
275 const char* getAuthnInstant() const {
276 return m_obj["authn_instant"].string();
279 const saml2::NameID* getNameID() const {
283 const char* getSessionIndex() const {
284 return m_obj["session_index"].string();
286 const char* getAuthnContextClassRef() const {
287 return m_obj["authncontext_class"].string();
289 const char* getAuthnContextDeclRef() const {
290 return m_obj["authncontext_decl"].string();
292 const vector<Attribute*>& getAttributes() const {
293 if (m_attributes.empty())
294 unmarshallAttributes();
297 const multimap<string,const Attribute*>& getIndexedAttributes() const {
298 if (m_attributeIndex.empty()) {
299 if (m_attributes.empty())
300 unmarshallAttributes();
301 for (vector<Attribute*>::const_iterator a = m_attributes.begin(); a != m_attributes.end(); ++a) {
302 const vector<string>& aliases = (*a)->getAliases();
303 for (vector<string>::const_iterator alias = aliases.begin(); alias != aliases.end(); ++alias)
304 m_attributeIndex.insert(multimap<string,const Attribute*>::value_type(*alias, *a));
307 return m_attributeIndex;
309 const vector<const char*>& getAssertionIDs() const {
311 DDF ids = m_obj["assertions"];
312 DDF id = ids.first();
313 while (id.isstring()) {
314 m_ids.push_back(id.string());
321 void validate(const Application& application, const char* client_addr, time_t* timeout);
324 void addAttributes(const vector<Attribute*>& attributes);
325 const Assertion* getAssertion(const char* id) const;
326 void addAssertion(Assertion* assertion);
329 time_t getExpiration() const { return m_expires; }
330 time_t getLastAccess() const { return m_lastAccess; }
333 void unmarshallAttributes() const;
337 saml2::NameID* m_nameid;
338 mutable map<string,Assertion*> m_tokens;
340 mutable vector<Attribute*> m_attributes;
341 mutable multimap<string,const Attribute*> m_attributeIndex;
342 mutable vector<const char*> m_ids;
345 time_t m_expires,m_lastAccess;
349 SessionCache* SHIBSP_DLLLOCAL StorageServiceCacheFactory(const DOMElement* const & e)
351 return new SSCache(e);
355 Session* SessionCache::find(const Application& application, HTTPRequest& request, const char* client_addr, time_t* timeout)
357 return find(application, const_cast<const HTTPRequest&>(request), client_addr, timeout);
360 void SHIBSP_API shibsp::registerSessionCaches()
362 SPConfig::getConfig().SessionCacheManager.registerFactory(STORAGESERVICE_SESSION_CACHE, StorageServiceCacheFactory);
373 void StoredSession::unmarshallAttributes() const
375 Attribute* attribute;
376 DDF attrs = m_obj["attributes"];
377 DDF attr = attrs.first();
378 while (!attr.isnull()) {
380 attribute = Attribute::unmarshall(attr);
381 m_attributes.push_back(attribute);
382 if (m_cache->m_log.isDebugEnabled())
383 m_cache->m_log.debug("unmarshalled attribute (ID: %s) with %d value%s",
384 attribute->getId(), attr.first().integer(), attr.first().integer()!=1 ? "s" : "");
386 catch (AttributeException& ex) {
387 const char* id = attr.first().name();
388 m_cache->m_log.error("error unmarshalling attribute (ID: %s): %s", id ? id : "none", ex.what());
394 void StoredSession::validate(const Application& application, const char* client_addr, time_t* timeout)
396 time_t now = time(nullptr);
400 if (now > m_expires) {
401 m_cache->m_log.info("session expired (ID: %s)", getID());
402 throw RetryableProfileException("Your session has expired, and you must re-authenticate.");
408 if (m_cache->m_log.isDebugEnabled())
409 m_cache->m_log.debug("comparing client address %s against %s", client_addr, getClientAddress());
410 if (!XMLString::equals(getClientAddress(),client_addr)) {
411 m_cache->m_log.warn("client address mismatch");
412 throw RetryableProfileException(
413 "Your IP address ($1) does not match the address recorded at the time the session was established.",
414 params(1,client_addr)
422 if (!SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess)) {
423 DDF in("touch::"STORAGESERVICE_SESSION_CACHE"::SessionCache"), out;
426 in.addmember("key").string(getID());
427 in.addmember("version").integer(m_obj["version"].integer());
429 // On 64-bit Windows, time_t doesn't fit in a long, so I'm using ISO timestamps.
430 #ifndef HAVE_GMTIME_R
431 struct tm* ptime=gmtime(timeout);
434 struct tm* ptime=gmtime_r(timeout,&res);
437 strftime(timebuf,32,"%Y-%m-%dT%H:%M:%SZ",ptime);
438 in.addmember("timeout").string(timebuf);
442 out=application.getServiceProvider().getListenerService()->send(in);
449 if (out.isstruct()) {
450 // We got an updated record back.
452 for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());
453 m_attributes.clear();
454 m_attributeIndex.clear();
461 if (!m_cache->m_storage)
462 throw ConfigurationException("Session touch requires a StorageService.");
464 // Do a versioned read.
467 int curver = m_obj["version"].integer();
468 int ver = m_cache->m_storage->readText(getID(), "session", &record, &lastAccess, curver);
470 m_cache->m_log.warn("unsuccessful versioned read of session (ID: %s), cache out of sync?", getID());
471 throw RetryableProfileException("Your session has expired, and you must re-authenticate.");
474 // Adjust for expiration to recover last access time and check timeout.
475 lastAccess -= m_cache->m_cacheTimeout;
476 if (*timeout > 0 && now - lastAccess >= *timeout) {
477 m_cache->m_log.info("session timed out (ID: %s)", getID());
478 throw RetryableProfileException("Your session has expired, and you must re-authenticate.");
481 // Update storage expiration, if possible.
483 m_cache->m_storage->updateContext(getID(), now + m_cache->m_cacheTimeout);
485 catch (exception& ex) {
486 m_cache->m_log.error("failed to update session expiration: %s", ex.what());
490 // We got an updated record back.
492 istringstream in(record);
495 for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());
496 m_attributes.clear();
497 m_attributeIndex.clear();
502 throw ConfigurationException("Session touch requires a StorageService.");
511 void StoredSession::addAttributes(const vector<Attribute*>& attributes)
514 xmltooling::NDC ndc("addAttributes");
517 if (!m_cache->m_storage)
518 throw ConfigurationException("Session modification requires a StorageService.");
520 m_cache->m_log.debug("adding attributes to session (%s)", getID());
525 DDF attrs = m_obj["attributes"];
527 attrs = m_obj.addmember("attributes").list();
528 for (vector<Attribute*>::const_iterator a=attributes.begin(); a!=attributes.end(); ++a) {
529 attr = (*a)->marshall();
533 // Tentatively increment the version.
534 m_obj["version"].integer(m_obj["version"].integer()+1);
538 string record(str.str());
541 ver = m_cache->m_storage->updateText(getID(), "session", record.c_str(), 0, m_obj["version"].integer()-1);
544 // Roll back modification to record.
545 m_obj["version"].integer(m_obj["version"].integer()-1);
546 vector<Attribute*>::size_type count = attributes.size();
548 attrs.last().destroy();
553 // Roll back modification to record.
554 m_obj["version"].integer(m_obj["version"].integer()-1);
555 vector<Attribute*>::size_type count = attributes.size();
557 attrs.last().destroy();
560 // Fatal problem with update.
561 throw IOException("Unable to update stored session.");
565 m_cache->m_log.warn("storage service indicates the record is out of sync, updating with a fresh copy...");
566 ver = m_cache->m_storage->readText(getID(), "session", &record, nullptr);
568 m_cache->m_log.error("readText failed on StorageService for session (%s)", getID());
569 throw IOException("Unable to read back stored session.");
574 istringstream in(record);
578 for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());
579 m_attributes.clear();
580 m_attributeIndex.clear();
581 newobj["version"].integer(ver);
587 } while (ver < 0); // negative indicates a sync issue so we retry
589 TransactionLog* xlog = SPConfig::getConfig().getServiceProvider()->getTransactionLog();
591 xlog->log.infoStream() <<
592 "Added the following attributes to session (ID: " <<
594 ") for (applicationId: " <<
595 m_obj["application_id"].string() <<
597 for (vector<Attribute*>::const_iterator a=attributes.begin(); a!=attributes.end(); ++a)
598 xlog->log.infoStream() << "\t" << (*a)->getId() << " (" << (*a)->valueCount() << " values)";
601 // We own them now, so clean them up.
602 for_each(attributes.begin(), attributes.end(), xmltooling::cleanup<Attribute>());
605 const Assertion* StoredSession::getAssertion(const char* id) const
607 if (!m_cache->m_storage)
608 throw ConfigurationException("Assertion retrieval requires a StorageService.");
610 map<string,Assertion*>::const_iterator i = m_tokens.find(id);
611 if (i!=m_tokens.end())
615 if (!m_cache->m_storage->readText(getID(), id, &tokenstr, nullptr))
616 throw FatalProfileException("Assertion not found in cache.");
618 // Parse and bind the document into an XMLObject.
619 istringstream instr(tokenstr);
620 DOMDocument* doc = XMLToolingConfig::getConfig().getParser().parse(instr);
621 XercesJanitor<DOMDocument> janitor(doc);
622 auto_ptr<XMLObject> xmlObject(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(), true));
625 Assertion* token = dynamic_cast<Assertion*>(xmlObject.get());
627 throw FatalProfileException("Request for cached assertion returned an unknown object type.");
629 // Transfer ownership to us.
635 void StoredSession::addAssertion(Assertion* assertion)
638 xmltooling::NDC ndc("addAssertion");
641 if (!m_cache->m_storage)
642 throw ConfigurationException("Session modification requires a StorageService.");
645 throw FatalProfileException("Unknown object type passed to session for storage.");
647 auto_ptr_char id(assertion->getID());
649 m_cache->m_log.debug("adding assertion (%s) to session (%s)", id.get(), getID());
652 if (!m_cache->m_storage->readText(getID(), "session", nullptr, &exp))
653 throw IOException("Unable to load expiration time for stored session.");
655 ostringstream tokenstr;
656 tokenstr << *assertion;
657 if (!m_cache->m_storage->createText(getID(), id.get(), tokenstr.str().c_str(), exp))
658 throw IOException("Attempted to insert duplicate assertion ID into session.");
662 DDF token = DDF(nullptr).string(id.get());
663 m_obj["assertions"].add(token);
665 // Tentatively increment the version.
666 m_obj["version"].integer(m_obj["version"].integer()+1);
670 string record(str.str());
673 ver = m_cache->m_storage->updateText(getID(), "session", record.c_str(), 0, m_obj["version"].integer()-1);
677 m_obj["version"].integer(m_obj["version"].integer()-1);
678 m_cache->m_storage->deleteText(getID(), id.get());
684 m_obj["version"].integer(m_obj["version"].integer()-1);
687 // Fatal problem with update.
688 m_cache->m_log.error("updateText failed on StorageService for session (%s)", getID());
689 m_cache->m_storage->deleteText(getID(), id.get());
690 throw IOException("Unable to update stored session.");
694 m_cache->m_log.warn("storage service indicates the record is out of sync, updating with a fresh copy...");
695 ver = m_cache->m_storage->readText(getID(), "session", &record, nullptr);
697 m_cache->m_log.error("readText failed on StorageService for session (%s)", getID());
698 m_cache->m_storage->deleteText(getID(), id.get());
699 throw IOException("Unable to read back stored session.");
704 istringstream in(record);
708 for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());
709 m_attributes.clear();
710 m_attributeIndex.clear();
711 newobj["version"].integer(ver);
717 } while (ver < 0); // negative indicates a sync issue so we retry
722 TransactionLog* xlog = SPConfig::getConfig().getServiceProvider()->getTransactionLog();
725 "Added assertion (ID: %s) to session for (applicationId: %s) with (ID: %s)",
726 id.get(), m_obj["application_id"].string(), getID()
732 SessionCache::SessionCache()
736 SessionCache::~SessionCache()
740 SessionCacheEx::SessionCacheEx()
744 SessionCacheEx::~SessionCacheEx()
748 SSCache::SSCache(const DOMElement* e)
749 : m_log(Category::getInstance(SHIBSP_LOGCAT".SessionCache")), inproc(true), m_cacheTimeout(28800),
751 m_storage(nullptr), m_storage_lite(nullptr), m_cacheAssertions(true),
753 m_root(e), m_inprocTimeout(900), m_lock(nullptr), shutdown(false), shutdown_wait(nullptr), cleanup_thread(nullptr)
755 SPConfig& conf = SPConfig::getConfig();
756 inproc = conf.isEnabled(SPConfig::InProcess);
758 static const XMLCh cacheAssertions[] = UNICODE_LITERAL_15(c,a,c,h,e,A,s,s,e,r,t,i,o,n,s);
759 static const XMLCh cacheTimeout[] = UNICODE_LITERAL_12(c,a,c,h,e,T,i,m,e,o,u,t);
760 static const XMLCh inprocTimeout[] = UNICODE_LITERAL_13(i,n,p,r,o,c,T,i,m,e,o,u,t);
761 static const XMLCh _StorageService[] = UNICODE_LITERAL_14(S,t,o,r,a,g,e,S,e,r,v,i,c,e);
762 static const XMLCh _StorageServiceLite[] = UNICODE_LITERAL_18(S,t,o,r,a,g,e,S,e,r,v,i,c,e,L,i,t,e);
764 m_cacheTimeout = XMLHelper::getAttrInt(e, 28800, cacheTimeout);
766 m_inprocTimeout = XMLHelper::getAttrInt(e, 900, inprocTimeout);
769 if (conf.isEnabled(SPConfig::OutOfProcess)) {
770 string ssid(XMLHelper::getAttrString(e, nullptr, _StorageService));
772 m_storage = conf.getServiceProvider()->getStorageService(ssid.c_str());
774 m_log.info("bound to StorageService (%s)", ssid.c_str());
776 m_log.warn("specified StorageService (%s) not found", ssid.c_str());
779 m_storage = conf.getServiceProvider()->getStorageService(nullptr);
781 m_log.info("bound to arbitrary StorageService");
783 throw ConfigurationException("SessionCache unable to locate StorageService, check configuration.");
786 ssid = XMLHelper::getAttrString(e, nullptr, _StorageServiceLite);
788 m_storage_lite = conf.getServiceProvider()->getStorageService(ssid.c_str());
790 m_log.info("bound to 'lite' StorageService (%s)", ssid.c_str());
792 m_log.warn("specified 'lite' StorageService (%s) not found", ssid.c_str());
794 if (!m_storage_lite) {
795 m_log.info("StorageService for 'lite' use not set, using standard StorageService");
796 m_storage_lite = m_storage;
799 m_cacheAssertions = XMLHelper::getAttrBool(e, true, cacheAssertions);
803 ListenerService* listener=conf.getServiceProvider()->getListenerService(false);
805 if (!conf.isEnabled(SPConfig::OutOfProcess) && !listener)
806 throw ConfigurationException("SessionCache requires a ListenerService, but none available.");
807 m_lock = RWLock::create();
808 shutdown_wait = CondWait::create();
809 cleanup_thread = Thread::create(&cleanup_fn, this);
813 if (listener && conf.isEnabled(SPConfig::OutOfProcess)) {
814 listener->regListener("find::"STORAGESERVICE_SESSION_CACHE"::SessionCache",this);
815 listener->regListener("remove::"STORAGESERVICE_SESSION_CACHE"::SessionCache",this);
816 listener->regListener("touch::"STORAGESERVICE_SESSION_CACHE"::SessionCache",this);
819 m_log.info("no ListenerService available, cache remoting disabled");
828 // Shut down the cleanup thread and let it know...
830 shutdown_wait->signal();
831 cleanup_thread->join(nullptr);
833 for_each(m_hashtable.begin(),m_hashtable.end(),cleanup_pair<string,StoredSession>());
836 delete cleanup_thread;
837 delete shutdown_wait;
841 SPConfig& conf = SPConfig::getConfig();
842 ListenerService* listener=conf.getServiceProvider()->getListenerService(false);
843 if (listener && conf.isEnabled(SPConfig::OutOfProcess)) {
844 listener->unregListener("find::"STORAGESERVICE_SESSION_CACHE"::SessionCache",this);
845 listener->unregListener("remove::"STORAGESERVICE_SESSION_CACHE"::SessionCache",this);
846 listener->unregListener("touch::"STORAGESERVICE_SESSION_CACHE"::SessionCache",this);
856 auto_ptr_char temp(SAMLConfig::getConfig().generateIdentifier());
857 m_storage->createString("SessionCacheTest", temp.get(), "Test", time(nullptr) + 60);
858 m_storage->deleteString("SessionCacheTest", temp.get());
861 void SSCache::insert(const char* key, time_t expires, const char* name, const char* index)
864 if (strlen(name) > 255) {
865 dup = string(name).substr(0,255);
870 DDFJanitor jobj(obj);
872 // Since we can't guarantee uniqueness, check for an existing record.
875 int ver = m_storage_lite->readText("NameID", name, &record, &recordexp);
877 // Existing record, so we need to unmarshall it.
878 istringstream in(record);
883 obj = DDF(nullptr).structure();
886 if (!index || !*index)
888 DDF sessions = obj.addmember(index);
889 if (!sessions.islist())
891 DDF session = DDF(nullptr).string(key);
892 sessions.add(session);
894 // Remarshall the record.
898 // Try and store it back...
900 ver = m_storage_lite->updateText("NameID", name, out.str().c_str(), max(expires, recordexp), ver);
902 // Out of sync, or went missing, so retry.
903 return insert(key, expires, name, index);
906 else if (!m_storage_lite->createText("NameID", name, out.str().c_str(), expires)) {
907 // Hit a dup, so just retry, hopefully hitting the other branch.
908 return insert(key, expires, name, index);
912 void SSCache::insert(
913 const Application& application,
914 const HTTPRequest& httpRequest,
915 HTTPResponse& httpResponse,
917 const saml2md::EntityDescriptor* issuer,
918 const XMLCh* protocol,
919 const saml2::NameID* nameid,
920 const XMLCh* authn_instant,
921 const XMLCh* session_index,
922 const XMLCh* authncontext_class,
923 const XMLCh* authncontext_decl,
924 const vector<const Assertion*>* tokens,
925 const vector<Attribute*>* attributes
929 xmltooling::NDC ndc("insert");
932 throw ConfigurationException("SessionCache insertion requires a StorageService.");
934 m_log.debug("creating new session");
936 time_t now = time(nullptr);
937 auto_ptr_char index(session_index);
938 auto_ptr_char entity_id(issuer ? issuer->getEntityID() : nullptr);
939 auto_ptr_char name(nameid ? nameid->getName() : nullptr);
942 // Check for a pending logout.
943 if (strlen(name.get()) > 255)
944 const_cast<char*>(name.get())[255] = 0;
946 int ver = m_storage_lite->readText("Logout", name.get(), &pending);
949 DDFJanitor jpend(pendobj);
950 istringstream pstr(pending);
952 // IdP.SP.index contains logout expiration, if any.
953 DDF deadmenwalking = pendobj[issuer ? entity_id.get() : "_shibnull"][application.getRelyingParty(issuer)->getString("entityID").second];
954 const char* logexpstr = deadmenwalking[session_index ? index.get() : "_shibnull"].string();
955 if (!logexpstr && session_index) // we tried an exact session match, now try for nullptr
956 logexpstr = deadmenwalking["_shibnull"].string();
958 auto_ptr_XMLCh dt(logexpstr);
959 DateTime dtobj(dt.get());
960 dtobj.parseDateTime();
961 time_t logexp = dtobj.getEpoch();
962 if (now - XMLToolingConfig::getConfig().clock_skew_secs < logexp)
963 throw FatalProfileException("A logout message from your identity provider has blocked your login attempt.");
968 auto_ptr_char key(SAMLConfig::getConfig().generateIdentifier());
970 // Store session properties in DDF.
971 DDF obj = DDF(key.get()).structure();
972 DDFJanitor entryobj(obj);
973 obj.addmember("version").integer(1);
974 obj.addmember("application_id").string(application.getId());
976 // On 64-bit Windows, time_t doesn't fit in a long, so I'm using ISO timestamps.
977 #ifndef HAVE_GMTIME_R
978 struct tm* ptime=gmtime(&expires);
981 struct tm* ptime=gmtime_r(&expires,&res);
984 strftime(timebuf,32,"%Y-%m-%dT%H:%M:%SZ",ptime);
985 obj.addmember("expires").string(timebuf);
987 obj.addmember("client_addr").string(httpRequest.getRemoteAddr().c_str());
989 obj.addmember("entity_id").string(entity_id.get());
991 auto_ptr_char prot(protocol);
992 obj.addmember("protocol").string(prot.get());
995 auto_ptr_char instant(authn_instant);
996 obj.addmember("authn_instant").string(instant.get());
999 obj.addmember("session_index").string(index.get());
1000 if (authncontext_class) {
1001 auto_ptr_char ac(authncontext_class);
1002 obj.addmember("authncontext_class").string(ac.get());
1004 if (authncontext_decl) {
1005 auto_ptr_char ad(authncontext_decl);
1006 obj.addmember("authncontext_decl").string(ad.get());
1010 ostringstream namestr;
1012 obj.addmember("nameid").string(namestr.str().c_str());
1015 if (tokens && m_cacheAssertions) {
1016 obj.addmember("assertions").list();
1017 for (vector<const Assertion*>::const_iterator t = tokens->begin(); t!=tokens->end(); ++t) {
1018 auto_ptr_char tokenid((*t)->getID());
1019 DDF tokid = DDF(nullptr).string(tokenid.get());
1020 obj["assertions"].add(tokid);
1026 DDF attrlist = obj.addmember("attributes").list();
1027 for (vector<Attribute*>::const_iterator a=attributes->begin(); a!=attributes->end(); ++a) {
1028 attr = (*a)->marshall();
1033 ostringstream record;
1036 m_log.debug("storing new session...");
1037 if (!m_storage->createText(key.get(), "session", record.str().c_str(), now + m_cacheTimeout))
1038 throw FatalProfileException("Attempted to create a session with a duplicate key.");
1040 // Store the reverse mapping for logout.
1043 insert(key.get(), expires, name.get(), index.get());
1045 catch (exception& ex) {
1046 m_log.error("error storing back mapping of NameID for logout: %s", ex.what());
1049 if (tokens && m_cacheAssertions) {
1051 for (vector<const Assertion*>::const_iterator t = tokens->begin(); t!=tokens->end(); ++t) {
1052 ostringstream tokenstr;
1054 auto_ptr_char tokenid((*t)->getID());
1055 if (!m_storage->createText(key.get(), tokenid.get(), tokenstr.str().c_str(), now + m_cacheTimeout))
1056 throw IOException("duplicate assertion ID ($1)", params(1, tokenid.get()));
1059 catch (exception& ex) {
1060 m_log.error("error storing assertion along with session: %s", ex.what());
1064 const char* pid = obj["entity_id"].string();
1065 const char* prot = obj["protocol"].string();
1066 m_log.info("new session created: ID (%s) IdP (%s) Protocol(%s) Address (%s)",
1067 key.get(), pid ? pid : "none", prot ? prot : "none", httpRequest.getRemoteAddr().c_str());
1069 // Transaction Logging
1070 string primaryAssertionID("none");
1071 if (m_cacheAssertions) {
1073 primaryAssertionID = obj["assertions"].first().string();
1076 auto_ptr_char tokenid(tokens->front()->getID());
1077 primaryAssertionID = tokenid.get();
1079 TransactionLog* xlog = application.getServiceProvider().getTransactionLog();
1080 Locker locker(xlog);
1081 xlog->log.infoStream() <<
1082 "New session (ID: " <<
1084 ") with (applicationId: " <<
1085 application.getId() <<
1086 ") for principal from (IdP: " <<
1087 (pid ? pid : "none") <<
1088 ") at (ClientAddress: " <<
1089 httpRequest.getRemoteAddr() <<
1090 ") with (NameIdentifier: " <<
1091 (nameid ? name.get() : "none") <<
1092 ") using (Protocol: " <<
1093 (prot ? prot : "none") <<
1094 ") from (AssertionID: " <<
1095 primaryAssertionID <<
1099 xlog->log.infoStream() <<
1100 "Cached the following attributes with session (ID: " <<
1102 ") for (applicationId: " <<
1103 application.getId() <<
1105 for (vector<Attribute*>::const_iterator a=attributes->begin(); a!=attributes->end(); ++a)
1106 xlog->log.infoStream() << "\t" << (*a)->getId() << " (" << (*a)->valueCount() << " values)";
1107 xlog->log.info("}");
1110 time_t cookieLifetime = 0;
1111 pair<string,const char*> shib_cookie = application.getCookieNameProps("_shibsession_", &cookieLifetime);
1112 string k(key.get());
1113 k += shib_cookie.second;
1115 if (cookieLifetime > 0) {
1116 cookieLifetime += now;
1117 #ifndef HAVE_GMTIME_R
1118 ptime=gmtime(&cookieLifetime);
1120 ptime=gmtime_r(&cookieLifetime,&res);
1122 char cookietimebuf[64];
1123 strftime(cookietimebuf,64,"; expires=%a, %d %b %Y %H:%M:%S GMT",ptime);
1127 httpResponse.setCookie(shib_cookie.first.c_str(), k.c_str());
1130 bool SSCache::matches(
1131 const Application& application,
1132 const xmltooling::HTTPRequest& request,
1133 const saml2md::EntityDescriptor* issuer,
1134 const saml2::NameID& nameid,
1135 const set<string>* indexes
1138 auto_ptr_char entityID(issuer ? issuer->getEntityID() : nullptr);
1140 Session* session = find(application, request);
1142 Locker locker(session, false);
1143 if (XMLString::equals(session->getEntityID(), entityID.get()) && session->getNameID() &&
1144 stronglyMatches(issuer->getEntityID(), application.getRelyingParty(issuer)->getXMLString("entityID").second, nameid, *session->getNameID())) {
1145 return (!indexes || indexes->empty() || (session->getSessionIndex() ? (indexes->count(session->getSessionIndex())>0) : false));
1149 catch (exception& ex) {
1150 m_log.error("error while matching session: %s", ex.what());
1155 vector<string>::size_type SSCache::logout(
1156 const Application& application,
1157 const saml2md::EntityDescriptor* issuer,
1158 const saml2::NameID& nameid,
1159 const set<string>* indexes,
1161 vector<string>& sessionsKilled
1165 xmltooling::NDC ndc("logout");
1169 throw ConfigurationException("SessionCache insertion requires a StorageService.");
1171 auto_ptr_char entityID(issuer ? issuer->getEntityID() : nullptr);
1172 auto_ptr_char name(nameid.getName());
1174 m_log.info("request to logout sessions from (%s) for (%s)", entityID.get() ? entityID.get() : "unknown", name.get());
1176 if (strlen(name.get()) > 255)
1177 const_cast<char*>(name.get())[255] = 0;
1180 DDFJanitor jobj(obj);
1185 // Record the logout to prevent post-delivered assertions.
1186 // On 64-bit Windows, time_t doesn't fit in a long, so I'm using ISO timestamps.
1187 #ifndef HAVE_GMTIME_R
1188 struct tm* ptime=gmtime(&expires);
1191 struct tm* ptime=gmtime_r(&expires,&res);
1194 strftime(timebuf,32,"%Y-%m-%dT%H:%M:%SZ",ptime);
1197 ver = m_storage_lite->readText("Logout", name.get(), &record, &oldexp);
1199 istringstream lin(record);
1203 obj = DDF(nullptr).structure();
1206 // Structure is keyed by the IdP and SP, with a member per session index containing the expiration.
1207 DDF root = obj.addmember(issuer ? entityID.get() : "_shibnull").addmember(application.getRelyingParty(issuer)->getString("entityID").second);
1209 for (set<string>::const_iterator x = indexes->begin(); x!=indexes->end(); ++x)
1210 root.addmember(x->c_str()).string(timebuf);
1213 root.addmember("_shibnull").string(timebuf);
1221 ver = m_storage_lite->updateText("Logout", name.get(), lout.str().c_str(), max(expires, oldexp), ver);
1223 // Out of sync, or went missing, so retry.
1224 return logout(application, issuer, nameid, indexes, expires, sessionsKilled);
1227 else if (!m_storage_lite->createText("Logout", name.get(), lout.str().c_str(), expires)) {
1228 // Hit a dup, so just retry, hopefully hitting the other branch.
1229 return logout(application, issuer, nameid, indexes, expires, sessionsKilled);
1236 // Read in potentially matching sessions.
1237 ver = m_storage_lite->readText("NameID", name.get(), &record);
1239 m_log.debug("no active sessions to logout for supplied issuer and subject");
1243 istringstream in(record);
1246 // The record contains child lists for each known session index.
1248 DDF sessions = obj.first();
1249 while (sessions.islist()) {
1250 if (!indexes || indexes->empty() || indexes->count(sessions.name())) {
1251 key = sessions.first();
1252 while (key.isstring()) {
1253 // Fetch the session for comparison.
1254 Session* session = nullptr;
1256 session = find(application, key.string());
1258 catch (exception& ex) {
1259 m_log.error("error locating session (%s): %s", key.string(), ex.what());
1263 Locker locker(session, false);
1265 if (XMLString::equals(session->getEntityID(), entityID.get())) {
1267 if (stronglyMatches(issuer->getEntityID(), application.getRelyingParty(issuer)->getXMLString("entityID").second, nameid, *session->getNameID())) {
1268 sessionsKilled.push_back(key.string());
1272 m_log.debug("session (%s) contained a non-matching NameID, leaving it alone", key.string());
1276 m_log.debug("session (%s) established by different IdP, leaving it alone", key.string());
1280 // Session's gone, so...
1281 sessionsKilled.push_back(key.string());
1284 key = sessions.next();
1287 // No sessions left for this index?
1288 if (sessions.first().isnull())
1291 sessions = obj.next();
1294 if (obj.first().isnull())
1297 // If possible, write back the mapping record (this isn't crucial).
1300 m_storage_lite->deleteText("NameID", name.get());
1302 else if (!sessionsKilled.empty()) {
1305 if (m_storage_lite->updateText("NameID", name.get(), out.str().c_str(), 0, ver) <= 0)
1306 m_log.warn("logout mapping record changed behind us, leaving it alone");
1309 catch (exception& ex) {
1310 m_log.error("error updating logout mapping record: %s", ex.what());
1313 return sessionsKilled.size();
1316 bool SSCache::stronglyMatches(const XMLCh* idp, const XMLCh* sp, const saml2::NameID& n1, const saml2::NameID& n2) const
1318 if (!XMLString::equals(n1.getName(), n2.getName()))
1321 const XMLCh* s1 = n1.getFormat();
1322 const XMLCh* s2 = n2.getFormat();
1324 s1 = saml2::NameID::UNSPECIFIED;
1326 s2 = saml2::NameID::UNSPECIFIED;
1327 if (!XMLString::equals(s1,s2))
1330 s1 = n1.getNameQualifier();
1331 s2 = n2.getNameQualifier();
1336 if (!XMLString::equals(s1,s2))
1339 s1 = n1.getSPNameQualifier();
1340 s2 = n2.getSPNameQualifier();
1345 if (!XMLString::equals(s1,s2))
1353 Session* SSCache::find(const Application& application, const char* key, const char* client_addr, time_t* timeout)
1356 xmltooling::NDC ndc("find");
1358 StoredSession* session=nullptr;
1361 m_log.debug("searching local cache for session (%s)", key);
1363 map<string,StoredSession*>::const_iterator i=m_hashtable.find(key);
1364 if (i!=m_hashtable.end()) {
1365 // Save off and lock the session.
1366 session = i->second;
1369 m_log.debug("session found locally, validating it for use");
1377 if (!SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess)) {
1378 m_log.debug("session not found locally, remoting the search");
1379 // Remote the request.
1380 DDF in("find::"STORAGESERVICE_SESSION_CACHE"::SessionCache"), out;
1383 in.addmember("key").string(key);
1384 in.addmember("application_id").string(application.getId());
1385 if (timeout && *timeout) {
1386 // On 64-bit Windows, time_t doesn't fit in a long, so I'm using ISO timestamps.
1387 #ifndef HAVE_GMTIME_R
1388 struct tm* ptime=gmtime(timeout);
1391 struct tm* ptime=gmtime_r(timeout,&res);
1394 strftime(timebuf,32,"%Y-%m-%dT%H:%M:%SZ",ptime);
1395 in.addmember("timeout").string(timebuf);
1399 out=application.getServiceProvider().getListenerService()->send(in);
1400 if (!out.isstruct()) {
1402 m_log.debug("session not found in remote cache");
1406 // Wrap the results in a local entry and save it.
1407 session = new StoredSession(this, out);
1408 // The remote end has handled timeout issues, we handle address and expiration checks.
1417 // We're out of process, so we can search the storage service directly.
1420 throw ConfigurationException("SessionCache lookup requires a StorageService.");
1422 m_log.debug("searching for session (%s)", key);
1427 int ver = m_storage->readText(key, "session", &record, &lastAccess);
1431 m_log.debug("reconstituting session and checking validity");
1433 istringstream in(record);
1436 lastAccess -= m_cacheTimeout; // adjusts it back to the last time the record's timestamp was touched
1437 time_t now=time(nullptr);
1439 if (timeout && *timeout > 0 && now - lastAccess >= *timeout) {
1440 m_log.info("session timed out (ID: %s)", key);
1441 remove(application, key);
1442 const char* eid = obj["entity_id"].string();
1445 throw RetryableProfileException("Your session has expired, and you must re-authenticate.");
1449 throw RetryableProfileException("Your session has expired, and you must re-authenticate.", namedparams(1, "entityID", eid2.c_str()));
1453 // Update storage expiration, if possible.
1455 m_storage->updateContext(key, now + m_cacheTimeout);
1457 catch (exception& ex) {
1458 m_log.error("failed to update session expiration: %s", ex.what());
1462 // Wrap the results in a local entry and save it.
1463 session = new StoredSession(this, obj);
1464 // We handled timeout issues, still need to handle address and expiration checks.
1467 throw ConfigurationException("SessionCache search requires a StorageService.");
1472 // Lock for writing and repeat the search to avoid duplication.
1474 SharedLock shared(m_lock, false);
1475 if (m_hashtable.count(key)) {
1476 // We're using an existing session entry.
1478 session = m_hashtable[key];
1482 m_hashtable[key]=session;
1488 if (!XMLString::equals(session->getApplicationID(), application.getId())) {
1489 m_log.error("an application (%s) tried to access another application's session", application.getId());
1494 // Verify currency and update the timestamp if indicated by caller.
1496 session->validate(application, client_addr, timeout);
1500 remove(application, key);
1507 void SSCache::remove(const Application& application, const char* key)
1510 xmltooling::NDC ndc("remove");
1512 // Take care of local copy.
1516 if (SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess)) {
1517 // Remove the session from storage directly.
1519 m_storage->deleteContext(key);
1520 m_log.info("removed session (%s)", key);
1522 TransactionLog* xlog = application.getServiceProvider().getTransactionLog();
1523 Locker locker(xlog);
1524 xlog->log.info("Destroyed session (applicationId: %s) (ID: %s)", application.getId(), key);
1526 throw ConfigurationException("SessionCache removal requires a StorageService.");
1530 // Remote the request.
1531 DDF in("remove::"STORAGESERVICE_SESSION_CACHE"::SessionCache");
1534 in.addmember("key").string(key);
1535 in.addmember("application_id").string(application.getId());
1537 DDF out = application.getServiceProvider().getListenerService()->send(in);
1542 void SSCache::dormant(const char* key)
1545 xmltooling::NDC ndc("dormant");
1548 m_log.debug("deleting local copy of session (%s)", key);
1550 // lock the cache for writing, which means we know nobody is sitting in find()
1553 // grab the entry from the table
1554 map<string,StoredSession*>::const_iterator i=m_hashtable.find(key);
1555 if (i==m_hashtable.end()) {
1560 // ok, remove the entry and lock it
1561 StoredSession* entry=i->second;
1562 m_hashtable.erase(key);
1568 // we can release the cache entry lock because we know we're not in the cache anymore
1574 void* SSCache::cleanup_fn(void* p)
1577 xmltooling::NDC ndc("cleanup");
1580 SSCache* pcache = reinterpret_cast<SSCache*>(p);
1583 // First, let's block all signals
1584 Thread::mask_all_signals();
1587 auto_ptr<Mutex> mutex(Mutex::create());
1589 // Load our configuration details...
1590 static const XMLCh cleanupInterval[] = UNICODE_LITERAL_15(c,l,e,a,n,u,p,I,n,t,e,r,v,a,l);
1591 const XMLCh* tag=pcache->m_root ? pcache->m_root->getAttributeNS(nullptr, cleanupInterval) : nullptr;
1592 int rerun_timer = 900;
1594 rerun_timer = XMLString::parseInt(tag);
1595 if (rerun_timer <= 0)
1601 pcache->m_log.info("cleanup thread started...run every %d secs; timeout after %d secs", rerun_timer, pcache->m_inprocTimeout);
1603 while (!pcache->shutdown) {
1604 pcache->shutdown_wait->timedwait(mutex.get(), rerun_timer);
1605 if (pcache->shutdown)
1608 // Ok, let's run through the cleanup process and clean out
1609 // really old sessions. This is a two-pass process. The
1610 // first pass is done holding a read-lock while we iterate over
1611 // the cache. The second pass doesn't need a lock because
1612 // the 'deletes' will lock the cache.
1614 // Pass 1: iterate over the map and find all entries that have not been
1615 // used in the allotted timeout.
1616 vector<string> stale_keys;
1617 time_t stale = time(nullptr) - pcache->m_inprocTimeout;
1619 pcache->m_log.debug("cleanup thread running");
1621 pcache->m_lock->rdlock();
1622 for (map<string,StoredSession*>::const_iterator i=pcache->m_hashtable.begin(); i!=pcache->m_hashtable.end(); ++i) {
1623 // If the last access was BEFORE the stale timeout...
1625 time_t last=i->second->getLastAccess();
1626 i->second->unlock();
1628 stale_keys.push_back(i->first);
1630 pcache->m_lock->unlock();
1632 if (!stale_keys.empty()) {
1633 pcache->m_log.info("purging %d old sessions", stale_keys.size());
1635 // Pass 2: walk through the list of stale entries and remove them from the cache
1636 for (vector<string>::const_iterator j = stale_keys.begin(); j != stale_keys.end(); ++j)
1637 pcache->dormant(j->c_str());
1640 pcache->m_log.debug("cleanup thread completed");
1643 pcache->m_log.info("cleanup thread exiting");
1651 void SSCache::receive(DDF& in, ostream& out)
1654 xmltooling::NDC ndc("receive");
1657 if (!strcmp(in.name(),"find::"STORAGESERVICE_SESSION_CACHE"::SessionCache")) {
1658 const char* key=in["key"].string();
1660 throw ListenerException("Required parameters missing for session lookup.");
1662 const Application* app = SPConfig::getConfig().getServiceProvider()->getApplication(in["application_id"].string());
1664 throw ListenerException("Application not found, check configuration?");
1666 // Do an unversioned read.
1669 if (!m_storage->readText(key, "session", &record, &lastAccess)) {
1671 DDFJanitor jan(ret);
1676 // Adjust for expiration to recover last access time and check timeout.
1677 lastAccess -= m_cacheTimeout;
1678 time_t now=time(nullptr);
1680 // See if we need to check for a timeout.
1681 if (in["timeout"].string()) {
1683 auto_ptr_XMLCh dt(in["timeout"].string());
1684 DateTime dtobj(dt.get());
1685 dtobj.parseDateTime();
1686 timeout = dtobj.getEpoch();
1688 if (timeout > 0 && now - lastAccess >= timeout) {
1689 m_log.info("session timed out (ID: %s)", key);
1691 throw RetryableProfileException("Your session has expired, and you must re-authenticate.");
1694 // Update storage expiration, if possible.
1696 m_storage->updateContext(key, now + m_cacheTimeout);
1698 catch (exception& ex) {
1699 m_log.error("failed to update session expiration: %s", ex.what());
1703 // Send the record back.
1706 else if (!strcmp(in.name(),"touch::"STORAGESERVICE_SESSION_CACHE"::SessionCache")) {
1707 const char* key=in["key"].string();
1709 throw ListenerException("Required parameters missing for session check.");
1711 // Do a versioned read.
1714 int curver = in["version"].integer();
1715 int ver = m_storage->readText(key, "session", &record, &lastAccess, curver);
1717 m_log.warn("unsuccessful versioned read of session (ID: %s), caches out of sync?", key);
1718 throw RetryableProfileException("Your session has expired, and you must re-authenticate.");
1721 // Adjust for expiration to recover last access time and check timeout.
1722 lastAccess -= m_cacheTimeout;
1723 time_t now=time(nullptr);
1725 // See if we need to check for a timeout.
1727 auto_ptr_XMLCh dt(in["timeout"].string());
1729 DateTime dtobj(dt.get());
1730 dtobj.parseDateTime();
1731 timeout = dtobj.getEpoch();
1734 if (timeout > 0 && now - lastAccess >= timeout) {
1735 m_log.info("session timed out (ID: %s)", key);
1736 throw RetryableProfileException("Your session has expired, and you must re-authenticate.");
1739 // Update storage expiration, if possible.
1741 m_storage->updateContext(key, now + m_cacheTimeout);
1743 catch (exception& ex) {
1744 m_log.error("failed to update session expiration: %s", ex.what());
1748 // Send the record back.
1753 DDFJanitor jan(ret);
1757 else if (!strcmp(in.name(),"remove::"STORAGESERVICE_SESSION_CACHE"::SessionCache")) {
1758 const char* key=in["key"].string();
1760 throw ListenerException("Required parameter missing for session removal.");
1762 const Application* app = SPConfig::getConfig().getServiceProvider()->getApplication(in["application_id"].string());
1764 throw ConfigurationException("Application not found, check configuration?");
1768 DDFJanitor jan(ret);