Allow DOM-based construction.
authorScott Cantor <cantor.2@osu.edu>
Fri, 2 Mar 2007 04:54:30 +0000 (04:54 +0000)
committerScott Cantor <cantor.2@osu.edu>
Fri, 2 Mar 2007 04:54:30 +0000 (04:54 +0000)
saml/binding/ArtifactMap.h
saml/binding/impl/ArtifactMap.cpp

index dfee352..36f533a 100644 (file)
@@ -46,9 +46,17 @@ namespace opensaml {
          * 
          * @param storage       pointer to a StorageService, or NULL to keep map in memory
          * @param context       optional label for storage context
-         * @param artifactTTL   time to live value, determines how long artifact remains valid
+         * @param artifactTTL   time to live in seconds, determines how long artifact remains valid
          */
-        ArtifactMap(xmltooling::StorageService* storage=NULL, const char* context=NULL, int artifactTTL=180);
+        ArtifactMap(xmltooling::StorageService* storage=NULL, const char* context=NULL, unsigned int artifactTTL=180);
+
+        /**
+         * Creates a map on top of a particular storage service context, or in-memory.
+         * 
+         * @param e         root of a DOM with optional XML attributes for context and artifactTTL
+         * @param storage   pointer to a StorageService, or NULL to keep map in memory
+         */
+        ArtifactMap(const DOMElement* e, xmltooling::StorageService* storage=NULL);
 
         virtual ~ArtifactMap();
         
@@ -81,7 +89,7 @@ namespace opensaml {
         xmltooling::StorageService* m_storage;
         std::string m_context;
         ArtifactMappings* m_mappings;
-        int m_artifactTTL;
+        unsigned int m_artifactTTL;
     };
 };
 
index 0b61a7f..2abaecc 100644 (file)
@@ -64,6 +64,11 @@ namespace opensaml {
         map<string,Mapping> m_artMap;
         multimap<time_t,string> m_expMap;
     };
+
+    static const XMLCh artifactTTL[] =  UNICODE_LITERAL_11(a,r,t,i,f,a,c,t,T,T,L);
+    static const XMLCh context[] =      UNICODE_LITERAL_7(c,o,n,t,e,x,t);
+    static const XMLCh Mapping[] =      UNICODE_LITERAL_7(M,a,p,p,i,n,g);
+    static const XMLCh _relyingParty[] = UNICODE_LITERAL_12(r,e,l,y,i,n,g,P,a,r,t,y);
 };
 
 void ArtifactMappings::removeMapping(const map<string,Mapping>::iterator& i)
@@ -135,21 +140,38 @@ XMLObject* ArtifactMappings::retrieveContent(const SAMLArtifact* artifact, const
     return ret;
 }
 
-ArtifactMap::ArtifactMap(xmltooling::StorageService* storage, const char* context, int artifactTTL)
+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)
 {
     if (!m_storage)
         m_mappings = new ArtifactMappings();
 }
 
+ArtifactMap::ArtifactMap(const DOMElement* e, xmltooling::StorageService* storage)
+    : m_storage(storage), m_mappings(NULL), m_artifactTTL(180)
+{
+    if (e) {
+        auto_ptr_char c(e->getAttributeNS(NULL, context));
+        if (c.get() && *c.get())
+            m_context = c.get();
+        
+        const XMLCh* TTL = e->getAttributeNS(NULL, artifactTTL);
+        if (TTL) {
+            m_artifactTTL = XMLString::parseInt(TTL);
+            if (!m_artifactTTL)
+                m_artifactTTL = 180;
+        }
+    }
+    
+    if (!m_storage)
+        m_mappings = new ArtifactMappings();
+}
+
 ArtifactMap::~ArtifactMap()
 {
     delete m_mappings;
 }
 
-static const XMLCh M[] = UNICODE_LITERAL_7(M,a,p,p,i,n,g);
-static const XMLCh RP[] = UNICODE_LITERAL_12(r,e,l,y,i,n,g,P,a,r,t,y);
-
 void ArtifactMap::storeContent(XMLObject* content, const SAMLArtifact* artifact, const char* relyingParty)
 {
     if (content->getParent())
@@ -163,8 +185,8 @@ void ArtifactMap::storeContent(XMLObject* content, const SAMLArtifact* artifact,
     // Build a DOM with the same document to store the relyingParty mapping.
     if (relyingParty) {
         auto_ptr_XMLCh temp(relyingParty);
-        root = root->getOwnerDocument()->createElementNS(NULL,M);
-        root->setAttributeNS(NULL,RP,temp.get());
+        root = root->getOwnerDocument()->createElementNS(NULL,Mapping);
+        root->setAttributeNS(NULL,_relyingParty,temp.get());
         root->appendChild(content->getDOM());
     }
     
@@ -202,8 +224,8 @@ XMLObject* ArtifactMap::retrieveContent(const SAMLArtifact* artifact, const char
     
     // Check the root element.
     DOMElement* messageRoot = doc->getDocumentElement();
-    if (XMLHelper::isNodeNamed(messageRoot, NULL, M)) {
-        auto_ptr_char temp(messageRoot->getAttributeNS(NULL,RP));
+    if (XMLHelper::isNodeNamed(messageRoot, NULL, Mapping)) {
+        auto_ptr_char temp(messageRoot->getAttributeNS(NULL,_relyingParty));
         if (!relyingParty || strcmp(temp.get(),relyingParty)) {
             log.warn("request from (%s) for artifact issued to (%s)", relyingParty ? relyingParty : "unknown", temp.get());
             throw BindingException("Unauthorized artifact mapping request.");