2 * Copyright 2001-2007 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 * StorageServiceSessionCache.cpp
\r
20 * StorageService-based SessionCache implementation.
\r
22 * Instead of optimizing this plugin with a buffering scheme that keeps objects around
\r
23 * and avoids extra parsing steps, I'm assuming that systems that require such can
\r
24 * layer their own cache plugin on top of this version either by delegating to it
\r
25 * or using the remoting support. So this version will load sessions directly
\r
26 * from the StorageService, instantiate enough to expose the Session API,
\r
27 * and then delete everything when they're unlocked. All data in memory is always
\r
28 * kept in sync with the StorageService (no lazy updates).
\r
31 #include "internal.h"
\r
32 #include "Application.h"
\r
33 #include "exceptions.h"
\r
34 #include "ServiceProvider.h"
\r
35 #include "SessionCache.h"
\r
36 #include "TransactionLog.h"
\r
37 #include "attribute/Attribute.h"
\r
38 #include "remoting/ListenerService.h"
\r
39 #include "util/SPConstants.h"
\r
41 #include <log4cpp/Category.hh>
\r
42 #include <saml/SAMLConfig.h>
\r
43 #include <xmltooling/util/NDC.h>
\r
44 #include <xmltooling/util/StorageService.h>
\r
45 #include <xmltooling/util/XMLHelper.h>
\r
46 #include <xercesc/util/XMLUniDefs.hpp>
\r
48 using namespace shibsp;
\r
49 using namespace opensaml::saml2md;
\r
50 using namespace opensaml;
\r
51 using namespace xmltooling;
\r
52 using namespace log4cpp;
\r
53 using namespace std;
\r
58 class StoredSession : public virtual Session
\r
61 StoredSession(SSCache* cache, DDF& obj) : m_obj(obj), m_cache(cache) {
\r
62 const char* nameid = obj["nameid"].string();
\r
64 throw FatalProfileException("NameID missing from cached session.");
\r
66 // Parse and bind the document into an XMLObject.
\r
67 istringstream instr(nameid);
\r
68 DOMDocument* doc = XMLToolingConfig::getConfig().getParser().parse(instr);
\r
69 XercesJanitor<DOMDocument> janitor(doc);
\r
70 auto_ptr<saml2::NameID> n(saml2::NameIDBuilder::buildNameID());
\r
71 n->unmarshall(doc->getDocumentElement(), true);
\r
73 m_nameid = n.release();
\r
85 const char* getClientAddress() const {
\r
86 return m_obj["client_addr"].string();
\r
88 const char* getEntityID() const {
\r
89 return m_obj["entity_id"].string();
\r
91 const char* getAuthnInstant() const {
\r
92 return m_obj["authn_instant"].string();
\r
94 const opensaml::saml2::NameID& getNameID() const {
\r
97 const char* getSessionIndex() const {
\r
98 return m_obj["session_index"].string();
\r
100 const char* getAuthnContextClassRef() const {
\r
101 return m_obj["authncontext_class"].string();
\r
103 const char* getAuthnContextDeclRef() const {
\r
104 return m_obj["authncontext_decl"].string();
\r
106 const map<string,const Attribute*>& getAttributes() const {
\r
107 if (m_attributes.empty())
\r
108 unmarshallAttributes();
\r
109 return m_attributes;
\r
111 const vector<const char*>& getAssertionIDs() const {
\r
112 if (m_ids.empty()) {
\r
113 DDF id = m_obj["assertions"].first();
\r
114 while (id.isstring()) {
\r
115 m_ids.push_back(id.string());
\r
122 void addAttributes(const vector<Attribute*>& attributes);
\r
123 const RootObject* getAssertion(const char* id) const;
\r
124 void addAssertion(RootObject* assertion);
\r
127 void unmarshallAttributes() const;
\r
130 saml2::NameID* m_nameid;
\r
131 mutable map<string,const Attribute*> m_attributes;
\r
132 mutable vector<const char*> m_ids;
\r
133 mutable map<string,RootObject*> m_tokens;
\r
137 class SSCache : public SessionCache, public virtual Remoted
\r
140 SSCache(const DOMElement* e);
\r
143 void receive(DDF& in, ostream& out);
\r
147 const Application& application,
\r
148 const char* client_addr,
\r
149 const saml2md::EntityDescriptor* issuer,
\r
150 const saml2::NameID& nameid,
\r
151 const char* authn_instant=NULL,
\r
152 const char* session_index=NULL,
\r
153 const char* authncontext_class=NULL,
\r
154 const char* authncontext_decl=NULL,
\r
155 const RootObject* ssoToken=NULL,
\r
156 const vector<Attribute*>* attributes=NULL
\r
158 Session* find(const char* key, const Application& application, const char* client_addr=NULL, time_t timeout=0);
\r
159 void remove(const char* key, const Application& application, const char* client_addr);
\r
162 StorageService* m_storage;
\r
165 SessionCache* SHIBSP_DLLLOCAL StorageServiceCacheFactory(const DOMElement* const & e)
\r
167 return new SSCache(e);
\r
170 static const XMLCh _StorageService[] = UNICODE_LITERAL_14(S,t,o,r,a,g,e,S,e,r,v,i,c,e);
\r
173 StoredSession::~StoredSession()
\r
177 for_each(m_attributes.begin(), m_attributes.end(), cleanup_const_pair<string,Attribute>());
\r
178 for_each(m_tokens.begin(), m_tokens.end(), cleanup_pair<string,RootObject>());
\r
181 void StoredSession::unmarshallAttributes() const
\r
183 Attribute* attribute;
\r
184 DDF attr = m_obj["attributes"].first();
\r
185 while (!attr.isnull()) {
\r
187 attribute = Attribute::unmarshall(attr);
\r
188 m_attributes[attribute->getId()] = attribute;
\r
189 if (m_cache->m_log.isDebugEnabled())
\r
190 m_cache->m_log.debug("unmarshalled attribute (ID: %s) with %d value%s",
\r
191 attribute->getId(), attr.first().integer(), attr.first().integer()!=1 ? "s" : "");
\r
193 catch (AttributeException& ex) {
\r
194 const char* id = attr.first().name();
\r
195 m_cache->m_log.error("error unmarshalling attribute (ID: %s): %s", id ? id : "none", ex.what());
\r
197 attr = attr.next();
\r
201 void StoredSession::addAttributes(const vector<Attribute*>& attributes)
\r
204 xmltooling::NDC ndc("addAttributes");
\r
207 m_cache->m_log.debug("adding attributes to session (%s)", m_obj.name());
\r
212 DDF attrs = m_obj["attributes"];
\r
213 if (!attrs.islist())
\r
214 attrs = m_obj.addmember("attributes").list();
\r
215 for (vector<Attribute*>::const_iterator a=attributes.begin(); a!=attributes.end(); ++a) {
\r
216 attr = (*a)->marshall();
\r
220 // Tentatively increment the version.
\r
221 m_obj["version"].integer(m_obj["version"].integer()+1);
\r
225 string record(str.str());
\r
228 ver = m_cache->m_storage->updateText(m_obj.name(), "session", record.c_str(), 0, m_obj["version"].integer()-1);
\r
230 catch (exception&) {
\r
231 // Roll back modification to record.
\r
232 m_obj["version"].integer(m_obj["version"].integer()-1);
\r
233 vector<Attribute*>::size_type count = attributes.size();
\r
235 attrs.last().destroy();
\r
240 // Roll back modification to record.
\r
241 m_obj["version"].integer(m_obj["version"].integer()-1);
\r
242 vector<Attribute*>::size_type count = attributes.size();
\r
244 attrs.last().destroy();
\r
247 // Fatal problem with update.
\r
248 throw IOException("Unable to update stored session.");
\r
250 else if (ver < 0) {
\r
252 m_cache->m_log.warn("storage service indicates the record is out of sync, updating with a fresh copy...");
\r
253 ver = m_cache->m_storage->readText(m_obj.name(), "session", &record, NULL);
\r
255 m_cache->m_log.error("readText failed on StorageService for session (%s)", m_obj.name());
\r
256 throw IOException("Unable to read back stored session.");
\r
261 istringstream in(record);
\r
265 for_each(m_attributes.begin(), m_attributes.end(), cleanup_const_pair<string,Attribute>());
\r
266 m_attributes.clear();
\r
267 newobj["version"].integer(ver);
\r
273 } while (ver < 0); // negative indicates a sync issue so we retry
\r
275 TransactionLog* xlog = SPConfig::getConfig().getServiceProvider()->getTransactionLog();
\r
276 Locker locker(xlog);
\r
277 xlog->log.infoStream() <<
\r
278 "Added the following attributes to session (ID: " <<
\r
280 ") for (applicationId: " <<
\r
281 m_obj["application_id"].string() <<
\r
283 for (vector<Attribute*>::const_iterator a=attributes.begin(); a!=attributes.end(); ++a)
\r
284 xlog->log.infoStream() << "\t" << (*a)->getId() << " (" << (*a)->valueCount() << " values)";
\r
285 xlog->log.info("}");
\r
287 // We own them now, so clean them up.
\r
288 for_each(attributes.begin(), attributes.end(), xmltooling::cleanup<Attribute>());
\r
291 const RootObject* StoredSession::getAssertion(const char* id) const
\r
293 map<string,RootObject*>::const_iterator i = m_tokens.find(id);
\r
294 if (i!=m_tokens.end())
\r
298 if (!m_cache->m_storage->readText(m_obj.name(), id, &tokenstr, NULL))
\r
299 throw FatalProfileException("Assertion not found in cache.");
\r
301 // Parse and bind the document into an XMLObject.
\r
302 istringstream instr(tokenstr);
\r
303 DOMDocument* doc = XMLToolingConfig::getConfig().getParser().parse(instr);
\r
304 XercesJanitor<DOMDocument> janitor(doc);
\r
305 auto_ptr<XMLObject> xmlObject(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(), true));
\r
308 RootObject* token = dynamic_cast<RootObject*>(xmlObject.get());
\r
309 if (!token || !token->isAssertion())
\r
310 throw FatalProfileException("Request for cached assertion returned an unknown object type.");
\r
312 // Transfer ownership to us.
\r
313 xmlObject.release();
\r
314 m_tokens[id]=token;
\r
318 void StoredSession::addAssertion(RootObject* assertion)
\r
321 xmltooling::NDC ndc("addAssertion");
\r
324 if (!assertion || !assertion->isAssertion())
\r
325 throw FatalProfileException("Unknown object type passed to session for storage.");
\r
327 auto_ptr_char id(assertion->getID());
\r
329 m_cache->m_log.debug("adding assertion (%s) to session (%s)", id.get(), m_obj.name());
\r
332 if (!m_cache->m_storage->readText(m_obj.name(), "session", NULL, &exp))
\r
333 throw IOException("Unable to load expiration time for stored session.");
\r
335 ostringstream tokenstr;
\r
336 tokenstr << *assertion;
\r
337 m_cache->m_storage->createText(m_obj.name(), id.get(), tokenstr.str().c_str(), exp);
\r
341 DDF token = DDF(NULL).string(id.get());
\r
342 m_obj["assertions"].add(token);
\r
344 // Tentatively increment the version.
\r
345 m_obj["version"].integer(m_obj["version"].integer()+1);
\r
349 string record(str.str());
\r
352 ver = m_cache->m_storage->updateText(m_obj.name(), "session", record.c_str(), 0, m_obj["version"].integer()-1);
\r
354 catch (exception&) {
\r
356 m_obj["version"].integer(m_obj["version"].integer()-1);
\r
357 m_cache->m_storage->deleteText(m_obj.name(), id.get());
\r
363 m_obj["version"].integer(m_obj["version"].integer()-1);
\r
366 // Fatal problem with update.
\r
367 m_cache->m_log.error("updateText failed on StorageService for session (%s)", m_obj.name());
\r
368 m_cache->m_storage->deleteText(m_obj.name(), id.get());
\r
369 throw IOException("Unable to update stored session.");
\r
371 else if (ver < 0) {
\r
373 m_cache->m_log.warn("storage service indicates the record is out of sync, updating with a fresh copy...");
\r
374 ver = m_cache->m_storage->readText(m_obj.name(), "session", &record, NULL);
\r
376 m_cache->m_log.error("readText failed on StorageService for session (%s)", m_obj.name());
\r
377 m_cache->m_storage->deleteText(m_obj.name(), id.get());
\r
378 throw IOException("Unable to read back stored session.");
\r
383 istringstream in(record);
\r
387 for_each(m_attributes.begin(), m_attributes.end(), cleanup_const_pair<string,Attribute>());
\r
388 m_attributes.clear();
\r
389 newobj["version"].integer(ver);
\r
395 } while (ver < 0); // negative indicates a sync issue so we retry
\r
400 TransactionLog* xlog = SPConfig::getConfig().getServiceProvider()->getTransactionLog();
\r
401 Locker locker(xlog);
\r
403 "Added assertion (ID: %s) to session for (applicationId: %s) with (ID: %s)",
\r
404 id.get(), m_obj["application_id"].string(), m_obj.name()
\r
408 SSCache::SSCache(const DOMElement* e)
\r
409 : SessionCache(e), m_log(Category::getInstance(SHIBSP_LOGCAT".SessionCache")), m_storage(NULL)
\r
411 SPConfig& conf = SPConfig::getConfig();
\r
412 const XMLCh* tag = e ? e->getAttributeNS(NULL,_StorageService) : NULL;
\r
414 auto_ptr_char ssid(tag);
\r
415 m_storage = conf.getServiceProvider()->getStorageService(ssid.get());
\r
417 m_log.info("bound to StorageService (%s)", ssid.get());
\r
419 throw ConfigurationException("SessionCache unable to locate StorageService, check configuration.");
\r
422 ListenerService* listener=conf.getServiceProvider()->getListenerService(false);
\r
423 if (listener && conf.isEnabled(SPConfig::OutOfProcess)) {
\r
424 listener->regListener("insert::"REMOTED_SESSION_CACHE,this);
\r
425 listener->regListener("find::"REMOTED_SESSION_CACHE,this);
\r
426 listener->regListener("remove::"REMOTED_SESSION_CACHE,this);
\r
429 m_log.info("no ListenerService available, cache remoting is disabled");
\r
433 string SSCache::insert(
\r
435 const Application& application,
\r
436 const char* client_addr,
\r
437 const saml2md::EntityDescriptor* issuer,
\r
438 const saml2::NameID& nameid,
\r
439 const char* authn_instant,
\r
440 const char* session_index,
\r
441 const char* authncontext_class,
\r
442 const char* authncontext_decl,
\r
443 const RootObject* ssoToken,
\r
444 const vector<Attribute*>* attributes
\r
448 xmltooling::NDC ndc("insert");
\r
451 m_log.debug("creating new session");
\r
453 auto_ptr_char key(SAMLConfig::getConfig().generateIdentifier());
\r
455 // Store session properties in DDF.
\r
456 DDF obj = DDF(key.get()).structure();
\r
457 obj.addmember("version").integer(1);
\r
458 obj.addmember("application_id").string(application.getId());
\r
460 // On 64-bit Windows, time_t doesn't fit in a long, so I'm using ISO timestamps.
\r
461 #ifndef HAVE_GMTIME_R
\r
462 struct tm* ptime=gmtime(&expires);
\r
465 struct tm* ptime=gmtime_r(&expires,&res);
\r
468 strftime(timebuf,32,"%Y-%m-%dT%H:%M:%SZ",ptime);
\r
469 obj.addmember("expires").string(timebuf);
\r
471 obj.addmember("client_addr").string(client_addr);
\r
473 auto_ptr_char entity_id(issuer->getEntityID());
\r
474 obj.addmember("entity_id").string(entity_id.get());
\r
477 obj.addmember("authn_instant").string(authn_instant);
\r
479 obj.addmember("session_index").string(session_index);
\r
480 if (authncontext_class)
\r
481 obj.addmember("authncontext_class").string(authncontext_class);
\r
482 if (authncontext_decl)
\r
483 obj.addmember("authncontext_decl").string(authncontext_decl);
\r
485 ostringstream namestr;
\r
487 obj.addmember("nameid").string(namestr.str().c_str());
\r
491 ostringstream tstr;
\r
493 tokenstr = tstr.str();
\r
494 auto_ptr_char tokenid(ssoToken->getID());
\r
495 DDF tokid = DDF(NULL).string(tokenid.get());
\r
496 obj.addmember("assertions").list().add(tokid);
\r
501 DDF attrlist = obj.addmember("attributes").list();
\r
502 for (vector<Attribute*>::const_iterator a=attributes->begin(); a!=attributes->end(); ++a) {
\r
503 attr = (*a)->marshall();
\r
504 attrlist.add(attr);
\r
508 ostringstream record;
\r
511 m_log.debug("storing new session...");
\r
512 time_t now = time(NULL);
\r
513 m_storage->createText(key.get(), "session", record.str().c_str(), now + m_cacheTimeout);
\r
516 m_storage->createText(key.get(), obj["assertions"].first().string(), tokenstr.c_str(), now + m_cacheTimeout);
\r
518 catch (exception& ex) {
\r
519 m_log.error("error storing assertion along with session: %s", ex.what());
\r
523 const char* pid = obj["entity_id"].string();
\r
524 m_log.debug("new session created: SessionID (%s) IdP (%s) Address (%s)", key.get(), pid ? pid : "none", client_addr);
\r
526 // Transaction Logging
\r
527 auto_ptr_char name(nameid.getName());
\r
528 TransactionLog* xlog = SPConfig::getConfig().getServiceProvider()->getTransactionLog();
\r
529 Locker locker(xlog);
\r
530 xlog->log.infoStream() <<
\r
531 "New session (ID: " <<
\r
533 ") with (applicationId: " <<
\r
534 application.getId() <<
\r
535 ") for principal from (IdP: " <<
\r
536 (pid ? pid : "none") <<
\r
537 ") at (ClientAddress: " <<
\r
539 ") with (NameIdentifier: " <<
\r
544 xlog->log.infoStream() <<
\r
545 "Cached the following attributes with session (ID: " <<
\r
547 ") for (applicationId: " <<
\r
548 application.getId() <<
\r
550 for (vector<Attribute*>::const_iterator a=attributes->begin(); a!=attributes->end(); ++a)
\r
551 xlog->log.infoStream() << "\t" << (*a)->getId() << " (" << (*a)->valueCount() << " values)";
\r
552 xlog->log.info("}");
\r
553 for_each(attributes->begin(), attributes->end(), xmltooling::cleanup<Attribute>());
\r
559 Session* SSCache::find(const char* key, const Application& application, const char* client_addr, time_t timeout)
\r
562 xmltooling::NDC ndc("find");
\r
565 m_log.debug("searching for session (%s)", key);
\r
569 int ver = m_storage->readText(key, "session", &record, &lastAccess);
\r
573 m_log.debug("reconstituting session and checking validity");
\r
576 istringstream in(record);
\r
579 if (!XMLString::equals(obj["application_id"].string(), application.getId())) {
\r
580 m_log.error("an application (%s) tried to access another application's session", application.getId());
\r
586 if (m_log.isDebugEnabled())
\r
587 m_log.debug("comparing client address %s against %s", client_addr, obj["client_addr"].string());
\r
588 if (strcmp(obj["client_addr"].string(),client_addr)) {
\r
589 m_log.warn("client address mismatch");
\r
590 remove(key, application, client_addr);
\r
591 RetryableProfileException ex(
\r
592 "Your IP address ($1) does not match the address recorded at the time the session was established.",
\r
593 params(1,client_addr)
\r
595 string eid(obj["entity_id"].string());
\r
599 MetadataProvider* m=application.getMetadataProvider();
\r
601 annotateException(&ex,m->getEntityDescriptor(eid.c_str(),false)); // throws it
\r
605 lastAccess -= m_cacheTimeout; // adjusts it back to the last time the record's timestamp was touched
\r
606 time_t now=time(NULL);
\r
608 if (timeout > 0 && now - lastAccess >= timeout) {
\r
609 m_log.info("session timed out (ID: %s)", key);
\r
610 remove(key, application, client_addr);
\r
611 RetryableProfileException ex("Your session has expired, and you must re-authenticate.");
\r
612 string eid(obj["entity_id"].string());
\r
616 MetadataProvider* m=application.getMetadataProvider();
\r
618 annotateException(&ex,m->getEntityDescriptor(eid.c_str(),false)); // throws it
\r
621 auto_ptr_XMLCh exp(obj["expires"].string());
\r
623 DateTime iso(exp.get());
\r
624 iso.parseDateTime();
\r
625 if (now > iso.getEpoch()) {
\r
626 m_log.info("session expired (ID: %s)", key);
\r
627 remove(key, application, client_addr);
\r
628 RetryableProfileException ex("Your session has expired, and you must re-authenticate.");
\r
629 string eid(obj["entity_id"].string());
\r
633 MetadataProvider* m=application.getMetadataProvider();
\r
635 annotateException(&ex,m->getEntityDescriptor(eid.c_str(),false)); // throws it
\r
639 // Update storage expiration, if possible.
\r
641 m_storage->updateContext(key, now + m_cacheTimeout);
\r
643 catch (exception& ex) {
\r
644 m_log.error("failed to update session expiration: %s", ex.what());
\r
647 // Finally build the Session object.
\r
649 return new StoredSession(this, obj);
\r
651 catch (exception&) {
\r
657 void SSCache::remove(const char* key, const Application& application, const char* client_addr)
\r
660 xmltooling::NDC ndc("remove");
\r
663 m_log.debug("removing session (%s)", key);
\r
665 m_storage->deleteContext(key);
\r
667 TransactionLog* xlog = SPConfig::getConfig().getServiceProvider()->getTransactionLog();
\r
668 Locker locker(xlog);
\r
669 xlog->log.info("Destroyed session (applicationId: %s) (ID: %s)", application.getId(), key);
\r
672 void SSCache::receive(DDF& in, ostream& out)
\r
675 xmltooling::NDC ndc("receive");
\r
678 if (!strcmp(in.name(),"insert::"REMOTED_SESSION_CACHE)) {
\r
679 auto_ptr_char key(SAMLConfig::getConfig().generateIdentifier());
\r
680 in.name(key.get());
\r
682 DDF token = in["token"].remove();
\r
683 DDFJanitor tjan(token);
\r
685 m_log.debug("storing new session...");
\r
686 ostringstream record;
\r
688 time_t now = time(NULL);
\r
689 m_storage->createText(key.get(), "session", record.str().c_str(), now + m_cacheTimeout);
\r
690 if (token.isstring()) {
\r
692 m_storage->createText(key.get(), in["assertions"].first().string(), token.string(), now + m_cacheTimeout);
\r
694 catch (IOException& ex) {
\r
695 m_log.error("error storing assertion along with session: %s", ex.what());
\r
698 const char* pid = in["entity_id"].string();
\r
699 m_log.debug("new session created: SessionID (%s) IdP (%s) Address (%s)", key.get(), pid ? pid : "none", in["client_addr"].string());
\r
701 DDF ret = DDF(NULL).structure();
\r
702 DDFJanitor jan(ret);
\r
703 ret.addmember("key").string(key.get());
\r
706 else if (!strcmp(in.name(),"find::"REMOTED_SESSION_CACHE)) {
\r
707 const char* key=in["key"].string();
\r
709 throw ListenerException("Required parameters missing for session removal.");
\r
711 // Do an unversioned read.
\r
714 if (!m_storage->readText(key, "session", &record, &lastAccess)) {
\r
716 DDFJanitor jan(ret);
\r
721 // Adjust for expiration to recover last access time and check timeout.
\r
722 lastAccess -= m_cacheTimeout;
\r
723 time_t now=time(NULL);
\r
725 // See if we need to check for a timeout.
\r
726 time_t timeout = 0;
\r
727 auto_ptr_XMLCh dt(in["timeout"].string());
\r
729 DateTime dtobj(dt.get());
\r
730 dtobj.parseDateTime();
\r
731 timeout = dtobj.getEpoch();
\r
734 if (timeout > 0 && now - lastAccess >= timeout) {
\r
735 m_log.info("session timed out (ID: %s)", key);
\r
736 remove(key,*(SPConfig::getConfig().getServiceProvider()->getApplication("default")),NULL);
\r
737 throw RetryableProfileException("Your session has expired, and you must re-authenticate.");
\r
740 // Update storage expiration, if possible.
\r
742 m_storage->updateContext(key, now + m_cacheTimeout);
\r
744 catch (exception& ex) {
\r
745 m_log.error("failed to update session expiration: %s", ex.what());
\r
748 // Send the record back.
\r
751 else if (!strcmp(in.name(),"touch::"REMOTED_SESSION_CACHE)) {
\r
752 const char* key=in["key"].string();
\r
754 throw ListenerException("Required parameters missing for session check.");
\r
756 // Do a versioned read.
\r
759 int curver = in["version"].integer();
\r
760 int ver = m_storage->readText(key, "session", &record, &lastAccess, curver);
\r
762 m_log.warn("unsuccessful versioned read of session (ID: %s), caches out of sync?", key);
\r
763 throw RetryableProfileException("Your session has expired, and you must re-authenticate.");
\r
766 // Adjust for expiration to recover last access time and check timeout.
\r
767 lastAccess -= m_cacheTimeout;
\r
768 time_t now=time(NULL);
\r
770 // See if we need to check for a timeout.
\r
771 time_t timeout = 0;
\r
772 auto_ptr_XMLCh dt(in["timeout"].string());
\r
774 DateTime dtobj(dt.get());
\r
775 dtobj.parseDateTime();
\r
776 timeout = dtobj.getEpoch();
\r
779 if (timeout > 0 && now - lastAccess >= timeout) {
\r
780 m_log.info("session timed out (ID: %s)", key);
\r
781 throw RetryableProfileException("Your session has expired, and you must re-authenticate.");
\r
784 // Update storage expiration, if possible.
\r
786 m_storage->updateContext(key, now + m_cacheTimeout);
\r
788 catch (exception& ex) {
\r
789 m_log.error("failed to update session expiration: %s", ex.what());
\r
792 if (ver > curver) {
\r
793 // Send the record back.
\r
798 DDFJanitor jan(ret);
\r
802 else if (!strcmp(in.name(),"remove::"REMOTED_SESSION_CACHE)) {
\r
803 const char* key=in["key"].string();
\r
805 throw ListenerException("Required parameter missing for session removal.");
\r
807 remove(key,*(SPConfig::getConfig().getServiceProvider()->getApplication("default")),NULL);
\r
809 DDFJanitor jan(ret);
\r
812 else if (!strcmp(in.name(),"getAssertion::"REMOTED_SESSION_CACHE)) {
\r
813 const char* key=in["key"].string();
\r
814 const char* id=in["id"].string();
\r
816 throw ListenerException("Required parameters missing for assertion retrieval.");
\r
818 if (!m_storage->readText(key, id, &token, NULL))
\r
819 throw FatalProfileException("Assertion not found in cache.");
\r