/*\r
- * Copyright 2001-2005 Internet2\r
+ * Copyright 2001-2007 Internet2\r
* \r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
class StoredSession : public virtual Session\r
{\r
public:\r
- StoredSession(SSCache* cache, const Application& app, DDF& obj)\r
- : m_appId(app.getId()), m_obj(obj), m_cache(cache) {\r
+ StoredSession(SSCache* cache, DDF& obj) : m_obj(obj), m_nameid(NULL), m_cache(cache) {\r
const char* nameid = obj["nameid"].string();\r
- if (!nameid)\r
- throw FatalProfileException("NameID missing from cached session.");\r
- \r
- // Parse and bind the document into an XMLObject.\r
- istringstream instr(nameid);\r
- DOMDocument* doc = XMLToolingConfig::getConfig().getParser().parse(instr); \r
- XercesJanitor<DOMDocument> janitor(doc);\r
- auto_ptr<saml2::NameID> n(saml2::NameIDBuilder::buildNameID());\r
- n->unmarshall(doc->getDocumentElement(), true);\r
- janitor.release();\r
- \r
- // TODO: Process attributes...\r
-\r
- m_nameid = n.release();\r
+ if (nameid) {\r
+ // Parse and bind the document into an XMLObject.\r
+ istringstream instr(nameid);\r
+ DOMDocument* doc = XMLToolingConfig::getConfig().getParser().parse(instr); \r
+ XercesJanitor<DOMDocument> janitor(doc);\r
+ auto_ptr<saml2::NameID> n(saml2::NameIDBuilder::buildNameID());\r
+ n->unmarshall(doc->getDocumentElement(), true);\r
+ janitor.release();\r
+ m_nameid = n.release();\r
+ }\r
}\r
\r
~StoredSession();\r
const char* getAuthnInstant() const {\r
return m_obj["authn_instant"].string();\r
}\r
- const opensaml::saml2::NameID& getNameID() const {\r
- return *m_nameid;\r
+ const opensaml::saml2::NameID* getNameID() const {\r
+ return m_nameid;\r
}\r
const char* getSessionIndex() const {\r
return m_obj["session_index"].string();\r
const char* getAuthnContextDeclRef() const {\r
return m_obj["authncontext_decl"].string();\r
}\r
- const vector<const Attribute*>& getAttributes() const {\r
+ const multimap<string,Attribute*>& getAttributes() const {\r
+ if (m_attributes.empty())\r
+ unmarshallAttributes();\r
return m_attributes;\r
}\r
const vector<const char*>& getAssertionIDs() const {\r
if (m_ids.empty()) {\r
- DDF id = m_obj["assertions"].first();\r
+ DDF ids = m_obj["assertions"];\r
+ DDF id = ids.first();\r
while (id.isstring()) {\r
- m_ids.push_back(id.name());\r
- id = id.next();\r
+ m_ids.push_back(id.string());\r
+ id = ids.next();\r
}\r
}\r
return m_ids;\r
}\r
\r
void addAttributes(const vector<Attribute*>& attributes);\r
- const RootObject* getAssertion(const char* id) const;\r
- void addAssertion(RootObject* assertion);\r
+ const Assertion* getAssertion(const char* id) const;\r
+ void addAssertion(Assertion* assertion);\r
\r
private:\r
- string m_appId;\r
+ void unmarshallAttributes() const;\r
+\r
DDF m_obj;\r
saml2::NameID* m_nameid;\r
- vector<const Attribute*> m_attributes;\r
+ mutable multimap<string,Attribute*> m_attributes;\r
mutable vector<const char*> m_ids;\r
- mutable map<string,RootObject*> m_tokens;\r
+ mutable map<string,Assertion*> m_tokens;\r
SSCache* m_cache;\r
};\r
\r
{\r
public:\r
SSCache(const DOMElement* e);\r
- ~SSCache() {}\r
+ ~SSCache();\r
\r
void receive(DDF& in, ostream& out);\r
\r
string insert(\r
time_t expires,\r
const Application& application,\r
- const char* client_addr,\r
- const saml2md::EntityDescriptor* issuer,\r
- const saml2::NameID& nameid,\r
+ const char* client_addr=NULL,\r
+ const saml2md::EntityDescriptor* issuer=NULL,\r
+ const saml2::NameID* nameid=NULL,\r
const char* authn_instant=NULL,\r
const char* session_index=NULL,\r
const char* authncontext_class=NULL,\r
const char* authncontext_decl=NULL,\r
- const RootObject* ssoToken=NULL,\r
- const vector<Attribute*>* attributes=NULL\r
+ const vector<const Assertion*>* tokens=NULL,\r
+ const multimap<string,Attribute*>* attributes=NULL\r
);\r
Session* find(const char* key, const Application& application, const char* client_addr=NULL, time_t timeout=0);\r
void remove(const char* key, const Application& application, const char* client_addr);\r
{\r
m_obj.destroy();\r
delete m_nameid;\r
- for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());\r
- for_each(m_tokens.begin(), m_tokens.end(), xmltooling::cleanup_pair<string,RootObject>());\r
+ for_each(m_attributes.begin(), m_attributes.end(), cleanup_pair<string,Attribute>());\r
+ for_each(m_tokens.begin(), m_tokens.end(), cleanup_pair<string,Assertion>());\r
+}\r
+\r
+void StoredSession::unmarshallAttributes() const\r
+{\r
+ Attribute* attribute;\r
+ DDF attrs = m_obj["attributes"];\r
+ DDF attr = attrs.first();\r
+ while (!attr.isnull()) {\r
+ try {\r
+ attribute = Attribute::unmarshall(attr);\r
+ m_attributes.insert(make_pair(attribute->getId(), attribute));\r
+ if (m_cache->m_log.isDebugEnabled())\r
+ m_cache->m_log.debug("unmarshalled attribute (ID: %s) with %d value%s",\r
+ attribute->getId(), attr.first().integer(), attr.first().integer()!=1 ? "s" : "");\r
+ }\r
+ catch (AttributeException& ex) {\r
+ const char* id = attr.first().name();\r
+ m_cache->m_log.error("error unmarshalling attribute (ID: %s): %s", id ? id : "none", ex.what());\r
+ }\r
+ attr = attrs.next();\r
+ }\r
}\r
\r
void StoredSession::addAttributes(const vector<Attribute*>& attributes)\r
str << m_obj;\r
string record(str.str()); \r
\r
- ver = m_cache->m_storage->updateText(m_appId.c_str(), m_obj.name(), record.c_str(), 0, m_obj["version"].integer()-1);\r
+ try {\r
+ ver = m_cache->m_storage->updateText(m_obj.name(), "session", record.c_str(), 0, m_obj["version"].integer()-1);\r
+ }\r
+ catch (exception&) {\r
+ // Roll back modification to record.\r
+ m_obj["version"].integer(m_obj["version"].integer()-1);\r
+ vector<Attribute*>::size_type count = attributes.size();\r
+ while (count--)\r
+ attrs.last().destroy(); \r
+ throw;\r
+ }\r
+\r
if (ver <= 0) {\r
// Roll back modification to record.\r
m_obj["version"].integer(m_obj["version"].integer()-1);\r
}\r
if (!ver) {\r
// Fatal problem with update.\r
- m_cache->m_log.error("updateText failed on StorageService for session (%s)", m_obj.name());\r
throw IOException("Unable to update stored session.");\r
}\r
else if (ver < 0) {\r
// Out of sync.\r
m_cache->m_log.warn("storage service indicates the record is out of sync, updating with a fresh copy...");\r
- ver = m_cache->m_storage->readText(m_appId.c_str(), m_obj.name(), &record, NULL);\r
+ ver = m_cache->m_storage->readText(m_obj.name(), "session", &record, NULL);\r
if (!ver) {\r
- m_cache->m_log.error("updateText failed on StorageService for session (%s)", m_obj.name());\r
- throw IOException("Unable to update stored session.");\r
+ m_cache->m_log.error("readText failed on StorageService for session (%s)", m_obj.name());\r
+ throw IOException("Unable to read back stored session.");\r
}\r
\r
// Reset object.\r
istringstream in(record);\r
in >> newobj;\r
\r
- m_obj.destroy();\r
m_ids.clear();\r
- for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());\r
+ for_each(m_attributes.begin(), m_attributes.end(), cleanup_const_pair<string,Attribute>());\r
m_attributes.clear();\r
newobj["version"].integer(ver);\r
+ m_obj.destroy();\r
m_obj = newobj;\r
- // TODO: handle attributes\r
- \r
+\r
ver = -1;\r
}\r
} while (ver < 0); // negative indicates a sync issue so we retry\r
\r
- // Transfer ownership to us.\r
- m_attributes.insert(m_attributes.end(), attributes.begin(), attributes.end());\r
-\r
TransactionLog* xlog = SPConfig::getConfig().getServiceProvider()->getTransactionLog();\r
Locker locker(xlog);\r
xlog->log.infoStream() <<\r
"Added the following attributes to session (ID: " <<\r
m_obj.name() <<\r
") for (applicationId: " <<\r
- m_appId.c_str() <<\r
+ m_obj["application_id"].string() <<\r
") {";\r
for (vector<Attribute*>::const_iterator a=attributes.begin(); a!=attributes.end(); ++a)\r
xlog->log.infoStream() << "\t" << (*a)->getId() << " (" << (*a)->valueCount() << " values)";\r
xlog->log.info("}");\r
+\r
+ // We own them now, so clean them up.\r
+ for_each(attributes.begin(), attributes.end(), xmltooling::cleanup<Attribute>());\r
}\r
\r
-const RootObject* StoredSession::getAssertion(const char* id) const\r
+const Assertion* StoredSession::getAssertion(const char* id) const\r
{\r
- map<string,RootObject*>::const_iterator i = m_tokens.find(id);\r
+ map<string,Assertion*>::const_iterator i = m_tokens.find(id);\r
if (i!=m_tokens.end())\r
return i->second;\r
\r
- // Parse and bind the document into an XMLObject.\r
- const char* tokenstr = m_obj["assertions"][id].string();\r
- if (!tokenstr)\r
+ string tokenstr;\r
+ if (!m_cache->m_storage->readText(m_obj.name(), id, &tokenstr, NULL))\r
throw FatalProfileException("Assertion not found in cache.");\r
+\r
+ // Parse and bind the document into an XMLObject.\r
istringstream instr(tokenstr);\r
DOMDocument* doc = XMLToolingConfig::getConfig().getParser().parse(instr); \r
XercesJanitor<DOMDocument> janitor(doc);\r
auto_ptr<XMLObject> xmlObject(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(), true));\r
janitor.release();\r
\r
- RootObject* token = dynamic_cast<RootObject*>(xmlObject.get());\r
- if (!token || !token->isAssertion())\r
+ Assertion* token = dynamic_cast<Assertion*>(xmlObject.get());\r
+ if (!token)\r
throw FatalProfileException("Request for cached assertion returned an unknown object type.");\r
\r
// Transfer ownership to us.\r
return token;\r
}\r
\r
-void StoredSession::addAssertion(RootObject* assertion)\r
+void StoredSession::addAssertion(Assertion* assertion)\r
{\r
#ifdef _DEBUG\r
xmltooling::NDC ndc("addAssertion");\r
#endif\r
\r
- if (!assertion || !assertion->isAssertion())\r
+ if (!assertion)\r
throw FatalProfileException("Unknown object type passed to session for storage.");\r
\r
auto_ptr_char id(assertion->getID());\r
\r
m_cache->m_log.debug("adding assertion (%s) to session (%s)", id.get(), m_obj.name());\r
\r
- ostringstream os;\r
- os << *assertion;\r
+ time_t exp;\r
+ if (!m_cache->m_storage->readText(m_obj.name(), "session", NULL, &exp))\r
+ throw IOException("Unable to load expiration time for stored session.");\r
+\r
+ ostringstream tokenstr;\r
+ tokenstr << *assertion;\r
+ m_cache->m_storage->createText(m_obj.name(), id.get(), tokenstr.str().c_str(), exp);\r
\r
int ver;\r
do {\r
- DDF token = m_obj["assertions"];\r
- if (!token.isstruct())\r
- token = m_obj.addmember("assertions").structure();\r
- token = token.addmember(id.get()).string(os.str().c_str());\r
+ DDF token = DDF(NULL).string(id.get());\r
+ m_obj["assertions"].add(token);\r
\r
// Tentatively increment the version.\r
m_obj["version"].integer(m_obj["version"].integer()+1);\r
str << m_obj;\r
string record(str.str()); \r
\r
- ver = m_cache->m_storage->updateText(m_appId.c_str(), m_obj.name(), record.c_str(), 0, m_obj["version"].integer()-1);\r
+ try {\r
+ ver = m_cache->m_storage->updateText(m_obj.name(), "session", record.c_str(), 0, m_obj["version"].integer()-1);\r
+ }\r
+ catch (exception&) {\r
+ token.destroy();\r
+ m_obj["version"].integer(m_obj["version"].integer()-1);\r
+ m_cache->m_storage->deleteText(m_obj.name(), id.get());\r
+ throw;\r
+ }\r
+\r
if (ver <= 0) {\r
token.destroy();\r
m_obj["version"].integer(m_obj["version"].integer()-1);\r
if (!ver) {\r
// Fatal problem with update.\r
m_cache->m_log.error("updateText failed on StorageService for session (%s)", m_obj.name());\r
+ m_cache->m_storage->deleteText(m_obj.name(), id.get());\r
throw IOException("Unable to update stored session.");\r
}\r
else if (ver < 0) {\r
// Out of sync.\r
m_cache->m_log.warn("storage service indicates the record is out of sync, updating with a fresh copy...");\r
- ver = m_cache->m_storage->readText(m_appId.c_str(), m_obj.name(), &record, NULL);\r
+ ver = m_cache->m_storage->readText(m_obj.name(), "session", &record, NULL);\r
if (!ver) {\r
- m_cache->m_log.error("updateText failed on StorageService for session (%s)", m_obj.name());\r
- throw IOException("Unable to update stored session.");\r
+ m_cache->m_log.error("readText failed on StorageService for session (%s)", m_obj.name());\r
+ m_cache->m_storage->deleteText(m_obj.name(), id.get());\r
+ throw IOException("Unable to read back stored session.");\r
}\r
\r
// Reset object.\r
istringstream in(record);\r
in >> newobj;\r
\r
- m_obj.destroy();\r
m_ids.clear();\r
- for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());\r
+ for_each(m_attributes.begin(), m_attributes.end(), cleanup_const_pair<string,Attribute>());\r
m_attributes.clear();\r
newobj["version"].integer(ver);\r
+ m_obj.destroy();\r
m_obj = newobj;\r
- // TODO: handle attributes\r
\r
ver = -1;\r
}\r
} while (ver < 0); // negative indicates a sync issue so we retry\r
\r
+ m_ids.clear();\r
delete assertion;\r
\r
TransactionLog* xlog = SPConfig::getConfig().getServiceProvider()->getTransactionLog();\r
Locker locker(xlog);\r
xlog->log.info(\r
"Added assertion (ID: %s) to session for (applicationId: %s) with (ID: %s)",\r
- id.get(), m_appId.c_str(), m_obj.name()\r
+ id.get(), m_obj["application_id"].string(), m_obj.name()\r
);\r
}\r
\r
\r
ListenerService* listener=conf.getServiceProvider()->getListenerService(false);\r
if (listener && conf.isEnabled(SPConfig::OutOfProcess)) {\r
- listener->regListener("insert::"REMOTED_SESSION_CACHE,this);\r
- listener->regListener("find::"REMOTED_SESSION_CACHE,this);\r
- listener->regListener("remove::"REMOTED_SESSION_CACHE,this);\r
+ listener->regListener("insert::"REMOTED_SESSION_CACHE"::SessionCache",this);\r
+ listener->regListener("find::"REMOTED_SESSION_CACHE"::SessionCache",this);\r
+ listener->regListener("remove::"REMOTED_SESSION_CACHE"::SessionCache",this);\r
+ listener->regListener("touch::"REMOTED_SESSION_CACHE"::SessionCache",this);\r
+ listener->regListener("getAssertion::"REMOTED_SESSION_CACHE"::SessionCache",this);\r
}\r
else {\r
- m_log.info("no ListenerService available, cache remoting is disabled");\r
+ m_log.info("no ListenerService available, cache remoting disabled");\r
+ }\r
+}\r
+\r
+SSCache::~SSCache()\r
+{\r
+ SPConfig& conf = SPConfig::getConfig();\r
+ ListenerService* listener=conf.getServiceProvider()->getListenerService(false);\r
+ if (listener && conf.isEnabled(SPConfig::OutOfProcess)) {\r
+ listener->unregListener("insert::"REMOTED_SESSION_CACHE"::SessionCache",this);\r
+ listener->unregListener("find::"REMOTED_SESSION_CACHE"::SessionCache",this);\r
+ listener->unregListener("remove::"REMOTED_SESSION_CACHE"::SessionCache",this);\r
+ listener->unregListener("touch::"REMOTED_SESSION_CACHE"::SessionCache",this);\r
+ listener->unregListener("getAssertion::"REMOTED_SESSION_CACHE"::SessionCache",this);\r
}\r
}\r
\r
const Application& application,\r
const char* client_addr,\r
const saml2md::EntityDescriptor* issuer,\r
- const saml2::NameID& nameid,\r
+ const saml2::NameID* nameid,\r
const char* authn_instant,\r
const char* session_index,\r
const char* authncontext_class,\r
const char* authncontext_decl,\r
- const RootObject* ssoToken,\r
- const vector<Attribute*>* attributes\r
+ const vector<const Assertion*>* tokens,\r
+ const multimap<string,Attribute*>* attributes\r
)\r
{\r
#ifdef _DEBUG\r
// Store session properties in DDF.\r
DDF obj = DDF(key.get()).structure();\r
obj.addmember("version").integer(1);\r
+ obj.addmember("application_id").string(application.getId());\r
if (expires > 0) {\r
// On 64-bit Windows, time_t doesn't fit in a long, so I'm using ISO timestamps. \r
#ifndef HAVE_GMTIME_R\r
strftime(timebuf,32,"%Y-%m-%dT%H:%M:%SZ",ptime);\r
obj.addmember("expires").string(timebuf);\r
}\r
- obj.addmember("client_addr").string(client_addr);\r
+ if (client_addr)\r
+ obj.addmember("client_addr").string(client_addr);\r
if (issuer) {\r
auto_ptr_char entity_id(issuer->getEntityID());\r
obj.addmember("entity_id").string(entity_id.get());\r
if (authncontext_decl)\r
obj.addmember("authncontext_decl").string(authncontext_decl);\r
\r
- ostringstream namestr;\r
- namestr << nameid;\r
- obj.addmember("nameid").string(namestr.str().c_str());\r
- \r
- if (ssoToken) {\r
- ostringstream tokenstr;\r
- tokenstr << *ssoToken;\r
- auto_ptr_char tokenid(ssoToken->getID());\r
- obj.addmember("assertions").structure().addmember(tokenid.get()).string(tokenstr.str().c_str());\r
+ if (nameid) {\r
+ ostringstream namestr;\r
+ namestr << *nameid;\r
+ obj.addmember("nameid").string(namestr.str().c_str());\r
+ }\r
+\r
+ if (tokens) {\r
+ obj.addmember("assertions").list();\r
+ for (vector<const Assertion*>::const_iterator t = tokens->begin(); t!=tokens->end(); ++t) {\r
+ auto_ptr_char tokenid((*t)->getID());\r
+ DDF tokid = DDF(NULL).string(tokenid.get());\r
+ obj["assertions"].add(tokid);\r
+ }\r
}\r
\r
if (attributes) {\r
DDF attr;\r
DDF attrlist = obj.addmember("attributes").list();\r
- for (vector<Attribute*>::const_iterator a=attributes->begin(); a!=attributes->end(); ++a) {\r
- attr = (*a)->marshall();\r
+ for (multimap<string,Attribute*>::const_iterator a=attributes->begin(); a!=attributes->end(); ++a) {\r
+ attr = a->second->marshall();\r
attrlist.add(attr);\r
}\r
}\r
record << obj;\r
\r
m_log.debug("storing new session...");\r
- m_storage->createText(application.getId(), key.get(), record.str().c_str(), time(NULL) + m_cacheTimeout);\r
+ time_t now = time(NULL);\r
+ m_storage->createText(key.get(), "session", record.str().c_str(), now + m_cacheTimeout);\r
+ if (tokens) {\r
+ try {\r
+ for (vector<const Assertion*>::const_iterator t = tokens->begin(); t!=tokens->end(); ++t) {\r
+ ostringstream tokenstr;\r
+ tokenstr << *(*t);\r
+ auto_ptr_char tokenid((*t)->getID());\r
+ m_storage->createText(key.get(), tokenid.get(), tokenstr.str().c_str(), now + m_cacheTimeout);\r
+ }\r
+ }\r
+ catch (exception& ex) {\r
+ m_log.error("error storing assertion along with session: %s", ex.what());\r
+ }\r
+ }\r
+\r
const char* pid = obj["entity_id"].string();\r
m_log.debug("new session created: SessionID (%s) IdP (%s) Address (%s)", key.get(), pid ? pid : "none", client_addr);\r
\r
// Transaction Logging\r
- auto_ptr_char name(nameid.getName());\r
- TransactionLog* xlog = SPConfig::getConfig().getServiceProvider()->getTransactionLog();\r
+ auto_ptr_char name(nameid ? nameid->getName() : NULL);\r
+ TransactionLog* xlog = application.getServiceProvider().getTransactionLog();\r
Locker locker(xlog);\r
xlog->log.infoStream() <<\r
"New session (ID: " <<\r
") for principal from (IdP: " <<\r
(pid ? pid : "none") <<\r
") at (ClientAddress: " <<\r
- client_addr <<\r
+ (client_addr ? client_addr : "none") <<\r
") with (NameIdentifier: " <<\r
- name.get() <<\r
+ (name.get() ? name.get() : "none") <<\r
")";\r
\r
+ if (attributes) {\r
+ xlog->log.infoStream() <<\r
+ "Cached the following attributes with session (ID: " <<\r
+ key.get() <<\r
+ ") for (applicationId: " <<\r
+ application.getId() <<\r
+ ") {";\r
+ for (multimap<string,Attribute*>::const_iterator a=attributes->begin(); a!=attributes->end(); ++a)\r
+ xlog->log.infoStream() << "\t" << a->second->getId() << " (" << a->second->valueCount() << " values)";\r
+ xlog->log.info("}");\r
+ for_each(attributes->begin(), attributes->end(), cleanup_pair<string,Attribute>());\r
+ }\r
+\r
return key.get();\r
}\r
\r
\r
time_t lastAccess;\r
string record;\r
- int ver = m_storage->readText(application.getId(), key, &record, &lastAccess);\r
+ int ver = m_storage->readText(key, "session", &record, &lastAccess);\r
if (!ver)\r
return NULL;\r
\r
- m_log.debug("reconstituting session and checking for validity");\r
+ m_log.debug("reconstituting session and checking validity");\r
\r
DDF obj;\r
istringstream in(record);\r
in >> obj;\r
\r
- lastAccess -= m_cacheTimeout; // adjusts it back to the last time the record's timestamp was touched\r
- \r
+ if (!XMLString::equals(obj["application_id"].string(), application.getId())) {\r
+ m_log.error("an application (%s) tried to access another application's session", application.getId());\r
+ obj.destroy();\r
+ return NULL;\r
+ }\r
+\r
if (client_addr) {\r
if (m_log.isDebugEnabled())\r
m_log.debug("comparing client address %s against %s", client_addr, obj["client_addr"].string());\r
if (strcmp(obj["client_addr"].string(),client_addr)) {\r
m_log.warn("client address mismatch");\r
+ remove(key, application, client_addr);\r
RetryableProfileException ex(\r
"Your IP address ($1) does not match the address recorded at the time the session was established.",\r
params(1,client_addr)\r
}\r
}\r
\r
+ lastAccess -= m_cacheTimeout; // adjusts it back to the last time the record's timestamp was touched\r
time_t now=time(NULL);\r
\r
if (timeout > 0 && now - lastAccess >= timeout) {\r
m_log.info("session timed out (ID: %s)", key);\r
+ remove(key, application, client_addr);\r
RetryableProfileException ex("Your session has expired, and you must re-authenticate.");\r
string eid(obj["entity_id"].string());\r
obj.destroy();\r
iso.parseDateTime();\r
if (now > iso.getEpoch()) {\r
m_log.info("session expired (ID: %s)", key);\r
+ remove(key, application, client_addr);\r
RetryableProfileException ex("Your session has expired, and you must re-authenticate.");\r
string eid(obj["entity_id"].string());\r
obj.destroy();\r
}\r
\r
// Update storage expiration, if possible.\r
- if (!m_storage->updateText(application.getId(), key, NULL, now + m_cacheTimeout))\r
- m_log.error("failed to update record expiration");\r
+ try {\r
+ m_storage->updateContext(key, now + m_cacheTimeout);\r
+ }\r
+ catch (exception& ex) {\r
+ m_log.error("failed to update session expiration: %s", ex.what());\r
+ }\r
\r
// Finally build the Session object.\r
try {\r
- return new StoredSession(this, application, obj);\r
+ return new StoredSession(this, obj);\r
}\r
catch (exception&) {\r
obj.destroy();\r
\r
m_log.debug("removing session (%s)", key);\r
\r
- m_storage->deleteText(application.getId(), key);\r
+ m_storage->deleteContext(key);\r
\r
- TransactionLog* xlog = SPConfig::getConfig().getServiceProvider()->getTransactionLog();\r
+ TransactionLog* xlog = application.getServiceProvider().getTransactionLog();\r
Locker locker(xlog);\r
xlog->log.info("Destroyed session (applicationId: %s) (ID: %s)", application.getId(), key);\r
}\r
xmltooling::NDC ndc("receive");\r
#endif\r
\r
- // Find application.\r
- ServiceProvider* sp = SPConfig::getConfig().getServiceProvider(); \r
- Locker confLocker(sp);\r
- const char* aid=in["application_id"].string();\r
- const Application* app=aid ? sp->getApplication(aid) : NULL;\r
- if (!app) {\r
- // Something's horribly wrong.\r
- m_log.error("couldn't find application (%s) for session", aid ? aid : "(missing)");\r
- throw ConfigurationException("Unable to locate application for session, deleted?");\r
- }\r
-\r
- if (!strcmp(in.name(),"insert::"REMOTED_SESSION_CACHE)) {\r
- in["application_id"].destroy();\r
+ if (!strcmp(in.name(),"insert::"REMOTED_SESSION_CACHE"::SessionCache")) {\r
auto_ptr_char key(SAMLConfig::getConfig().generateIdentifier());\r
in.name(key.get());\r
+\r
+ DDF tokens = in["tokens"].remove();\r
+ DDFJanitor tjan(tokens);\r
\r
m_log.debug("storing new session...");\r
ostringstream record;\r
record << in;\r
- m_storage->createText(app->getId(), key.get(), record.str().c_str(), time(NULL) + m_cacheTimeout);\r
+ time_t now = time(NULL);\r
+ m_storage->createText(key.get(), "session", record.str().c_str(), now + m_cacheTimeout);\r
+ if (tokens.islist()) {\r
+ try {\r
+ DDF token = tokens.first();\r
+ while (token.isstring()) {\r
+ m_storage->createText(key.get(), token.name(), token.string(), now + m_cacheTimeout);\r
+ token = tokens.next();\r
+ }\r
+ }\r
+ catch (IOException& ex) {\r
+ m_log.error("error storing assertion along with session: %s", ex.what());\r
+ }\r
+ }\r
const char* pid = in["entity_id"].string();\r
m_log.debug("new session created: SessionID (%s) IdP (%s) Address (%s)", key.get(), pid ? pid : "none", in["client_addr"].string());\r
\r
ret.addmember("key").string(key.get());\r
out << ret;\r
}\r
- else if (!strcmp(in.name(),"find::"REMOTED_SESSION_CACHE)) {\r
+ else if (!strcmp(in.name(),"find::"REMOTED_SESSION_CACHE"::SessionCache")) {\r
const char* key=in["key"].string();\r
if (!key)\r
throw ListenerException("Required parameters missing for session removal.");\r
// Do an unversioned read.\r
string record;\r
time_t lastAccess;\r
- if (!m_storage->readText(aid, key, &record, &lastAccess)) {\r
+ if (!m_storage->readText(key, "session", &record, &lastAccess)) {\r
DDF ret(NULL);\r
DDFJanitor jan(ret);\r
out << ret;\r
\r
if (timeout > 0 && now - lastAccess >= timeout) {\r
m_log.info("session timed out (ID: %s)", key);\r
+ remove(key,*(SPConfig::getConfig().getServiceProvider()->getApplication("default")),NULL);\r
throw RetryableProfileException("Your session has expired, and you must re-authenticate.");\r
} \r
\r
// Update storage expiration, if possible.\r
- if (!m_storage->updateText(aid, key, NULL, now + m_cacheTimeout)) \r
- m_log.error("failed to update record expiration");\r
+ try {\r
+ m_storage->updateContext(key, now + m_cacheTimeout);\r
+ }\r
+ catch (exception& ex) {\r
+ m_log.error("failed to update session expiration: %s", ex.what());\r
+ }\r
\r
// Send the record back.\r
out << record;\r
}\r
- else if (!strcmp(in.name(),"touch::"REMOTED_SESSION_CACHE)) {\r
+ else if (!strcmp(in.name(),"touch::"REMOTED_SESSION_CACHE"::SessionCache")) {\r
const char* key=in["key"].string();\r
if (!key)\r
throw ListenerException("Required parameters missing for session check.");\r
string record;\r
time_t lastAccess;\r
int curver = in["version"].integer();\r
- int ver = m_storage->readText(aid, key, &record, &lastAccess, curver);\r
+ int ver = m_storage->readText(key, "session", &record, &lastAccess, curver);\r
if (ver == 0) {\r
m_log.warn("unsuccessful versioned read of session (ID: %s), caches out of sync?", key);\r
throw RetryableProfileException("Your session has expired, and you must re-authenticate.");\r
} \r
\r
// Update storage expiration, if possible.\r
- if (!m_storage->updateText(aid, key, NULL, now + m_cacheTimeout)) \r
- m_log.error("failed to update record expiration");\r
+ try {\r
+ m_storage->updateContext(key, now + m_cacheTimeout);\r
+ }\r
+ catch (exception& ex) {\r
+ m_log.error("failed to update session expiration: %s", ex.what());\r
+ }\r
\r
if (ver > curver) {\r
// Send the record back.\r
out << ret;\r
}\r
}\r
- else if (!strcmp(in.name(),"remove::"REMOTED_SESSION_CACHE)) {\r
+ else if (!strcmp(in.name(),"remove::"REMOTED_SESSION_CACHE"::SessionCache")) {\r
const char* key=in["key"].string();\r
- const char* client_addr=in["client_addr"].string();\r
- if (!key || !client_addr)\r
- throw ListenerException("Required parameters missing for session removal.");\r
+ if (!key)\r
+ throw ListenerException("Required parameter missing for session removal.");\r
\r
- remove(key,*app,client_addr);\r
+ remove(key,*(SPConfig::getConfig().getServiceProvider()->getApplication("default")),NULL);\r
DDF ret(NULL);\r
DDFJanitor jan(ret);\r
out << ret;\r
}\r
+ else if (!strcmp(in.name(),"getAssertion::"REMOTED_SESSION_CACHE"::SessionCache")) {\r
+ const char* key=in["key"].string();\r
+ const char* id=in["id"].string();\r
+ if (!key || !id)\r
+ throw ListenerException("Required parameters missing for assertion retrieval.");\r
+ string token;\r
+ if (!m_storage->readText(key, id, &token, NULL))\r
+ throw FatalProfileException("Assertion not found in cache.");\r
+ out << token;\r
+ }\r
}\r