2 * Copyright 2001-2010 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * MetadataProvider.cpp
20 * Supplies an individual source of metadata.
24 #include "saml2/metadata/MetadataFilter.h"
25 #include "saml2/metadata/MetadataProvider.h"
28 #include <xercesc/util/XMLUniDefs.hpp>
29 #include <xmltooling/logging.h>
30 #include <xmltooling/unicode.h>
31 #include <xmltooling/util/NDC.h>
32 #include <xmltooling/util/XMLHelper.h>
34 using namespace opensaml::saml2md;
35 using namespace opensaml;
36 using namespace xmltooling::logging;
37 using namespace xmltooling;
42 SAML_DLLLOCAL PluginManager<MetadataProvider,string,const DOMElement*>::Factory XMLMetadataProviderFactory;
43 SAML_DLLLOCAL PluginManager<MetadataProvider,string,const DOMElement*>::Factory DynamicMetadataProviderFactory;
44 SAML_DLLLOCAL PluginManager<MetadataProvider,string,const DOMElement*>::Factory ChainingMetadataProviderFactory;
45 SAML_DLLLOCAL PluginManager<MetadataProvider,string,const DOMElement*>::Factory NullMetadataProviderFactory;
46 SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory BlacklistMetadataFilterFactory;
47 SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory WhitelistMetadataFilterFactory;
48 SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory SignatureMetadataFilterFactory;
49 SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory RequireValidUntilMetadataFilterFactory;
50 SAML_DLLLOCAL PluginManager<MetadataFilter,string,const DOMElement*>::Factory EntityRoleMetadataFilterFactory;
54 void SAML_API opensaml::saml2md::registerMetadataProviders()
56 SAMLConfig& conf=SAMLConfig::getConfig();
57 conf.MetadataProviderManager.registerFactory(XML_METADATA_PROVIDER, XMLMetadataProviderFactory);
58 conf.MetadataProviderManager.registerFactory(DYNAMIC_METADATA_PROVIDER, DynamicMetadataProviderFactory);
59 conf.MetadataProviderManager.registerFactory(CHAINING_METADATA_PROVIDER, ChainingMetadataProviderFactory);
60 conf.MetadataProviderManager.registerFactory(NULL_METADATA_PROVIDER, NullMetadataProviderFactory);
63 void SAML_API opensaml::saml2md::registerMetadataFilters()
65 SAMLConfig::getConfig().MetadataFilterManager.registerFactory(BLACKLIST_METADATA_FILTER, BlacklistMetadataFilterFactory);
66 SAMLConfig::getConfig().MetadataFilterManager.registerFactory(WHITELIST_METADATA_FILTER, WhitelistMetadataFilterFactory);
67 SAMLConfig::getConfig().MetadataFilterManager.registerFactory(SIGNATURE_METADATA_FILTER, SignatureMetadataFilterFactory);
68 SAMLConfig::getConfig().MetadataFilterManager.registerFactory(REQUIREVALIDUNTIL_METADATA_FILTER, RequireValidUntilMetadataFilterFactory);
69 // additional name matching Java code
70 SAMLConfig::getConfig().MetadataFilterManager.registerFactory("RequiredValidUntil", RequireValidUntilMetadataFilterFactory);
71 SAMLConfig::getConfig().MetadataFilterManager.registerFactory(ENTITYROLE_METADATA_FILTER, EntityRoleMetadataFilterFactory);
74 static const XMLCh _MetadataFilter[] = UNICODE_LITERAL_14(M,e,t,a,d,a,t,a,F,i,l,t,e,r);
75 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);
76 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);
77 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);
78 static const XMLCh Exclude[] = UNICODE_LITERAL_7(E,x,c,l,u,d,e);
79 static const XMLCh Include[] = UNICODE_LITERAL_7(I,n,c,l,u,d,e);
80 static const XMLCh type[] = UNICODE_LITERAL_4(t,y,p,e);
82 MetadataProvider::MetadataProvider(const DOMElement* e)
85 NDC ndc("MetadataProvider");
87 Category& log = Category::getInstance(SAML_LOGCAT".Metadata");
88 SAMLConfig& conf=SAMLConfig::getConfig();
90 // Locate any default recognized filters and plugins.
92 DOMElement* child = e ? XMLHelper::getFirstChildElement(e) : nullptr;
94 if (XMLString::equals(child->getLocalName(),_MetadataFilter)) {
95 auto_ptr_char t(child->getAttributeNS(nullptr,type));
96 if (t.get() && *t.get()) {
97 log.info("building MetadataFilter of type %s", t.get());
98 m_filters.push_back(conf.MetadataFilterManager.newPlugin(t.get(),child));
101 else if (XMLString::equals(child->getLocalName(),SigFilter)) {
102 log.info("building MetadataFilter of type %s", SIGNATURE_METADATA_FILTER);
103 m_filters.push_back(conf.MetadataFilterManager.newPlugin(SIGNATURE_METADATA_FILTER,child));
105 else if (XMLString::equals(child->getLocalName(),Whitelist)) {
106 log.info("building MetadataFilter of type %s", WHITELIST_METADATA_FILTER);
107 m_filters.push_back(conf.MetadataFilterManager.newPlugin(WHITELIST_METADATA_FILTER,child));
109 else if (XMLString::equals(child->getLocalName(),Blacklist)) {
110 log.info("building MetadataFilter of type %s", BLACKLIST_METADATA_FILTER);
111 m_filters.push_back(conf.MetadataFilterManager.newPlugin(BLACKLIST_METADATA_FILTER,child));
113 else if (XMLString::equals(child->getLocalName(),Include)) {
114 log.info("building MetadataFilter of type %s", WHITELIST_METADATA_FILTER);
115 m_filters.push_back(conf.MetadataFilterManager.newPlugin(WHITELIST_METADATA_FILTER,e));
117 else if (XMLString::equals(child->getLocalName(),Exclude)) {
118 log.info("building MetadataFilter of type %s", BLACKLIST_METADATA_FILTER);
119 m_filters.push_back(conf.MetadataFilterManager.newPlugin(BLACKLIST_METADATA_FILTER,e));
121 child = XMLHelper::getNextSiblingElement(child);
124 catch (XMLToolingException& ex) {
125 log.error("caught exception while installing filters: %s", ex.what());
126 for_each(m_filters.begin(),m_filters.end(),xmltooling::cleanup<MetadataFilter>());
131 MetadataProvider::~MetadataProvider()
133 for_each(m_filters.begin(),m_filters.end(),xmltooling::cleanup<MetadataFilter>());
136 void MetadataProvider::addMetadataFilter(MetadataFilter* newFilter)
138 m_filters.push_back(newFilter);
141 MetadataFilter* MetadataProvider::removeMetadataFilter(MetadataFilter* oldFilter)
143 for (vector<MetadataFilter*>::iterator i=m_filters.begin(); i!=m_filters.end(); i++) {
144 if (oldFilter==(*i)) {
152 void MetadataProvider::doFilters(XMLObject& xmlObject) const
155 NDC ndc("doFilters");
157 Category& log=Category::getInstance(SAML_LOGCAT".Metadata");
158 for (std::vector<MetadataFilter*>::const_iterator i=m_filters.begin(); i!=m_filters.end(); i++) {
159 log.info("applying metadata filter (%s)", (*i)->getId());
160 (*i)->doFilter(xmlObject);
164 const EntitiesDescriptor* MetadataProvider::getEntitiesDescriptor(const XMLCh* name, bool strict) const
166 auto_ptr_char temp(name);
167 return getEntitiesDescriptor(temp.get(),strict);
170 MetadataProvider::Criteria::Criteria()
171 : entityID_unicode(nullptr), entityID_ascii(nullptr), artifact(nullptr), role(nullptr), protocol(nullptr), protocol2(nullptr), validOnly(true)
175 MetadataProvider::Criteria::Criteria(const XMLCh* id, const xmltooling::QName* q, const XMLCh* prot, bool valid)
176 : entityID_unicode(id), entityID_ascii(nullptr), artifact(nullptr), role(q), protocol(prot), protocol2(nullptr), validOnly(valid)
180 MetadataProvider::Criteria::Criteria(const char* id, const xmltooling::QName* q, const XMLCh* prot, bool valid)
181 : entityID_unicode(nullptr), entityID_ascii(id), artifact(nullptr), role(q), protocol(prot), protocol2(nullptr), validOnly(valid)
185 MetadataProvider::Criteria::Criteria(const SAMLArtifact* a, const xmltooling::QName* q, const XMLCh* prot, bool valid)
186 : entityID_unicode(nullptr), entityID_ascii(nullptr), artifact(a), role(q), protocol(prot), protocol2(nullptr), validOnly(valid)
190 MetadataProvider::Criteria::~Criteria()
194 void MetadataProvider::Criteria::reset()
196 entityID_unicode=nullptr;
197 entityID_ascii=nullptr;
205 MetadataFilter::MetadataFilter()
209 MetadataFilter::~MetadataFilter()