https://issues.shibboleth.net/jira/browse/CPPOST-69
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / impl / MetadataProvider.cpp
index e0efc7a..719f8cd 100644 (file)
@@ -1,31 +1,37 @@
-/*
- *  Copyright 2001-2009 Internet2
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
  *
- * 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
+ * UCAID licenses this file to you 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
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
  */
 
 /**
  * MetadataProvider.cpp
  *
- * Registration of factories for built-in providers
+ * Supplies an individual source of metadata.
  */
 
 #include "internal.h"
 #include "saml2/metadata/MetadataFilter.h"
 #include "saml2/metadata/MetadataProvider.h"
 
+#include <algorithm>
 #include <xercesc/util/XMLUniDefs.hpp>
 #include <xmltooling/logging.h>
+#include <xmltooling/unicode.h>
 #include <xmltooling/util/NDC.h>
 #include <xmltooling/util/XMLHelper.h>
 
@@ -40,6 +46,7 @@ namespace opensaml {
         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 FolderMetadataProviderFactory;
         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;
@@ -55,6 +62,7 @@ void SAML_API opensaml::saml2md::registerMetadataProviders()
     conf.MetadataProviderManager.registerFactory(XML_METADATA_PROVIDER, XMLMetadataProviderFactory);
     conf.MetadataProviderManager.registerFactory(DYNAMIC_METADATA_PROVIDER, DynamicMetadataProviderFactory);
     conf.MetadataProviderManager.registerFactory(CHAINING_METADATA_PROVIDER, ChainingMetadataProviderFactory);
+    conf.MetadataProviderManager.registerFactory(FOLDER_METADATA_PROVIDER, FolderMetadataProviderFactory);
     conf.MetadataProviderManager.registerFactory(NULL_METADATA_PROVIDER, NullMetadataProviderFactory);
 }
 
@@ -83,38 +91,38 @@ MetadataProvider::MetadataProvider(const DOMElement* e)
     NDC ndc("MetadataProvider");
 #endif
     Category& log = Category::getInstance(SAML_LOGCAT".Metadata");
-    SAMLConfig& conf=SAMLConfig::getConfig();
+    SAMLConfig& conf = SAMLConfig::getConfig();
 
     // Locate any default recognized filters and plugins.
     try {
-        DOMElement* child = e ? XMLHelper::getFirstChildElement(e) : NULL;
+        DOMElement* child = XMLHelper::getFirstChildElement(e);
         while (child) {
-            if (XMLString::equals(child->getLocalName(),_MetadataFilter)) {
-                auto_ptr_char t(child->getAttributeNS(NULL,type));
-                if (t.get() && *t.get()) {
-                    log.info("building MetadataFilter of type %s", t.get());
-                    m_filters.push_back(conf.MetadataFilterManager.newPlugin(t.get(),child));
+            if (XMLString::equals(child->getLocalName(), _MetadataFilter)) {
+                string t = XMLHelper::getAttrString(child, nullptr, type);
+                if (!t.empty()) {
+                    log.info("building MetadataFilter of type %s", t.c_str());
+                    m_filters.push_back(conf.MetadataFilterManager.newPlugin(t.c_str(), child));
                 }
             }
-            else if (XMLString::equals(child->getLocalName(),SigFilter)) {
+            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));
+                m_filters.push_back(conf.MetadataFilterManager.newPlugin(SIGNATURE_METADATA_FILTER, child));
             }
-            else if (XMLString::equals(child->getLocalName(),Whitelist)) {
+            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));
+                m_filters.push_back(conf.MetadataFilterManager.newPlugin(WHITELIST_METADATA_FILTER, child));
             }
-            else if (XMLString::equals(child->getLocalName(),Blacklist)) {
+            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));
+                m_filters.push_back(conf.MetadataFilterManager.newPlugin(BLACKLIST_METADATA_FILTER, child));
             }
-            else if (XMLString::equals(child->getLocalName(),Include)) {
+            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));
+                m_filters.push_back(conf.MetadataFilterManager.newPlugin(WHITELIST_METADATA_FILTER, e));
             }
-            else if (XMLString::equals(child->getLocalName(),Exclude)) {
+            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));
+                m_filters.push_back(conf.MetadataFilterManager.newPlugin(BLACKLIST_METADATA_FILTER, e));
             }
             child = XMLHelper::getNextSiblingElement(child);
         }
@@ -128,7 +136,28 @@ MetadataProvider::MetadataProvider(const DOMElement* e)
 
 MetadataProvider::~MetadataProvider()
 {
-    for_each(m_filters.begin(),m_filters.end(),xmltooling::cleanup<MetadataFilter>());
+    for_each(m_filters.begin(), m_filters.end(), xmltooling::cleanup<MetadataFilter>());
+}
+
+const char* MetadataProvider::getId() const
+{
+    return nullptr;
+}
+
+void MetadataProvider::addMetadataFilter(MetadataFilter* newFilter)
+{
+    m_filters.push_back(newFilter);
+}
+
+MetadataFilter* MetadataProvider::removeMetadataFilter(MetadataFilter* oldFilter)
+{
+    for (vector<MetadataFilter*>::iterator i=m_filters.begin(); i!=m_filters.end(); i++) {
+        if (oldFilter==(*i)) {
+            m_filters.erase(i);
+            return oldFilter;
+        }
+    }
+    return nullptr;
 }
 
 void MetadataProvider::doFilters(XMLObject& xmlObject) const
@@ -143,8 +172,55 @@ void MetadataProvider::doFilters(XMLObject& xmlObject) const
     }
 }
 
+void MetadataProvider::outputStatus(ostream& os) const
+{
+}
+
 const EntitiesDescriptor* MetadataProvider::getEntitiesDescriptor(const XMLCh* name, bool strict) const
 {
     auto_ptr_char temp(name);
     return getEntitiesDescriptor(temp.get(),strict);
 }
+
+MetadataProvider::Criteria::Criteria()
+    : entityID_unicode(nullptr), entityID_ascii(nullptr), artifact(nullptr), role(nullptr), protocol(nullptr), protocol2(nullptr), validOnly(true)
+{
+}
+
+MetadataProvider::Criteria::Criteria(const XMLCh* id, const xmltooling::QName* q, const XMLCh* prot, bool valid)
+    : entityID_unicode(id), entityID_ascii(nullptr), artifact(nullptr), role(q), protocol(prot), protocol2(nullptr), validOnly(valid)
+{
+}
+
+MetadataProvider::Criteria::Criteria(const char* id, const xmltooling::QName* q, const XMLCh* prot, bool valid)
+    : entityID_unicode(nullptr), entityID_ascii(id), artifact(nullptr), role(q), protocol(prot), protocol2(nullptr), validOnly(valid)
+{
+}
+
+MetadataProvider::Criteria::Criteria(const SAMLArtifact* a, const xmltooling::QName* q, const XMLCh* prot, bool valid)
+    : entityID_unicode(nullptr), entityID_ascii(nullptr), artifact(a), role(q), protocol(prot), protocol2(nullptr), validOnly(valid)
+{
+}
+
+MetadataProvider::Criteria::~Criteria()
+{
+}
+
+void MetadataProvider::Criteria::reset()
+{
+    entityID_unicode=nullptr;
+    entityID_ascii=nullptr;
+    artifact=nullptr;
+    role=nullptr;
+    protocol=nullptr;
+    protocol2=nullptr;
+    validOnly=true;
+}
+
+MetadataFilter::MetadataFilter()
+{
+}
+
+MetadataFilter::~MetadataFilter()
+{
+}