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_nameid(NULL), m_cache(cache) {
\r
62 const char* nameid = obj["nameid"].string();
\r
64 // Parse and bind the document into an XMLObject.
\r
65 istringstream instr(nameid);
\r
66 DOMDocument* doc = XMLToolingConfig::getConfig().getParser().parse(instr);
\r
67 XercesJanitor<DOMDocument> janitor(doc);
\r
68 auto_ptr<saml2::NameID> n(saml2::NameIDBuilder::buildNameID());
\r
69 n->unmarshall(doc->getDocumentElement(), true);
\r
71 m_nameid = n.release();
\r
84 const char* getID() const {
\r
85 return m_obj.name();
\r
87 const char* getClientAddress() const {
\r
88 return m_obj["client_addr"].string();
\r
90 const char* getEntityID() const {
\r
91 return m_obj["entity_id"].string();
\r
93 const char* getAuthnInstant() const {
\r
94 return m_obj["authn_instant"].string();
\r
96 const opensaml::saml2::NameID* getNameID() const {
\r
99 const char* getSessionIndex() const {
\r
100 return m_obj["session_index"].string();
\r
102 const char* getAuthnContextClassRef() const {
\r
103 return m_obj["authncontext_class"].string();
\r
105 const char* getAuthnContextDeclRef() const {
\r
106 return m_obj["authncontext_decl"].string();
\r
108 const multimap<string,Attribute*>& getAttributes() const {
\r
109 if (m_attributes.empty())
\r
110 unmarshallAttributes();
\r
111 return m_attributes;
\r
113 const vector<const char*>& getAssertionIDs() const {
\r
114 if (m_ids.empty()) {
\r
115 DDF ids = m_obj["assertions"];
\r
116 DDF id = ids.first();
\r
117 while (id.isstring()) {
\r
118 m_ids.push_back(id.string());
\r
125 void addAttributes(const vector<Attribute*>& attributes);
\r
126 const Assertion* getAssertion(const char* id) const;
\r
127 void addAssertion(Assertion* assertion);
\r
130 void unmarshallAttributes() const;
\r
133 saml2::NameID* m_nameid;
\r
134 mutable multimap<string,Attribute*> m_attributes;
\r
135 mutable vector<const char*> m_ids;
\r
136 mutable map<string,Assertion*> m_tokens;
\r
140 class SSCache : public SessionCache, public virtual Remoted
\r
143 SSCache(const DOMElement* e);
\r
146 void receive(DDF& in, ostream& out);
\r
150 const Application& application,
\r
151 const char* client_addr=NULL,
\r
152 const saml2md::EntityDescriptor* issuer=NULL,
\r
153 const saml2::NameID* nameid=NULL,
\r
154 const char* authn_instant=NULL,
\r
155 const char* session_index=NULL,
\r
156 const char* authncontext_class=NULL,
\r
157 const char* authncontext_decl=NULL,
\r
158 const vector<const Assertion*>* tokens=NULL,
\r
159 const multimap<string,Attribute*>* attributes=NULL
\r
161 Session* find(const char* key, const Application& application, const char* client_addr=NULL, time_t* timeout=NULL);
\r
162 void remove(const char* key, const Application& application, const char* client_addr);
\r
165 StorageService* m_storage;
\r
168 SessionCache* SHIBSP_DLLLOCAL StorageServiceCacheFactory(const DOMElement* const & e)
\r
170 return new SSCache(e);
\r
173 static const XMLCh _StorageService[] = UNICODE_LITERAL_14(S,t,o,r,a,g,e,S,e,r,v,i,c,e);
\r
176 StoredSession::~StoredSession()
\r
180 for_each(m_attributes.begin(), m_attributes.end(), cleanup_pair<string,Attribute>());
\r
181 for_each(m_tokens.begin(), m_tokens.end(), cleanup_pair<string,Assertion>());
\r
184 void StoredSession::unmarshallAttributes() const
\r
186 Attribute* attribute;
\r
187 DDF attrs = m_obj["attributes"];
\r
188 DDF attr = attrs.first();
\r
189 while (!attr.isnull()) {
\r
191 attribute = Attribute::unmarshall(attr);
\r
192 m_attributes.insert(make_pair(attribute->getId(), attribute));
\r
193 if (m_cache->m_log.isDebugEnabled())
\r
194 m_cache->m_log.debug("unmarshalled attribute (ID: %s) with %d value%s",
\r
195 attribute->getId(), attr.first().integer(), attr.first().integer()!=1 ? "s" : "");
\r
197 catch (AttributeException& ex) {
\r
198 const char* id = attr.first().name();
\r
199 m_cache->m_log.error("error unmarshalling attribute (ID: %s): %s", id ? id : "none", ex.what());
\r
201 attr = attrs.next();
\r
205 void StoredSession::addAttributes(const vector<Attribute*>& attributes)
\r
208 xmltooling::NDC ndc("addAttributes");
\r
211 m_cache->m_log.debug("adding attributes to session (%s)", getID());
\r
216 DDF attrs = m_obj["attributes"];
\r
217 if (!attrs.islist())
\r
218 attrs = m_obj.addmember("attributes").list();
\r
219 for (vector<Attribute*>::const_iterator a=attributes.begin(); a!=attributes.end(); ++a) {
\r
220 attr = (*a)->marshall();
\r
224 // Tentatively increment the version.
\r
225 m_obj["version"].integer(m_obj["version"].integer()+1);
\r
229 string record(str.str());
\r
232 ver = m_cache->m_storage->updateText(getID(), "session", record.c_str(), 0, m_obj["version"].integer()-1);
\r
234 catch (exception&) {
\r
235 // Roll back modification to record.
\r
236 m_obj["version"].integer(m_obj["version"].integer()-1);
\r
237 vector<Attribute*>::size_type count = attributes.size();
\r
239 attrs.last().destroy();
\r
244 // Roll back modification to record.
\r
245 m_obj["version"].integer(m_obj["version"].integer()-1);
\r
246 vector<Attribute*>::size_type count = attributes.size();
\r
248 attrs.last().destroy();
\r
251 // Fatal problem with update.
\r
252 throw IOException("Unable to update stored session.");
\r
254 else if (ver < 0) {
\r
256 m_cache->m_log.warn("storage service indicates the record is out of sync, updating with a fresh copy...");
\r
257 ver = m_cache->m_storage->readText(getID(), "session", &record, NULL);
\r
259 m_cache->m_log.error("readText failed on StorageService for session (%s)", getID());
\r
260 throw IOException("Unable to read back stored session.");
\r
265 istringstream in(record);
\r
269 for_each(m_attributes.begin(), m_attributes.end(), cleanup_const_pair<string,Attribute>());
\r
270 m_attributes.clear();
\r
271 newobj["version"].integer(ver);
\r
277 } while (ver < 0); // negative indicates a sync issue so we retry
\r
279 TransactionLog* xlog = SPConfig::getConfig().getServiceProvider()->getTransactionLog();
\r
280 Locker locker(xlog);
\r
281 xlog->log.infoStream() <<
\r
282 "Added the following attributes to session (ID: " <<
\r
284 ") for (applicationId: " <<
\r
285 m_obj["application_id"].string() <<
\r
287 for (vector<Attribute*>::const_iterator a=attributes.begin(); a!=attributes.end(); ++a)
\r
288 xlog->log.infoStream() << "\t" << (*a)->getId() << " (" << (*a)->valueCount() << " values)";
\r
289 xlog->log.info("}");
\r
291 // We own them now, so clean them up.
\r
292 for_each(attributes.begin(), attributes.end(), xmltooling::cleanup<Attribute>());
\r
295 const Assertion* StoredSession::getAssertion(const char* id) const
\r
297 map<string,Assertion*>::const_iterator i = m_tokens.find(id);
\r
298 if (i!=m_tokens.end())
\r
302 if (!m_cache->m_storage->readText(getID(), id, &tokenstr, NULL))
\r
303 throw FatalProfileException("Assertion not found in cache.");
\r
305 // Parse and bind the document into an XMLObject.
\r
306 istringstream instr(tokenstr);
\r
307 DOMDocument* doc = XMLToolingConfig::getConfig().getParser().parse(instr);
\r
308 XercesJanitor<DOMDocument> janitor(doc);
\r
309 auto_ptr<XMLObject> xmlObject(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(), true));
\r
312 Assertion* token = dynamic_cast<Assertion*>(xmlObject.get());
\r
314 throw FatalProfileException("Request for cached assertion returned an unknown object type.");
\r
316 // Transfer ownership to us.
\r
317 xmlObject.release();
\r
318 m_tokens[id]=token;
\r
322 void StoredSession::addAssertion(Assertion* assertion)
\r
325 xmltooling::NDC ndc("addAssertion");
\r
329 throw FatalProfileException("Unknown object type passed to session for storage.");
\r
331 auto_ptr_char id(assertion->getID());
\r
333 m_cache->m_log.debug("adding assertion (%s) to session (%s)", id.get(), getID());
\r
336 if (!m_cache->m_storage->readText(getID(), "session", NULL, &exp))
\r
337 throw IOException("Unable to load expiration time for stored session.");
\r
339 ostringstream tokenstr;
\r
340 tokenstr << *assertion;
\r
341 m_cache->m_storage->createText(getID(), id.get(), tokenstr.str().c_str(), exp);
\r
345 DDF token = DDF(NULL).string(id.get());
\r
346 m_obj["assertions"].add(token);
\r
348 // Tentatively increment the version.
\r
349 m_obj["version"].integer(m_obj["version"].integer()+1);
\r
353 string record(str.str());
\r
356 ver = m_cache->m_storage->updateText(getID(), "session", record.c_str(), 0, m_obj["version"].integer()-1);
\r
358 catch (exception&) {
\r
360 m_obj["version"].integer(m_obj["version"].integer()-1);
\r
361 m_cache->m_storage->deleteText(getID(), id.get());
\r
367 m_obj["version"].integer(m_obj["version"].integer()-1);
\r
370 // Fatal problem with update.
\r
371 m_cache->m_log.error("updateText failed on StorageService for session (%s)", getID());
\r
372 m_cache->m_storage->deleteText(getID(), id.get());
\r
373 throw IOException("Unable to update stored session.");
\r
375 else if (ver < 0) {
\r
377 m_cache->m_log.warn("storage service indicates the record is out of sync, updating with a fresh copy...");
\r
378 ver = m_cache->m_storage->readText(getID(), "session", &record, NULL);
\r
380 m_cache->m_log.error("readText failed on StorageService for session (%s)", getID());
\r
381 m_cache->m_storage->deleteText(getID(), id.get());
\r
382 throw IOException("Unable to read back stored session.");
\r
387 istringstream in(record);
\r
391 for_each(m_attributes.begin(), m_attributes.end(), cleanup_const_pair<string,Attribute>());
\r
392 m_attributes.clear();
\r
393 newobj["version"].integer(ver);
\r
399 } while (ver < 0); // negative indicates a sync issue so we retry
\r
404 TransactionLog* xlog = SPConfig::getConfig().getServiceProvider()->getTransactionLog();
\r
405 Locker locker(xlog);
\r
407 "Added assertion (ID: %s) to session for (applicationId: %s) with (ID: %s)",
\r
408 id.get(), m_obj["application_id"].string(), getID()
\r
412 SSCache::SSCache(const DOMElement* e)
\r
413 : SessionCache(e), m_log(Category::getInstance(SHIBSP_LOGCAT".SessionCache")), m_storage(NULL)
\r
415 SPConfig& conf = SPConfig::getConfig();
\r
416 const XMLCh* tag = e ? e->getAttributeNS(NULL,_StorageService) : NULL;
\r
418 auto_ptr_char ssid(tag);
\r
419 m_storage = conf.getServiceProvider()->getStorageService(ssid.get());
\r
421 m_log.info("bound to StorageService (%s)", ssid.get());
\r
423 throw ConfigurationException("SessionCache unable to locate StorageService, check configuration.");
\r
426 ListenerService* listener=conf.getServiceProvider()->getListenerService(false);
\r
427 if (listener && conf.isEnabled(SPConfig::OutOfProcess)) {
\r
428 listener->regListener("find::"REMOTED_SESSION_CACHE"::SessionCache",this);
\r
429 listener->regListener("remove::"REMOTED_SESSION_CACHE"::SessionCache",this);
\r
430 listener->regListener("touch::"REMOTED_SESSION_CACHE"::SessionCache",this);
\r
431 listener->regListener("getAssertion::"REMOTED_SESSION_CACHE"::SessionCache",this);
\r
434 m_log.info("no ListenerService available, cache remoting disabled");
\r
438 SSCache::~SSCache()
\r
440 SPConfig& conf = SPConfig::getConfig();
\r
441 ListenerService* listener=conf.getServiceProvider()->getListenerService(false);
\r
442 if (listener && conf.isEnabled(SPConfig::OutOfProcess)) {
\r
443 listener->unregListener("find::"REMOTED_SESSION_CACHE"::SessionCache",this);
\r
444 listener->unregListener("remove::"REMOTED_SESSION_CACHE"::SessionCache",this);
\r
445 listener->unregListener("touch::"REMOTED_SESSION_CACHE"::SessionCache",this);
\r
446 listener->unregListener("getAssertion::"REMOTED_SESSION_CACHE"::SessionCache",this);
\r
450 string SSCache::insert(
\r
452 const Application& application,
\r
453 const char* client_addr,
\r
454 const saml2md::EntityDescriptor* issuer,
\r
455 const saml2::NameID* nameid,
\r
456 const char* authn_instant,
\r
457 const char* session_index,
\r
458 const char* authncontext_class,
\r
459 const char* authncontext_decl,
\r
460 const vector<const Assertion*>* tokens,
\r
461 const multimap<string,Attribute*>* attributes
\r
465 xmltooling::NDC ndc("insert");
\r
468 m_log.debug("creating new session");
\r
470 auto_ptr_char key(SAMLConfig::getConfig().generateIdentifier());
\r
472 // Store session properties in DDF.
\r
473 DDF obj = DDF(key.get()).structure();
\r
474 obj.addmember("version").integer(1);
\r
475 obj.addmember("application_id").string(application.getId());
\r
477 // On 64-bit Windows, time_t doesn't fit in a long, so I'm using ISO timestamps.
\r
478 #ifndef HAVE_GMTIME_R
\r
479 struct tm* ptime=gmtime(&expires);
\r
482 struct tm* ptime=gmtime_r(&expires,&res);
\r
485 strftime(timebuf,32,"%Y-%m-%dT%H:%M:%SZ",ptime);
\r
486 obj.addmember("expires").string(timebuf);
\r
489 obj.addmember("client_addr").string(client_addr);
\r
491 auto_ptr_char entity_id(issuer->getEntityID());
\r
492 obj.addmember("entity_id").string(entity_id.get());
\r
495 obj.addmember("authn_instant").string(authn_instant);
\r
497 obj.addmember("session_index").string(session_index);
\r
498 if (authncontext_class)
\r
499 obj.addmember("authncontext_class").string(authncontext_class);
\r
500 if (authncontext_decl)
\r
501 obj.addmember("authncontext_decl").string(authncontext_decl);
\r
504 ostringstream namestr;
\r
505 namestr << *nameid;
\r
506 obj.addmember("nameid").string(namestr.str().c_str());
\r
510 obj.addmember("assertions").list();
\r
511 for (vector<const Assertion*>::const_iterator t = tokens->begin(); t!=tokens->end(); ++t) {
\r
512 auto_ptr_char tokenid((*t)->getID());
\r
513 DDF tokid = DDF(NULL).string(tokenid.get());
\r
514 obj["assertions"].add(tokid);
\r
520 DDF attrlist = obj.addmember("attributes").list();
\r
521 for (multimap<string,Attribute*>::const_iterator a=attributes->begin(); a!=attributes->end(); ++a) {
\r
522 attr = a->second->marshall();
\r
523 attrlist.add(attr);
\r
527 ostringstream record;
\r
530 m_log.debug("storing new session...");
\r
531 time_t now = time(NULL);
\r
532 m_storage->createText(key.get(), "session", record.str().c_str(), now + m_cacheTimeout);
\r
535 for (vector<const Assertion*>::const_iterator t = tokens->begin(); t!=tokens->end(); ++t) {
\r
536 ostringstream tokenstr;
\r
538 auto_ptr_char tokenid((*t)->getID());
\r
539 m_storage->createText(key.get(), tokenid.get(), tokenstr.str().c_str(), now + m_cacheTimeout);
\r
542 catch (exception& ex) {
\r
543 m_log.error("error storing assertion along with session: %s", ex.what());
\r
547 const char* pid = obj["entity_id"].string();
\r
548 m_log.info("new session created: SessionID (%s) IdP (%s) Address (%s)", key.get(), pid ? pid : "none", client_addr);
\r
550 // Transaction Logging
\r
551 auto_ptr_char name(nameid ? nameid->getName() : NULL);
\r
552 TransactionLog* xlog = application.getServiceProvider().getTransactionLog();
\r
553 Locker locker(xlog);
\r
554 xlog->log.infoStream() <<
\r
555 "New session (ID: " <<
\r
557 ") with (applicationId: " <<
\r
558 application.getId() <<
\r
559 ") for principal from (IdP: " <<
\r
560 (pid ? pid : "none") <<
\r
561 ") at (ClientAddress: " <<
\r
562 (client_addr ? client_addr : "none") <<
\r
563 ") with (NameIdentifier: " <<
\r
564 (name.get() ? name.get() : "none") <<
\r
568 xlog->log.infoStream() <<
\r
569 "Cached the following attributes with session (ID: " <<
\r
571 ") for (applicationId: " <<
\r
572 application.getId() <<
\r
574 for (multimap<string,Attribute*>::const_iterator a=attributes->begin(); a!=attributes->end(); ++a)
\r
575 xlog->log.infoStream() << "\t" << a->second->getId() << " (" << a->second->valueCount() << " values)";
\r
576 xlog->log.info("}");
\r
582 Session* SSCache::find(const char* key, const Application& application, const char* client_addr, time_t* timeout)
\r
585 xmltooling::NDC ndc("find");
\r
588 m_log.debug("searching for session (%s)", key);
\r
592 int ver = m_storage->readText(key, "session", &record, &lastAccess);
\r
596 m_log.debug("reconstituting session and checking validity");
\r
599 istringstream in(record);
\r
602 if (!XMLString::equals(obj["application_id"].string(), application.getId())) {
\r
603 m_log.error("an application (%s) tried to access another application's session", application.getId());
\r
609 if (m_log.isDebugEnabled())
\r
610 m_log.debug("comparing client address %s against %s", client_addr, obj["client_addr"].string());
\r
611 if (strcmp(obj["client_addr"].string(),client_addr)) {
\r
612 m_log.warn("client address mismatch");
\r
613 remove(key, application, client_addr);
\r
614 RetryableProfileException ex(
\r
615 "Your IP address ($1) does not match the address recorded at the time the session was established.",
\r
616 params(1,client_addr)
\r
618 string eid(obj["entity_id"].string());
\r
622 MetadataProvider* m=application.getMetadataProvider();
\r
624 annotateException(&ex,m->getEntityDescriptor(eid.c_str(),false)); // throws it
\r
628 lastAccess -= m_cacheTimeout; // adjusts it back to the last time the record's timestamp was touched
\r
629 time_t now=time(NULL);
\r
631 if (timeout && *timeout > 0 && now - lastAccess >= *timeout) {
\r
632 m_log.info("session timed out (ID: %s)", key);
\r
633 remove(key, application, client_addr);
\r
634 RetryableProfileException ex("Your session has expired, and you must re-authenticate.");
\r
635 string eid(obj["entity_id"].string());
\r
639 MetadataProvider* m=application.getMetadataProvider();
\r
641 annotateException(&ex,m->getEntityDescriptor(eid.c_str(),false)); // throws it
\r
644 auto_ptr_XMLCh exp(obj["expires"].string());
\r
646 DateTime iso(exp.get());
\r
647 iso.parseDateTime();
\r
648 if (now > iso.getEpoch()) {
\r
649 m_log.info("session expired (ID: %s)", key);
\r
650 remove(key, application, client_addr);
\r
651 RetryableProfileException ex("Your session has expired, and you must re-authenticate.");
\r
652 string eid(obj["entity_id"].string());
\r
656 MetadataProvider* m=application.getMetadataProvider();
\r
658 annotateException(&ex,m->getEntityDescriptor(eid.c_str(),false)); // throws it
\r
663 // Update storage expiration, if possible.
\r
665 m_storage->updateContext(key, now + m_cacheTimeout);
\r
667 catch (exception& ex) {
\r
668 m_log.error("failed to update session expiration: %s", ex.what());
\r
672 // Finally build the Session object.
\r
674 return new StoredSession(this, obj);
\r
676 catch (exception&) {
\r
682 void SSCache::remove(const char* key, const Application& application, const char* client_addr)
\r
685 xmltooling::NDC ndc("remove");
\r
688 m_storage->deleteContext(key);
\r
689 m_log.info("removed session (%s)", key);
\r
691 TransactionLog* xlog = application.getServiceProvider().getTransactionLog();
\r
692 Locker locker(xlog);
\r
693 xlog->log.info("Destroyed session (applicationId: %s) (ID: %s)", application.getId(), key);
\r
696 void SSCache::receive(DDF& in, ostream& out)
\r
699 xmltooling::NDC ndc("receive");
\r
702 if (!strcmp(in.name(),"find::"REMOTED_SESSION_CACHE"::SessionCache")) {
\r
703 const char* key=in["key"].string();
\r
705 throw ListenerException("Required parameters missing for session removal.");
\r
707 // Do an unversioned read.
\r
710 if (!m_storage->readText(key, "session", &record, &lastAccess)) {
\r
712 DDFJanitor jan(ret);
\r
717 // Adjust for expiration to recover last access time and check timeout.
\r
718 lastAccess -= m_cacheTimeout;
\r
719 time_t now=time(NULL);
\r
721 // See if we need to check for a timeout.
\r
722 if (in["timeout"].string()) {
\r
723 time_t timeout = 0;
\r
724 auto_ptr_XMLCh dt(in["timeout"].string());
\r
725 DateTime dtobj(dt.get());
\r
726 dtobj.parseDateTime();
\r
727 timeout = dtobj.getEpoch();
\r
729 if (timeout > 0 && now - lastAccess >= timeout) {
\r
730 m_log.info("session timed out (ID: %s)", key);
\r
731 remove(key,*(SPConfig::getConfig().getServiceProvider()->getApplication("default")),NULL);
\r
732 throw RetryableProfileException("Your session has expired, and you must re-authenticate.");
\r
735 // Update storage expiration, if possible.
\r
737 m_storage->updateContext(key, now + m_cacheTimeout);
\r
739 catch (exception& ex) {
\r
740 m_log.error("failed to update session expiration: %s", ex.what());
\r
744 // Send the record back.
\r
747 else if (!strcmp(in.name(),"touch::"REMOTED_SESSION_CACHE"::SessionCache")) {
\r
748 const char* key=in["key"].string();
\r
750 throw ListenerException("Required parameters missing for session check.");
\r
752 // Do a versioned read.
\r
755 int curver = in["version"].integer();
\r
756 int ver = m_storage->readText(key, "session", &record, &lastAccess, curver);
\r
758 m_log.warn("unsuccessful versioned read of session (ID: %s), caches out of sync?", key);
\r
759 throw RetryableProfileException("Your session has expired, and you must re-authenticate.");
\r
762 // Adjust for expiration to recover last access time and check timeout.
\r
763 lastAccess -= m_cacheTimeout;
\r
764 time_t now=time(NULL);
\r
766 // See if we need to check for a timeout.
\r
767 time_t timeout = 0;
\r
768 auto_ptr_XMLCh dt(in["timeout"].string());
\r
770 DateTime dtobj(dt.get());
\r
771 dtobj.parseDateTime();
\r
772 timeout = dtobj.getEpoch();
\r
775 if (timeout > 0 && now - lastAccess >= timeout) {
\r
776 m_log.info("session timed out (ID: %s)", key);
\r
777 throw RetryableProfileException("Your session has expired, and you must re-authenticate.");
\r
780 // Update storage expiration, if possible.
\r
782 m_storage->updateContext(key, now + m_cacheTimeout);
\r
784 catch (exception& ex) {
\r
785 m_log.error("failed to update session expiration: %s", ex.what());
\r
788 if (ver > curver) {
\r
789 // Send the record back.
\r
794 DDFJanitor jan(ret);
\r
798 else if (!strcmp(in.name(),"remove::"REMOTED_SESSION_CACHE"::SessionCache")) {
\r
799 const char* key=in["key"].string();
\r
801 throw ListenerException("Required parameter missing for session removal.");
\r
803 remove(key,*(SPConfig::getConfig().getServiceProvider()->getApplication("default")),NULL);
\r
805 DDFJanitor jan(ret);
\r
808 else if (!strcmp(in.name(),"getAssertion::"REMOTED_SESSION_CACHE"::SessionCache")) {
\r
809 const char* key=in["key"].string();
\r
810 const char* id=in["id"].string();
\r
812 throw ListenerException("Required parameters missing for assertion retrieval.");
\r
814 if (!m_storage->readText(key, id, &token, NULL))
\r
815 throw FatalProfileException("Assertion not found in cache.");
\r