2 * Copyright 2001-2007 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 * Registration of factories for built-in providers
24 #include "saml2/metadata/MetadataProvider.h"
26 #include <log4cpp/Category.hh>
27 #include <xercesc/util/XMLUniDefs.hpp>
28 #include <xmltooling/util/NDC.h>
29 #include <xmltooling/util/XMLHelper.h>
31 using namespace opensaml::saml2md;
32 using namespace opensaml;
33 using namespace xmltooling;
34 using namespace log4cpp;
39 SAML_DLLLOCAL PluginManager<MetadataProvider,const DOMElement*>::Factory XMLMetadataProviderFactory;
40 SAML_DLLLOCAL PluginManager<MetadataProvider,const DOMElement*>::Factory ChainingMetadataProviderFactory;
41 SAML_DLLLOCAL PluginManager<MetadataFilter,const DOMElement*>::Factory BlacklistMetadataFilterFactory;
42 SAML_DLLLOCAL PluginManager<MetadataFilter,const DOMElement*>::Factory WhitelistMetadataFilterFactory;
43 SAML_DLLLOCAL PluginManager<MetadataFilter,const DOMElement*>::Factory SignatureMetadataFilterFactory;
47 void SAML_API opensaml::saml2md::registerMetadataProviders()
49 SAMLConfig& conf=SAMLConfig::getConfig();
50 conf.MetadataProviderManager.registerFactory(XML_METADATA_PROVIDER, XMLMetadataProviderFactory);
51 conf.MetadataProviderManager.registerFactory(CHAINING_METADATA_PROVIDER, ChainingMetadataProviderFactory);
52 conf.MetadataProviderManager.registerFactory("edu.internet2.middleware.shibboleth.metadata.provider.XMLMetadata", XMLMetadataProviderFactory);
53 conf.MetadataProviderManager.registerFactory("edu.internet2.middleware.shibboleth.common.provider.XMLMetadata", XMLMetadataProviderFactory);
56 void SAML_API opensaml::saml2md::registerMetadataFilters()
58 SAMLConfig::getConfig().MetadataFilterManager.registerFactory(BLACKLIST_METADATA_FILTER, BlacklistMetadataFilterFactory);
59 SAMLConfig::getConfig().MetadataFilterManager.registerFactory(WHITELIST_METADATA_FILTER, WhitelistMetadataFilterFactory);
60 SAMLConfig::getConfig().MetadataFilterManager.registerFactory(SIGNATURE_METADATA_FILTER, SignatureMetadataFilterFactory);
63 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);
64 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);
65 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);
66 static const XMLCh Exclude[] = UNICODE_LITERAL_7(E,x,c,l,u,d,e);
67 static const XMLCh Include[] = UNICODE_LITERAL_7(I,n,c,l,u,d,e);
68 static const XMLCh GenericMetadataFilter[] = UNICODE_LITERAL_14(M,e,t,a,d,a,t,a,F,i,l,t,e,r);
69 static const XMLCh type[] = UNICODE_LITERAL_4(t,y,p,e);
71 MetadataProvider::MetadataProvider(const DOMElement* e)
74 NDC ndc("MetadataProvider");
76 SAMLConfig& conf=SAMLConfig::getConfig();
78 // Locate any default recognized filters and plugins.
80 DOMElement* child = e ? XMLHelper::getFirstChildElement(e) : NULL;
82 if (XMLString::equals(child->getLocalName(),GenericMetadataFilter)) {
83 auto_ptr_char t(child->getAttributeNS(NULL,type));
85 m_filters.push_back(conf.MetadataFilterManager.newPlugin(t.get(),child));
87 throw UnknownExtensionException("<MetadataFilter> element found with no type attribute");
89 else if (XMLString::equals(child->getLocalName(),SigFilter)) {
90 m_filters.push_back(conf.MetadataFilterManager.newPlugin(SIGNATURE_METADATA_FILTER,child));
92 else if (XMLString::equals(child->getLocalName(),Whitelist)) {
93 m_filters.push_back(conf.MetadataFilterManager.newPlugin(WHITELIST_METADATA_FILTER,child));
95 else if (XMLString::equals(child->getLocalName(),Blacklist)) {
96 m_filters.push_back(conf.MetadataFilterManager.newPlugin(BLACKLIST_METADATA_FILTER,child));
98 else if (XMLString::equals(child->getLocalName(),Include)) {
99 m_filters.push_back(conf.MetadataFilterManager.newPlugin(WHITELIST_METADATA_FILTER,e));
101 else if (XMLString::equals(child->getLocalName(),Exclude)) {
102 m_filters.push_back(conf.MetadataFilterManager.newPlugin(BLACKLIST_METADATA_FILTER,e));
104 child = XMLHelper::getNextSiblingElement(child);
107 catch (XMLToolingException& ex) {
108 Category::getInstance(SAML_LOGCAT".Metadata").error("caught exception while installing filters: %s", ex.what());
109 for_each(m_filters.begin(),m_filters.end(),xmltooling::cleanup<MetadataFilter>());
114 MetadataProvider::~MetadataProvider()
116 for_each(m_filters.begin(),m_filters.end(),xmltooling::cleanup<MetadataFilter>());
119 void MetadataProvider::doFilters(XMLObject& xmlObject) const
122 NDC ndc("doFilters");
124 Category& log=Category::getInstance(SAML_LOGCAT".Metadata");
125 for (std::vector<MetadataFilter*>::const_iterator i=m_filters.begin(); i!=m_filters.end(); i++) {
126 log.info("applying metadata filter (%s)", (*i)->getId());
127 (*i)->doFilter(xmlObject);
131 const EntitiesDescriptor* MetadataProvider::getEntitiesDescriptor(const XMLCh* name, bool strict) const
133 auto_ptr_char temp(name);
134 return getEntitiesDescriptor(temp.get(),strict);
137 const EntityDescriptor* MetadataProvider::getEntityDescriptor(const XMLCh* name, bool strict) const
139 auto_ptr_char temp(name);
140 return getEntityDescriptor(temp.get(),strict);