Clear caching key resolvers when provider changes.
authorScott Cantor <cantor.2@osu.edu>
Sun, 13 Aug 2006 03:48:51 +0000 (03:48 +0000)
committerScott Cantor <cantor.2@osu.edu>
Sun, 13 Aug 2006 03:48:51 +0000 (03:48 +0000)
saml/saml2/metadata/MetadataProvider.h
saml/saml2/metadata/impl/MetadataProvider.cpp
saml/saml2/metadata/impl/ObservableMetadataProvider.cpp

index 1c2765e..f773e41 100644 (file)
 #ifndef __saml2_metadataprov_h__
 #define __saml2_metadataprov_h__
 
-#include <xmltooling/Lockable.h>
 #include <saml/saml2/metadata/MetadataFilter.h>
 
+#include <xmltooling/Lockable.h>
+#include <xmltooling/signature/KeyResolver.h>
+
 namespace opensaml {
     
     class SAML_API SAMLArtifact;
@@ -45,11 +47,16 @@ namespace opensaml {
             
         protected:
             /**
-             * Constructor. If a DOM is supplied, a set of default logic will be
-             * used to identify and build MetadataFilter plugins and install them
-             * into the provider. The following XML content is supported:
+             * Constructor.
+             * 
+             * If a DOM is supplied, a set of default logic will be used to identify
+             * and build MetadataFilter plugins and install them into the provider.
+             * A KeyResolver can also be supplied, or a default resolver will be used.
+             * 
+             * The following XML content is supported:
              * 
              * <ul>
+             *  <li>&lt;KeyResolver&gt; elements with a type attribute
              *  <li>&lt;MetadataFilter&gt; elements with a type attribute
              *  <li>&lt;Exclude&gt; elements representing a BlacklistMetadataFilter
              *  <li>&lt;BlacklistMetadataFilter&gt; element containing &lt;Exclude&gt; elements 
@@ -105,6 +112,15 @@ namespace opensaml {
             virtual void init()=0;
             
             /**
+             * Returns a KeyResolver associated with this metadata provider, if any.
+             * 
+             * @return an associated KeyResolver, or NULL
+             */
+            virtual const xmlsignature::KeyResolver* getKeyResolver() const {
+                return m_resolver;
+            }
+            
+            /**
              * Gets the entire metadata tree, after the registered filter has been applied.
              * The caller MUST unlock the provider when finished with the data.
              * 
@@ -172,6 +188,9 @@ namespace opensaml {
             virtual const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const;
 
         protected:
+            /** Embedded KeyResolver instance. */
+            xmlsignature::KeyResolver* m_resolver;
+
             /**
              * Applies any installed filters to a metadata instance.
              * 
index 049cb6b..3e88ff3 100644 (file)
@@ -56,24 +56,30 @@ void SAML_API opensaml::saml2md::registerMetadataFilters()
 }
 
 static const XMLCh Blacklist[] =                    UNICODE_LITERAL_23(B,l,a,c,k,l,i,s,t,M,e,t,a,d,a,t,a,F,i,l,t,e,r);
+static const XMLCh Whitelist[] =                    UNICODE_LITERAL_23(W,h,i,t,e,l,i,s,t,M,e,t,a,d,a,t,a,F,i,l,t,e,r);
 static const XMLCh Exclude[] =                      UNICODE_LITERAL_7(E,x,c,l,u,d,e);
 static const XMLCh Include[] =                      UNICODE_LITERAL_7(I,n,c,l,u,d,e);
+static const XMLCh GenericKeyResolver[] =           UNICODE_LITERAL_11(K,e,y,R,e,s,o,l,v,e,r);
 static const XMLCh GenericMetadataFilter[] =        UNICODE_LITERAL_14(M,e,t,a,d,a,t,a,F,i,l,t,e,r);
 static const XMLCh type[] =                         UNICODE_LITERAL_4(t,y,p,e);
-static const XMLCh Whitelist[] =                    UNICODE_LITERAL_23(W,h,i,t,e,l,i,s,t,M,e,t,a,d,a,t,a,F,i,l,t,e,r);
 
-MetadataProvider::MetadataProvider(const DOMElement* e)
+MetadataProvider::MetadataProvider(const DOMElement* e) : m_resolver(NULL)
 {
 #ifdef _DEBUG
     NDC ndc("MetadataProvider");
 #endif
     SAMLConfig& conf=SAMLConfig::getConfig();
     
-    // Locate any default recognized filters.
+    // Locate any default recognized filters and plugins.
     try {
         DOMElement* child = e ? XMLHelper::getFirstChildElement(e) : NULL;
         while (child) {
-            if (XMLString::equals(child->getLocalName(),GenericMetadataFilter)) {
+            if (!m_resolver && XMLString::equals(child->getLocalName(),GenericKeyResolver)) {
+                auto_ptr_char t(child->getAttributeNS(NULL,type));
+                if (t.get())
+                    m_resolver = XMLToolingConfig::getConfig().KeyResolverManager.newPlugin(t.get(),child);
+            }
+            else if (XMLString::equals(child->getLocalName(),GenericMetadataFilter)) {
                 auto_ptr_char t(child->getAttributeNS(NULL,type));
                 if (t.get())
                     m_filters.push_back(conf.MetadataFilterManager.newPlugin(t.get(),child));
@@ -92,9 +98,14 @@ MetadataProvider::MetadataProvider(const DOMElement* e)
             }
             child = XMLHelper::getNextSiblingElement(child);
         }
+        
+        if (!m_resolver) {
+            m_resolver = XMLToolingConfig::getConfig().KeyResolverManager.newPlugin(INLINE_KEY_RESOLVER, child);
+        }
     }
     catch (XMLToolingException& ex) {
-        Category::getInstance(SAML_LOGCAT".Metadata").error("caught exception while installing filters: %s", ex.what());
+        Category::getInstance(SAML_LOGCAT".Metadata").error("caught exception while installing plugins and filters: %s", ex.what());
+        delete m_resolver;
         for_each(m_filters.begin(),m_filters.end(),xmltooling::cleanup<MetadataFilter>());
         throw;
     }
@@ -102,6 +113,7 @@ MetadataProvider::MetadataProvider(const DOMElement* e)
 
 MetadataProvider::~MetadataProvider()
 {
+    delete m_resolver;
     for_each(m_filters.begin(),m_filters.end(),xmltooling::cleanup<MetadataFilter>());
 }
 
index 569c030..069a1e2 100644 (file)
@@ -23,6 +23,8 @@
 #include "internal.h"
 #include "saml2/metadata/ObservableMetadataProvider.h"
 
+#include <xmltooling/signature/CachingKeyResolver.h>
+
 using namespace opensaml::saml2md;
 using namespace std;
 
@@ -33,6 +35,10 @@ ObservableMetadataProvider::~ObservableMetadataProvider()
 
 void ObservableMetadataProvider::emitChangeEvent()
 {
+    xmlsignature::CachingKeyResolver* ckr=dynamic_cast<xmlsignature::CachingKeyResolver*>(m_resolver);
+    if (ckr)
+        ckr->clearCache();
+    
     for (std::vector<Observer*>::const_iterator i=m_observers.begin(); i!=m_observers.end(); i++) {
         (*i)->onEvent(*this);
     }