X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=saml%2Fbinding%2Fimpl%2FArtifactMap.cpp;h=c22c6ef7eda495ad6973fb86e5c8da541a4afc8f;hb=980a4a1e781a297075b50bb689c4eb2a4c226e17;hp=2abaecc6942dac02ae9f56ec6c11b6ebeee0c84a;hpb=0559a5cb760882cbe43382dfacfd0a028ade1069;p=shibboleth%2Fcpp-opensaml.git diff --git a/saml/binding/impl/ArtifactMap.cpp b/saml/binding/impl/ArtifactMap.cpp index 2abaecc..c22c6ef 100644 --- a/saml/binding/impl/ArtifactMap.cpp +++ b/saml/binding/impl/ArtifactMap.cpp @@ -49,6 +49,7 @@ namespace opensaml { } void storeContent(XMLObject* content, const SAMLArtifact* artifact, const char* relyingParty, int TTL); XMLObject* retrieveContent(const SAMLArtifact* artifact, const char* relyingParty); + string getRelyingParty(const SAMLArtifact* artifact); private: struct SAML_DLLLOCAL Mapping { @@ -105,7 +106,7 @@ void ArtifactMappings::storeContent(XMLObject* content, const SAMLArtifact* arti if (relyingParty) m.m_relying = relyingParty; m.m_expires = now + TTL; - m_expMap.insert(make_pair(m.m_expires,hexed)); + m_expMap.insert(pair(m.m_expires,hexed)); } XMLObject* ArtifactMappings::retrieveContent(const SAMLArtifact* artifact, const char* relyingParty) @@ -140,8 +141,16 @@ XMLObject* ArtifactMappings::retrieveContent(const SAMLArtifact* artifact, const return ret; } +string ArtifactMappings::getRelyingParty(const SAMLArtifact* artifact) +{ + map::iterator i=m_artMap.find(SAMLArtifact::toHex(artifact->getMessageHandle())); + if (i==m_artMap.end()) + throw BindingException("Requested artifact not in map or may have expired."); + return i->second.m_relying; +} + ArtifactMap::ArtifactMap(xmltooling::StorageService* storage, const char* context, unsigned int artifactTTL) - : m_storage(storage), m_context(context ? context : "opensaml::ArtifactMap"), m_mappings(NULL), m_artifactTTL(artifactTTL) + : m_storage(storage), m_context((context && *context) ? context : "opensaml::ArtifactMap"), m_mappings(NULL), m_artifactTTL(artifactTTL) { if (!m_storage) m_mappings = new ArtifactMappings(); @@ -154,6 +163,8 @@ ArtifactMap::ArtifactMap(const DOMElement* e, xmltooling::StorageService* storag auto_ptr_char c(e->getAttributeNS(NULL, context)); if (c.get() && *c.get()) m_context = c.get(); + else + m_context = "opensaml::ArtifactMap"; const XMLCh* TTL = e->getAttributeNS(NULL, artifactTTL); if (TTL) { @@ -206,21 +217,22 @@ XMLObject* ArtifactMap::retrieveContent(const SAMLArtifact* artifact, const char #ifdef _DEBUG xmltooling::NDC ndc("retrieveContent"); #endif + Category& log=Category::getInstance(SAML_LOGCAT".ArtifactMap"); if (!m_storage) return m_mappings->retrieveContent(artifact, relyingParty); + // Read the mapping and then delete it. string xmlbuf; string key = SAMLArtifact::toHex(artifact->getMessageHandle()); if (!m_storage->readText(m_context.c_str(), key.c_str(), &xmlbuf)) throw BindingException("Artifact not found in mapping database."); + m_storage->deleteText(m_context.c_str(), key.c_str()); + // Parse the data back into XML. istringstream is(xmlbuf); DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(is); XercesJanitor janitor(doc); - - Category& log=Category::getInstance(SAML_LOGCAT".ArtifactMap"); - m_storage->deleteText(m_context.c_str(), key.c_str()); // Check the root element. DOMElement* messageRoot = doc->getDocumentElement(); @@ -240,3 +252,26 @@ XMLObject* ArtifactMap::retrieveContent(const SAMLArtifact* artifact, const char log.debug("resolved artifact for (%s)", relyingParty ? relyingParty : "unknown"); return xmlObject; } + +string ArtifactMap::getRelyingParty(const SAMLArtifact* artifact) +{ + if (!m_storage) + return m_mappings->getRelyingParty(artifact); + + string xmlbuf; + if (!m_storage->readText(m_context.c_str(), SAMLArtifact::toHex(artifact->getMessageHandle()).c_str(), &xmlbuf)) + throw BindingException("Artifact not found in mapping database."); + + // Parse the data back into XML. + istringstream is(xmlbuf); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(is); + XercesJanitor janitor(doc); + + // Check the root element. + DOMElement* messageRoot = doc->getDocumentElement(); + if (XMLHelper::isNodeNamed(messageRoot, NULL, Mapping)) { + auto_ptr_char temp(messageRoot->getAttributeNS(NULL,_relyingParty)); + return temp.get(); + } + return string(); +}