X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fcpp-opensaml.git;a=blobdiff_plain;f=saml%2Fsaml2%2Fmetadata%2Fimpl%2FMetadataProvider.cpp;h=efb923a3306cf12188d7738b127f741d42b7195b;hp=4d8d6b13e85863c7539682c0bdc823a8bff92a9f;hb=1462057b3b9ae7e165d34d988e30b14c213672ca;hpb=d8a4f024b89272eae00618fc39e6127b6c191edd diff --git a/saml/saml2/metadata/impl/MetadataProvider.cpp b/saml/saml2/metadata/impl/MetadataProvider.cpp index 4d8d6b1..efb923a 100644 --- a/saml/saml2/metadata/impl/MetadataProvider.cpp +++ b/saml/saml2/metadata/impl/MetadataProvider.cpp @@ -1,17 +1,21 @@ -/* - * 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. */ /** @@ -25,6 +29,7 @@ #include "saml2/metadata/MetadataProvider.h" #include +#include #include #include #include @@ -35,6 +40,8 @@ using namespace opensaml::saml2md; using namespace opensaml; using namespace xmltooling::logging; using namespace xmltooling; +using namespace boost::lambda; +using namespace boost; using namespace std; namespace opensaml { @@ -42,12 +49,14 @@ namespace opensaml { SAML_DLLLOCAL PluginManager::Factory XMLMetadataProviderFactory; SAML_DLLLOCAL PluginManager::Factory DynamicMetadataProviderFactory; SAML_DLLLOCAL PluginManager::Factory ChainingMetadataProviderFactory; + SAML_DLLLOCAL PluginManager::Factory FolderMetadataProviderFactory; SAML_DLLLOCAL PluginManager::Factory NullMetadataProviderFactory; SAML_DLLLOCAL PluginManager::Factory BlacklistMetadataFilterFactory; SAML_DLLLOCAL PluginManager::Factory WhitelistMetadataFilterFactory; SAML_DLLLOCAL PluginManager::Factory SignatureMetadataFilterFactory; SAML_DLLLOCAL PluginManager::Factory RequireValidUntilMetadataFilterFactory; SAML_DLLLOCAL PluginManager::Factory EntityRoleMetadataFilterFactory; + SAML_DLLLOCAL PluginManager::Factory EntityAttributesMetadataFilterFactory; }; }; @@ -57,6 +66,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); } @@ -69,6 +79,8 @@ void SAML_API opensaml::saml2md::registerMetadataFilters() // additional name matching Java code SAMLConfig::getConfig().MetadataFilterManager.registerFactory("RequiredValidUntil", RequireValidUntilMetadataFilterFactory); SAMLConfig::getConfig().MetadataFilterManager.registerFactory(ENTITYROLE_METADATA_FILTER, EntityRoleMetadataFilterFactory); + SAMLConfig::getConfig().MetadataFilterManager.registerFactory(ENTITYATTR_METADATA_FILTER, EntityAttributesMetadataFilterFactory); + } static const XMLCh _MetadataFilter[] = UNICODE_LITERAL_14(M,e,t,a,d,a,t,a,F,i,l,t,e,r); @@ -77,60 +89,68 @@ static const XMLCh Whitelist[] = UNICODE_LITERAL_23(W,h,i,t,e,l,i,s,t,M,e 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); +static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e); -MetadataProvider::MetadataProvider(const DOMElement* e) +MetadataProvider::MetadataProvider(const DOMElement* e) : m_filterContext(nullptr) { #ifdef _DEBUG NDC ndc("MetadataProvider"); #endif - Category& log = Category::getInstance(SAML_LOGCAT".Metadata"); - SAMLConfig& conf=SAMLConfig::getConfig(); + Category& log = Category::getInstance(SAML_LOGCAT ".Metadata"); + 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()); + auto_ptr np(conf.MetadataFilterManager.newPlugin(t.c_str(), child)); + m_filters.push_back(np.get()); + np.release(); + } + else { + log.error("MetadataFilter element missing type attribute"); } } - 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); } } catch (XMLToolingException& ex) { log.error("caught exception while installing filters: %s", ex.what()); - for_each(m_filters.begin(),m_filters.end(),xmltooling::cleanup()); throw; } } MetadataProvider::~MetadataProvider() { - for_each(m_filters.begin(),m_filters.end(),xmltooling::cleanup()); +} + +const char* MetadataProvider::getId() const +{ + return nullptr; } void MetadataProvider::addMetadataFilter(MetadataFilter* newFilter) @@ -140,27 +160,31 @@ void MetadataProvider::addMetadataFilter(MetadataFilter* newFilter) MetadataFilter* MetadataProvider::removeMetadataFilter(MetadataFilter* oldFilter) { - for (vector::iterator i=m_filters.begin(); i!=m_filters.end(); i++) { - if (oldFilter==(*i)) { - m_filters.erase(i); - return oldFilter; - } + ptr_vector::iterator i = find_if(m_filters.begin(), m_filters.end(), (&_1 == oldFilter)); + if (i != m_filters.end()) { + return m_filters.release(i).release(); } - return NULL; + return nullptr; +} + +void MetadataProvider::setContext(const MetadataFilterContext* ctx) +{ + m_filterContext = ctx; } void MetadataProvider::doFilters(XMLObject& xmlObject) const { -#ifdef _DEBUG - NDC ndc("doFilters"); -#endif - Category& log=Category::getInstance(SAML_LOGCAT".Metadata"); - for (std::vector::const_iterator i=m_filters.begin(); i!=m_filters.end(); i++) { - log.info("applying metadata filter (%s)", (*i)->getId()); - (*i)->doFilter(xmlObject); + Category& log = Category::getInstance(SAML_LOGCAT ".Metadata"); + for (ptr_vector::const_iterator i = m_filters.begin(); i != m_filters.end(); i++) { + log.info("applying metadata filter (%s)", i->getId()); + i->doFilter(m_filterContext, xmlObject); } } +void MetadataProvider::outputStatus(ostream& os) const +{ +} + const EntitiesDescriptor* MetadataProvider::getEntitiesDescriptor(const XMLCh* name, bool strict) const { auto_ptr_char temp(name); @@ -168,22 +192,22 @@ const EntitiesDescriptor* MetadataProvider::getEntitiesDescriptor(const XMLCh* n } MetadataProvider::Criteria::Criteria() - : entityID_unicode(NULL), entityID_ascii(NULL), artifact(NULL), role(NULL), protocol(NULL), protocol2(NULL), validOnly(true) + : 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(NULL), artifact(NULL), role(q), protocol(prot), protocol2(NULL), validOnly(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(NULL), entityID_ascii(id), artifact(NULL), role(q), protocol(prot), protocol2(NULL), validOnly(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(NULL), entityID_ascii(NULL), artifact(a), role(q), protocol(prot), protocol2(NULL), validOnly(valid) + : entityID_unicode(nullptr), entityID_ascii(nullptr), artifact(a), role(q), protocol(prot), protocol2(nullptr), validOnly(valid) { } @@ -193,13 +217,13 @@ MetadataProvider::Criteria::~Criteria() void MetadataProvider::Criteria::reset() { - entityID_unicode=NULL; - entityID_ascii=NULL; - artifact=NULL; - role=NULL; - protocol=NULL; - protocol2=NULL; - validOnly=true; + entityID_unicode = nullptr; + entityID_ascii = nullptr; + artifact = nullptr; + role = nullptr; + protocol = nullptr; + protocol2 = nullptr; + validOnly = true; } MetadataFilter::MetadataFilter() @@ -209,3 +233,22 @@ MetadataFilter::MetadataFilter() MetadataFilter::~MetadataFilter() { } + +void MetadataFilter::doFilter(const MetadataFilterContext* ctx, xmltooling::XMLObject& xmlObject) const +{ + // Default call into deprecated method. + doFilter(xmlObject); +} + +void MetadataFilter::doFilter(xmltooling::XMLObject& xmlObject) const +{ + // Empty default for deprecated method. +} + +MetadataFilterContext::MetadataFilterContext() +{ +} + +MetadataFilterContext::~MetadataFilterContext() +{ +}