Multi-line svn commit, see body.
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / impl / MetadataProvider.cpp
index b0bf178..0741b62 100644 (file)
@@ -1,6 +1,6 @@
 /*
- *  Copyright 2001-2006 Internet2
- * 
+ *  Copyright 2001-2007 Internet2
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 
 /**
  * MetadataProvider.cpp
- * 
+ *
  * Registration of factories for built-in providers
  */
 
 #include "internal.h"
+#include "saml2/metadata/MetadataFilter.h"
 #include "saml2/metadata/MetadataProvider.h"
 
-#include <log4cpp/Category.hh>
+#include <xercesc/util/XMLUniDefs.hpp>
+#include <xmltooling/logging.h>
 #include <xmltooling/util/NDC.h>
+#include <xmltooling/util/XMLHelper.h>
 
 using namespace opensaml::saml2md;
+using namespace opensaml;
+using namespace xmltooling::logging;
 using namespace xmltooling;
-using namespace log4cpp;
 using namespace std;
 
-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 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 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);
+namespace opensaml {
+    namespace saml2md {
+        SAML_DLLLOCAL PluginManager<MetadataProvider,string,const DOMElement*>::Factory XMLMetadataProviderFactory;
+        SAML_DLLLOCAL PluginManager<MetadataProvider,string,const DOMElement*>::Factory DynamicMetadataProviderFactory;
+        SAML_DLLLOCAL PluginManager<MetadataProvider,string,const DOMElement*>::Factory ChainingMetadataProviderFactory;
+        SAML_DLLLOCAL PluginManager<MetadataProvider,string,const DOMElement*>::Factory NullMetadataProviderFactory;
+        SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory BlacklistMetadataFilterFactory;
+        SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory WhitelistMetadataFilterFactory;
+        SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory SignatureMetadataFilterFactory;
+        SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory RequireValidUntilMetadataFilterFactory;
+    };
+};
+
+void SAML_API opensaml::saml2md::registerMetadataProviders()
+{
+    SAMLConfig& conf=SAMLConfig::getConfig();
+    conf.MetadataProviderManager.registerFactory(XML_METADATA_PROVIDER, XMLMetadataProviderFactory);
+    conf.MetadataProviderManager.registerFactory(DYNAMIC_METADATA_PROVIDER, DynamicMetadataProviderFactory);
+    conf.MetadataProviderManager.registerFactory(CHAINING_METADATA_PROVIDER, ChainingMetadataProviderFactory);
+    conf.MetadataProviderManager.registerFactory(NULL_METADATA_PROVIDER, NullMetadataProviderFactory);
+}
+
+void SAML_API opensaml::saml2md::registerMetadataFilters()
+{
+    SAMLConfig::getConfig().MetadataFilterManager.registerFactory(BLACKLIST_METADATA_FILTER, BlacklistMetadataFilterFactory);
+    SAMLConfig::getConfig().MetadataFilterManager.registerFactory(WHITELIST_METADATA_FILTER, WhitelistMetadataFilterFactory);
+    SAMLConfig::getConfig().MetadataFilterManager.registerFactory(SIGNATURE_METADATA_FILTER, SignatureMetadataFilterFactory);
+    SAMLConfig::getConfig().MetadataFilterManager.registerFactory(REQUIREVALIDUNTIL_METADATA_FILTER, RequireValidUntilMetadataFilterFactory);
+}
+
+static const XMLCh _MetadataFilter[] =  UNICODE_LITERAL_14(M,e,t,a,d,a,t,a,F,i,l,t,e,r);
+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 SigFilter[] =        UNICODE_LITERAL_23(S,i,g,n,a,t,u,r,e,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 type[] =             UNICODE_LITERAL_4(t,y,p,e);
 
 MetadataProvider::MetadataProvider(const DOMElement* e)
 {
 #ifdef _DEBUG
     NDC ndc("MetadataProvider");
 #endif
+    Category& log = Category::getInstance(SAML_LOGCAT".Metadata");
     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 (XMLString::equals(child->getLocalName(),_MetadataFilter)) {
                 auto_ptr_char t(child->getAttributeNS(NULL,type));
-                if (t.get())
+                if (t.get() && *t.get()) {
+                    log.info("building MetadataFilter of type %s", t.get());
                     m_filters.push_back(conf.MetadataFilterManager.newPlugin(t.get(),child));
+                }
+            }
+            else if (XMLString::equals(child->getLocalName(),SigFilter)) {
+                log.info("building MetadataFilter of type %s", SIGNATURE_METADATA_FILTER);
+                m_filters.push_back(conf.MetadataFilterManager.newPlugin(SIGNATURE_METADATA_FILTER,child));
             }
             else if (XMLString::equals(child->getLocalName(),Whitelist)) {
+                log.info("building MetadataFilter of type %s", WHITELIST_METADATA_FILTER);
                 m_filters.push_back(conf.MetadataFilterManager.newPlugin(WHITELIST_METADATA_FILTER,child));
             }
             else if (XMLString::equals(child->getLocalName(),Blacklist)) {
+                log.info("building MetadataFilter of type %s", BLACKLIST_METADATA_FILTER);
                 m_filters.push_back(conf.MetadataFilterManager.newPlugin(BLACKLIST_METADATA_FILTER,child));
             }
             else if (XMLString::equals(child->getLocalName(),Include)) {
+                log.info("building MetadataFilter of type %s", WHITELIST_METADATA_FILTER);
                 m_filters.push_back(conf.MetadataFilterManager.newPlugin(WHITELIST_METADATA_FILTER,e));
             }
             else if (XMLString::equals(child->getLocalName(),Exclude)) {
+                log.info("building MetadataFilter of type %s", BLACKLIST_METADATA_FILTER);
                 m_filters.push_back(conf.MetadataFilterManager.newPlugin(BLACKLIST_METADATA_FILTER,e));
             }
             child = XMLHelper::getNextSiblingElement(child);
         }
     }
     catch (XMLToolingException& ex) {
-        Category::getInstance(SAML_LOGCAT".Metadata").error("caught exception while installing filters: %s", ex.what());
+        log.error("caught exception while installing filters: %s", ex.what());
         for_each(m_filters.begin(),m_filters.end(),xmltooling::cleanup<MetadataFilter>());
         throw;
     }
@@ -93,24 +139,8 @@ void MetadataProvider::doFilters(XMLObject& xmlObject) const
     }
 }
 
-namespace opensaml {
-    namespace saml2md {
-        SAML_DLLLOCAL PluginManager<MetadataProvider,const DOMElement*>::Factory FilesystemMetadataProviderFactory; 
-        SAML_DLLLOCAL PluginManager<MetadataFilter,const DOMElement*>::Factory BlacklistMetadataFilterFactory; 
-        SAML_DLLLOCAL PluginManager<MetadataFilter,const DOMElement*>::Factory WhitelistMetadataFilterFactory; 
-    };
-};
-
-void SAML_API opensaml::saml2md::registerMetadataProviders()
-{
-    SAMLConfig& conf=SAMLConfig::getConfig();
-    conf.MetadataProviderManager.registerFactory(FILESYSTEM_METADATA_PROVIDER, FilesystemMetadataProviderFactory);
-    conf.MetadataProviderManager.registerFactory("edu.internet2.middleware.shibboleth.metadata.provider.XMLMetadata", FilesystemMetadataProviderFactory);
-    conf.MetadataProviderManager.registerFactory("edu.internet2.middleware.shibboleth.common.provider.XMLMetadata", FilesystemMetadataProviderFactory);
-}
-
-void SAML_API opensaml::saml2md::registerMetadataFilters()
+const EntitiesDescriptor* MetadataProvider::getEntitiesDescriptor(const XMLCh* name, bool strict) const
 {
-    SAMLConfig::getConfig().MetadataFilterManager.registerFactory(BLACKLIST_METADATA_FILTER, BlacklistMetadataFilterFactory);
-    SAMLConfig::getConfig().MetadataFilterManager.registerFactory(WHITELIST_METADATA_FILTER, WhitelistMetadataFilterFactory);
+    auto_ptr_char temp(name);
+    return getEntitiesDescriptor(temp.get(),strict);
 }