2 * The Shibboleth License, Version 1.
4 * University Corporation for Advanced Internet Development, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * Redistributions of source code must retain the above copyright notice, this
12 * list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution, if any, must include
17 * the following acknowledgment: "This product includes software developed by
18 * the University Corporation for Advanced Internet Development
19 * <http://www.ucaid.edu>Internet2 Project. Alternately, this acknowledegement
20 * may appear in the software itself, if and wherever such third-party
21 * acknowledgments normally appear.
23 * Neither the name of Shibboleth nor the names of its contributors, nor
24 * Internet2, nor the University Corporation for Advanced Internet Development,
25 * Inc., nor UCAID may be used to endorse or promote products derived from this
26 * software without specific prior written permission. For written permission,
27 * please contact shibboleth@shibboleth.org
29 * Products derived from this software may not be called Shibboleth, Internet2,
30 * UCAID, or the University Corporation for Advanced Internet Development, nor
31 * may Shibboleth appear in their name, without prior written permission of the
32 * University Corporation for Advanced Internet Development.
35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
36 * AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
38 * PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED AND THE ENTIRE RISK
39 * OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH LICENSEE.
40 * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY
41 * CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC. BE LIABLE FOR ANY DIRECT,
42 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
43 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 * shib-ini.h -- config file handling, now XML-based
58 #include <shib/shib-threads.h>
59 #include <log4cpp/Category.hh>
60 #include <log4cpp/PropertyConfigurator.hh>
62 #include <sys/types.h>
67 using namespace shibboleth;
68 using namespace shibtarget;
69 using namespace log4cpp;
71 namespace shibtarget {
73 // Application configuration wrapper
74 class XMLApplication : public virtual IApplication, public XMLPropertySet, public DOMNodeFilter
77 XMLApplication(const IConfig*, const Iterator<ICredentials*>& creds, const DOMElement* e, const XMLApplication* base=NULL);
78 ~XMLApplication() { cleanup(); }
81 pair<bool,bool> getBool(const char* name, const char* ns=NULL) const;
82 pair<bool,const char*> getString(const char* name, const char* ns=NULL) const;
83 pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const;
84 pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const;
85 pair<bool,int> getInt(const char* name, const char* ns=NULL) const;
86 const IPropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const;
89 const char* getId() const {return getString("id").second;}
90 const char* getHash() const {return m_hash.c_str();}
91 Iterator<SAMLAttributeDesignator*> getAttributeDesignators() const;
92 Iterator<IAAP*> getAAPProviders() const;
93 Iterator<IMetadata*> getMetadataProviders() const;
94 Iterator<ITrust*> getTrustProviders() const;
95 Iterator<const XMLCh*> getAudiences() const;
96 const IPropertySet* getCredentialUse(const IEntityDescriptor* provider) const;
97 const SAMLBrowserProfile* getBrowserProfile() const {return m_profile;}
98 const SAMLBinding* getBinding(const XMLCh* binding) const
99 {return XMLString::compareString(SAMLBinding::SOAP,binding) ? NULL : m_binding;}
100 SAMLBrowserProfile::ArtifactMapper* getArtifactMapper() const {return new STArtifactMapper(this);}
101 const IPropertySet* getDefaultSessionInitiator() const;
102 const IPropertySet* getSessionInitiatorById(const char* id) const;
103 const IPropertySet* getDefaultAssertionConsumerService() const;
104 const IPropertySet* getAssertionConsumerServiceByIndex(unsigned short index) const;
105 const IPropertySet* getHandler(const char* path) const;
107 // Provides filter to exclude special config elements.
108 short acceptNode(const DOMNode* node) const;
112 const IConfig* m_ini; // this is ok because its locking scope includes us
113 const XMLApplication* m_base;
115 vector<SAMLAttributeDesignator*> m_designators;
116 vector<IAAP*> m_aaps;
117 vector<IMetadata*> m_metadatas;
118 vector<ITrust*> m_trusts;
119 vector<const XMLCh*> m_audiences;
120 ShibBrowserProfile* m_profile;
121 SAMLBinding* m_binding;
122 ShibHTTPHook* m_bindingHook;
123 map<string,XMLPropertySet*> m_handlerMap;
124 map<unsigned int,const IPropertySet*> m_acsMap;
125 const IPropertySet* m_acsDefault;
126 map<string,const IPropertySet*> m_sessionInitMap;
127 const IPropertySet* m_sessionInitDefault;
128 XMLPropertySet* m_credDefault;
130 map<xstring,XMLPropertySet*> m_credMap;
132 map<const XMLCh*,XMLPropertySet*> m_credMap;
136 // Top-level configuration implementation
138 class XMLConfigImpl : public ReloadableXMLFileImpl, public XMLPropertySet, public DOMNodeFilter
141 XMLConfigImpl(const char* pathname, bool first, const XMLConfig* outer)
142 : ReloadableXMLFileImpl(pathname), m_outer(outer), m_requestMapper(NULL) { init(first); }
143 XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer)
144 : ReloadableXMLFileImpl(e), m_outer(outer), m_requestMapper(NULL) { init(first); }
147 IRequestMapper* m_requestMapper;
148 map<string,IApplication*> m_appmap;
149 vector<ICredentials*> m_creds;
151 // Provides filter to exclude special config elements.
152 short acceptNode(const DOMNode* node) const;
155 void init(bool first);
156 const XMLConfig* m_outer;
159 class XMLConfig : public IConfig, public ReloadableXMLFile
162 XMLConfig(const DOMElement* e) : ReloadableXMLFile(e), m_listener(NULL), m_sessionCache(NULL), m_replayCache(NULL) {}
163 ~XMLConfig() {delete m_listener; delete m_sessionCache; delete m_replayCache;}
166 pair<bool,bool> getBool(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getBool(name,ns);}
167 pair<bool,const char*> getString(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getString(name,ns);}
168 pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getXMLString(name,ns);}
169 pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getUnsignedInt(name,ns);}
170 pair<bool,int> getInt(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getInt(name,ns);}
171 const IPropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const {return static_cast<XMLConfigImpl*>(m_impl)->getPropertySet(name,ns);}
172 const DOMElement* getElement() const {return static_cast<XMLConfigImpl*>(m_impl)->getElement();}
175 const IListener* getListener() const {return m_listener;}
176 ISessionCache* getSessionCache() const {return m_sessionCache;}
177 IReplayCache* getReplayCache() const {return m_replayCache;}
178 IRequestMapper* getRequestMapper() const {return static_cast<XMLConfigImpl*>(m_impl)->m_requestMapper;}
179 const IApplication* getApplication(const char* applicationId) const {
180 map<string,IApplication*>::const_iterator i=static_cast<XMLConfigImpl*>(m_impl)->m_appmap.find(applicationId);
181 return (i!=static_cast<XMLConfigImpl*>(m_impl)->m_appmap.end()) ? i->second : NULL;
183 Iterator<ICredentials*> getCredentialsProviders() const {return static_cast<XMLConfigImpl*>(m_impl)->m_creds;}
186 virtual ReloadableXMLFileImpl* newImplementation(const char* pathname, bool first=true) const;
187 virtual ReloadableXMLFileImpl* newImplementation(const DOMElement* e, bool first=true) const;
190 friend class XMLConfigImpl;
191 mutable IListener* m_listener;
192 mutable ISessionCache* m_sessionCache;
193 mutable IReplayCache* m_replayCache;
197 IConfig* STConfig::ShibTargetConfigFactory(const DOMElement* e)
199 auto_ptr<XMLConfig> ret(new XMLConfig(e));
200 ret->getImplementation();
201 return ret.release();
204 XMLPropertySet::~XMLPropertySet()
206 for (map<string,pair<char*,const XMLCh*> >::iterator i=m_map.begin(); i!=m_map.end(); i++)
207 XMLString::release(&(i->second.first));
208 for (map<string,IPropertySet*>::iterator j=m_nested.begin(); j!=m_nested.end(); j++)
212 void XMLPropertySet::load(
215 DOMNodeFilter* filter,
216 const std::map<std::string,std::string>* remapper
220 saml::NDC ndc("load");
224 // Process each attribute as a property.
225 DOMNamedNodeMap* attrs=m_root->getAttributes();
226 for (XMLSize_t i=0; i<attrs->getLength(); i++) {
227 DOMNode* a=attrs->item(i);
228 if (!XMLString::compareString(a->getNamespaceURI(),saml::XML::XMLNS_NS))
230 char* val=XMLString::transcode(a->getNodeValue());
232 auto_ptr_char ns(a->getNamespaceURI());
233 auto_ptr_char name(a->getLocalName());
234 const char* realname=name.get();
236 map<string,string>::const_iterator remap=remapper->find(realname);
237 if (remap!=remapper->end()) {
238 log.debug("remapping property (%s) to (%s)",realname,remap->second.c_str());
239 realname=remap->second.c_str();
243 m_map[string("{") + ns.get() + '}' + realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
244 log.debug("added property {%s}%s (%s)",ns.get(),realname,val);
247 m_map[realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
248 log.debug("added property %s (%s)",realname,val);
253 // Process non-excluded elements as nested sets.
254 DOMTreeWalker* walker=
255 static_cast<DOMDocumentTraversal*>(
256 m_root->getOwnerDocument())->createTreeWalker(const_cast<DOMElement*>(m_root),DOMNodeFilter::SHOW_ELEMENT,filter,false
258 e=static_cast<DOMElement*>(walker->firstChild());
260 auto_ptr_char ns(e->getNamespaceURI());
261 auto_ptr_char name(e->getLocalName());
262 const char* realname=name.get();
264 map<string,string>::const_iterator remap=remapper->find(realname);
265 if (remap!=remapper->end()) {
266 log.debug("remapping property set (%s) to (%s)",realname,remap->second.c_str());
267 realname=remap->second.c_str();
272 key=string("{") + ns.get() + '}' + realname;
275 if (m_nested.find(key)!=m_nested.end())
276 log.warn("load() skipping duplicate property set: %s",key.c_str());
278 XMLPropertySet* set=new XMLPropertySet();
279 set->load(e,log,filter,remapper);
281 log.debug("added nested property set: %s",key.c_str());
283 e=static_cast<DOMElement*>(walker->nextSibling());
288 pair<bool,bool> XMLPropertySet::getBool(const char* name, const char* ns) const
290 pair<bool,bool> ret=pair<bool,bool>(false,false);
291 map<string,pair<char*,const XMLCh*> >::const_iterator i;
294 i=m_map.find(string("{") + ns + '}' + name);
298 if (i!=m_map.end()) {
300 ret.second=(!strcmp(i->second.first,"true") || !strcmp(i->second.first,"1"));
305 pair<bool,const char*> XMLPropertySet::getString(const char* name, const char* ns) const
307 pair<bool,const char*> ret=pair<bool,const char*>(false,NULL);
308 map<string,pair<char*,const XMLCh*> >::const_iterator i;
311 i=m_map.find(string("{") + ns + '}' + name);
315 if (i!=m_map.end()) {
317 ret.second=i->second.first;
322 pair<bool,const XMLCh*> XMLPropertySet::getXMLString(const char* name, const char* ns) const
324 pair<bool,const XMLCh*> ret=pair<bool,const XMLCh*>(false,NULL);
325 map<string,pair<char*,const XMLCh*> >::const_iterator i;
328 i=m_map.find(string("{") + ns + '}' + name);
332 if (i!=m_map.end()) {
334 ret.second=i->second.second;
339 pair<bool,unsigned int> XMLPropertySet::getUnsignedInt(const char* name, const char* ns) const
341 pair<bool,unsigned int> ret=pair<bool,unsigned int>(false,0);
342 map<string,pair<char*,const XMLCh*> >::const_iterator i;
345 i=m_map.find(string("{") + ns + '}' + name);
349 if (i!=m_map.end()) {
351 ret.second=strtol(i->second.first,NULL,10);
356 pair<bool,int> XMLPropertySet::getInt(const char* name, const char* ns) const
358 pair<bool,int> ret=pair<bool,int>(false,0);
359 map<string,pair<char*,const XMLCh*> >::const_iterator i;
362 i=m_map.find(string("{") + ns + '}' + name);
366 if (i!=m_map.end()) {
368 ret.second=atoi(i->second.first);
373 const IPropertySet* XMLPropertySet::getPropertySet(const char* name, const char* ns) const
375 map<string,IPropertySet*>::const_iterator i;
378 i=m_nested.find(string("{") + ns + '}' + name);
380 i=m_nested.find(name);
382 return (i!=m_nested.end()) ? i->second : NULL;
385 XMLApplication::XMLApplication(
387 const Iterator<ICredentials*>& creds,
389 const XMLApplication* base
390 ) : m_ini(ini), m_base(base), m_profile(NULL), m_binding(NULL), m_bindingHook(NULL),
391 m_credDefault(NULL), m_sessionInitDefault(NULL), m_acsDefault(NULL)
394 saml::NDC ndc("XMLApplication");
396 Category& log=Category::getInstance("shibtarget.XMLApplication");
399 // First load any property sets.
400 map<string,string> root_remap;
401 root_remap["shire"]="session";
402 root_remap["shireURL"]="handlerURL";
403 root_remap["shireSSL"]="handlerSSL";
404 load(e,log,this,&root_remap);
405 const IPropertySet* propcheck=getPropertySet("Errors");
406 if (propcheck && !propcheck->getString("session").first)
407 throw ConfigurationException("<Errors> element requires 'session' (or deprecated 'shire') attribute");
408 propcheck=getPropertySet("Sessions");
409 if (propcheck && !propcheck->getString("handlerURL").first)
410 throw ConfigurationException("<Sessions> element requires 'handlerURL' (or deprecated 'shireURL') attribute");
413 m_hash+=getString("providerId").second;
414 m_hash=SAMLArtifact::toHex(SAMLArtifactType0001::generateSourceId(m_hash.c_str()));
416 ShibTargetConfig& conf=ShibTargetConfig::getConfig();
417 SAMLConfig& shibConf=SAMLConfig::getConfig();
419 if (conf.isEnabled(ShibTargetConfig::RequestMapper)) {
421 bool hardACS=false, hardSessionInit=false;
422 DOMElement* handler=saml::XML::getFirstChildElement(propcheck->getElement());
424 XMLPropertySet* hprops=new XMLPropertySet();
425 hprops->load(handler,log,this); // filter irrelevant for now, no embedded elements expected
426 m_handlerMap[hprops->getString("Location").second]=hprops;
428 // If it's an ACS or SI, handle lookup mappings and defaulting.
429 if (saml::XML::isElementNamed(handler,shibtarget::XML::SAML2META_NS,SHIBT_L(AssertionConsumerService))) {
430 m_acsMap[hprops->getUnsignedInt("index").second]=hprops;
432 pair<bool,bool> defprop=hprops->getBool("isDefault");
434 if (defprop.second) {
439 else if (!m_acsDefault)
443 else if (saml::XML::isElementNamed(handler,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(SessionInitiator))) {
444 pair<bool,const char*> si_id=hprops->getString("id");
445 if (si_id.first && si_id.second)
446 m_sessionInitMap[si_id.second]=hprops;
447 if (!hardSessionInit) {
448 pair<bool,bool> defprop=hprops->getBool("isDefault");
450 if (defprop.second) {
451 hardSessionInit=true;
452 m_sessionInitDefault=hprops;
455 else if (!m_sessionInitDefault)
456 m_sessionInitDefault=hprops;
459 handler=saml::XML::getNextSiblingElement(handler);
463 // Process general configuration elements.
465 DOMNodeList* nlist=e->getElementsByTagNameNS(saml::XML::SAML_NS,L(AttributeDesignator));
466 for (i=0; nlist && i<nlist->getLength(); i++)
467 m_designators.push_back(new SAMLAttributeDesignator(static_cast<DOMElement*>(nlist->item(i))));
469 nlist=e->getElementsByTagNameNS(saml::XML::SAML_NS,L(Audience));
470 for (i=0; nlist && i<nlist->getLength(); i++)
471 m_audiences.push_back(nlist->item(i)->getFirstChild()->getNodeValue());
473 // Always include our own providerId as an audience.
474 m_audiences.push_back(getXMLString("providerId").second);
476 if (conf.isEnabled(ShibTargetConfig::AAP)) {
477 nlist=e->getElementsByTagNameNS(ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(AAPProvider));
478 for (i=0; nlist && i<nlist->getLength(); i++) {
479 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
480 log.info("building AAP provider of type %s...",type.get());
481 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
482 IAAP* aap=dynamic_cast<IAAP*>(plugin);
484 m_aaps.push_back(aap);
487 log.fatal("plugin was not an AAP provider");
488 throw UnsupportedExtensionException("plugin was not an AAP provider");
493 if (conf.isEnabled(ShibTargetConfig::Metadata)) {
494 nlist=e->getElementsByTagNameNS(ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(MetadataProvider));
495 for (i=0; nlist && i<nlist->getLength(); i++) {
496 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
497 log.info("building metadata provider of type %s...",type.get());
498 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
499 IMetadata* md=dynamic_cast<IMetadata*>(plugin);
501 m_metadatas.push_back(md);
504 log.fatal("plugin was not a metadata provider");
505 throw UnsupportedExtensionException("plugin was not a metadata provider");
508 nlist=e->getElementsByTagNameNS(ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(FederationProvider));
509 for (i=0; nlist && i<nlist->getLength(); i++) {
510 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
511 log.info("building metadata provider of type %s...",type.get());
512 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
513 IMetadata* md=dynamic_cast<IMetadata*>(plugin);
515 m_metadatas.push_back(md);
518 log.fatal("plugin was not a metadata provider");
519 throw UnsupportedExtensionException("plugin was not a metadata provider");
524 if (conf.isEnabled(ShibTargetConfig::Trust)) {
525 nlist=e->getElementsByTagNameNS(ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(TrustProvider));
526 for (i=0; nlist && i<nlist->getLength(); i++) {
527 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
528 log.info("building trust provider of type %s...",type.get());
529 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
530 ITrust* trust=dynamic_cast<ITrust*>(plugin);
532 m_trusts.push_back(trust);
535 log.fatal("plugin was not a trust provider");
536 throw UnsupportedExtensionException("plugin was not a trust provider");
541 // Finally, load credential mappings.
542 const DOMElement* cu=saml::XML::getFirstChildElement(e,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(CredentialUse));
544 m_credDefault=new XMLPropertySet();
545 m_credDefault->load(cu,log,this);
546 cu=saml::XML::getFirstChildElement(cu,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(RelyingParty));
548 XMLPropertySet* rp=new XMLPropertySet();
549 rp->load(cu,log,this);
550 m_credMap[cu->getAttributeNS(NULL,SHIBT_L(Name))]=rp;
551 cu=saml::XML::getNextSiblingElement(cu,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(RelyingParty));
555 if (conf.isEnabled(ShibTargetConfig::Caching)) {
556 // Really finally, build local browser profile and binding objects.
557 m_profile=new ShibBrowserProfile(
558 getMetadataProviders(),
561 m_bindingHook=new ShibHTTPHook(
565 m_binding=SAMLBinding::getInstance(SAMLBinding::SOAP);
566 SAMLSOAPHTTPBinding* bptr=dynamic_cast<SAMLSOAPHTTPBinding*>(m_binding);
568 log.fatal("binding implementation was not SOAP over HTTP");
569 throw UnsupportedExtensionException("binding implementation was not SOAP over HTTP");
571 bptr->addHook(m_bindingHook,m_bindingHook); // the hook is its own global context
574 catch (SAMLException& e) {
575 log.errorStream() << "Error while processing applicaton element: " << e.what() << CategoryStream::ENDLINE;
581 log.error("Unexpected error while processing application element");
588 void XMLApplication::cleanup()
590 delete m_bindingHook;
593 map<string,XMLPropertySet*>::iterator h=m_handlerMap.begin();
594 while (h!=m_handlerMap.end()) {
598 delete m_credDefault;
600 map<xstring,XMLPropertySet*>::iterator c=m_credMap.begin();
602 map<const XMLCh*,XMLPropertySet*>::iterator c=m_credMap.begin();
604 while (c!=m_credMap.end()) {
608 Iterator<SAMLAttributeDesignator*> i(m_designators);
611 Iterator<IAAP*> j(m_aaps);
614 Iterator<IMetadata*> k(m_metadatas);
617 Iterator<ITrust*> l(m_trusts);
622 short XMLApplication::acceptNode(const DOMNode* node) const
624 if (saml::XML::isElementNamed(static_cast<const DOMElement*>(node),saml::XML::SAML_NS,L(AttributeDesignator)))
625 return FILTER_REJECT;
626 else if (saml::XML::isElementNamed(static_cast<const DOMElement*>(node),saml::XML::SAML_NS,L(Audience)))
627 return FILTER_REJECT;
628 const XMLCh* name=node->getLocalName();
629 if (!XMLString::compareString(name,SHIBT_L(Application)) ||
630 !XMLString::compareString(name,SHIBT_L(AssertionConsumerService)) ||
631 !XMLString::compareString(name,SHIBT_L(SingleLogoutService)) ||
632 !XMLString::compareString(name,SHIBT_L(SessionInitiator)) ||
633 !XMLString::compareString(name,SHIBT_L(AAPProvider)) ||
634 !XMLString::compareString(name,SHIBT_L(CredentialUse)) ||
635 !XMLString::compareString(name,SHIBT_L(RelyingParty)) ||
636 !XMLString::compareString(name,SHIBT_L(FederationProvider)) ||
637 !XMLString::compareString(name,SHIBT_L(TrustProvider)))
638 return FILTER_REJECT;
640 return FILTER_ACCEPT;
643 pair<bool,bool> XMLApplication::getBool(const char* name, const char* ns) const
645 pair<bool,bool> ret=XMLPropertySet::getBool(name,ns);
648 return m_base ? m_base->getBool(name,ns) : ret;
651 pair<bool,const char*> XMLApplication::getString(const char* name, const char* ns) const
653 pair<bool,const char*> ret=XMLPropertySet::getString(name,ns);
656 return m_base ? m_base->getString(name,ns) : ret;
659 pair<bool,const XMLCh*> XMLApplication::getXMLString(const char* name, const char* ns) const
661 pair<bool,const XMLCh*> ret=XMLPropertySet::getXMLString(name,ns);
664 return m_base ? m_base->getXMLString(name,ns) : ret;
667 pair<bool,unsigned int> XMLApplication::getUnsignedInt(const char* name, const char* ns) const
669 pair<bool,unsigned int> ret=XMLPropertySet::getUnsignedInt(name,ns);
672 return m_base ? m_base->getUnsignedInt(name,ns) : ret;
675 pair<bool,int> XMLApplication::getInt(const char* name, const char* ns) const
677 pair<bool,int> ret=XMLPropertySet::getInt(name,ns);
680 return m_base ? m_base->getInt(name,ns) : ret;
683 const IPropertySet* XMLApplication::getPropertySet(const char* name, const char* ns) const
685 const IPropertySet* ret=XMLPropertySet::getPropertySet(name,ns);
688 return m_base->getPropertySet(name,ns);
691 Iterator<SAMLAttributeDesignator*> XMLApplication::getAttributeDesignators() const
693 if (!m_designators.empty() || !m_base)
694 return m_designators;
695 return m_base->getAttributeDesignators();
698 Iterator<IAAP*> XMLApplication::getAAPProviders() const
700 return (m_aaps.empty() && m_base) ? m_base->getAAPProviders() : m_aaps;
703 Iterator<IMetadata*> XMLApplication::getMetadataProviders() const
705 return (m_metadatas.empty() && m_base) ? m_base->getMetadataProviders() : m_metadatas;
708 Iterator<ITrust*> XMLApplication::getTrustProviders() const
710 return (m_trusts.empty() && m_base) ? m_base->getTrustProviders() : m_trusts;
713 Iterator<const XMLCh*> XMLApplication::getAudiences() const
715 return (m_audiences.empty() && m_base) ? m_base->getAudiences() : m_audiences;
718 const IPropertySet* XMLApplication::getCredentialUse(const IEntityDescriptor* provider) const
720 if (!m_credDefault && m_base)
721 return m_base->getCredentialUse(provider);
724 map<xstring,XMLPropertySet*>::const_iterator i=m_credMap.find(provider->getId());
725 if (i!=m_credMap.end())
727 const IEntitiesDescriptor* group=provider->getEntitiesDescriptor();
729 i=m_credMap.find(group->getName());
730 if (i!=m_credMap.end())
732 group=group->getEntitiesDescriptor();
735 map<const XMLCh*,XMLPropertySet*>::const_iterator i=m_credMap.begin();
736 for (; i!=m_credMap.end(); i++) {
737 if (!XMLString::compareString(i->first,provider->getId()))
739 const IEntitiesDescriptor* group=provider->getEntitiesDescriptor();
741 if (!XMLString::compareString(i->first,group->getName()))
743 group=group->getEntitiesDescriptor();
747 return m_credDefault;
750 const IPropertySet* XMLApplication::getDefaultSessionInitiator() const
752 if (m_sessionInitDefault) return m_sessionInitDefault;
753 return m_base ? m_base->getDefaultSessionInitiator() : NULL;
756 const IPropertySet* XMLApplication::getSessionInitiatorById(const char* id) const
758 map<string,const IPropertySet*>::const_iterator i=m_sessionInitMap.find(id);
759 if (i!=m_sessionInitMap.end()) return i->second;
760 return m_base ? m_base->getSessionInitiatorById(id) : NULL;
763 const IPropertySet* XMLApplication::getDefaultAssertionConsumerService() const
765 if (m_acsDefault) return m_acsDefault;
766 return m_base ? m_base->getDefaultAssertionConsumerService() : NULL;
769 const IPropertySet* XMLApplication::getAssertionConsumerServiceByIndex(unsigned short index) const
771 map<unsigned int,const IPropertySet*>::const_iterator i=m_acsMap.find(index);
772 if (i!=m_acsMap.end()) return i->second;
773 return m_base ? m_base->getAssertionConsumerServiceByIndex(index) : NULL;
776 const IPropertySet* XMLApplication::getHandler(const char* path) const
779 map<string,XMLPropertySet*>::const_iterator i=m_handlerMap.find(wrap.substr(0,wrap.find('?')));
780 return (i!=m_handlerMap.end()) ? i->second : NULL;
783 ReloadableXMLFileImpl* XMLConfig::newImplementation(const char* pathname, bool first) const
785 return new XMLConfigImpl(pathname,first,this);
788 ReloadableXMLFileImpl* XMLConfig::newImplementation(const DOMElement* e, bool first) const
790 return new XMLConfigImpl(e,first,this);
793 short XMLConfigImpl::acceptNode(const DOMNode* node) const
795 if (XMLString::compareString(node->getNamespaceURI(),ShibTargetConfig::SHIBTARGET_NS))
796 return FILTER_ACCEPT;
797 const XMLCh* name=node->getLocalName();
798 if (!XMLString::compareString(name,SHIBT_L(Applications)) ||
799 !XMLString::compareString(name,SHIBT_L(CredentialsProvider)) ||
800 !XMLString::compareString(name,SHIBT_L(Extensions)) ||
801 !XMLString::compareString(name,SHIBT_L(Implementation)) ||
802 !XMLString::compareString(name,SHIBT_L(Listener)) ||
803 !XMLString::compareString(name,SHIBT_L(MemorySessionCache)) ||
804 !XMLString::compareString(name,SHIBT_L(MySQLReplayCache)) ||
805 !XMLString::compareString(name,SHIBT_L(MySQLSessionCache)) ||
806 !XMLString::compareString(name,SHIBT_L(RequestMap)) ||
807 !XMLString::compareString(name,SHIBT_L(RequestMapProvider)) ||
808 !XMLString::compareString(name,SHIBT_L(ReplayCache)) ||
809 !XMLString::compareString(name,SHIBT_L(SessionCache)) ||
810 !XMLString::compareString(name,SHIBT_L(TCPListener)) ||
811 !XMLString::compareString(name,SHIBT_L(UnixListener)))
812 return FILTER_REJECT;
814 return FILTER_ACCEPT;
817 void XMLConfigImpl::init(bool first)
820 saml::NDC ndc("init");
822 Category& log=Category::getInstance("shibtarget.XMLConfig");
825 if (!saml::XML::isElementNamed(ReloadableXMLFileImpl::m_root,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(ShibbolethTargetConfig)) &&
826 !saml::XML::isElementNamed(ReloadableXMLFileImpl::m_root,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(SPConfig))) {
827 log.error("Construction requires a valid configuration file: (conf:SPConfig as root element)");
828 throw ConfigurationException("Construction requires a valid configuration file: (conf:SPConfig as root element)");
831 SAMLConfig& shibConf=SAMLConfig::getConfig();
832 ShibTargetConfig& conf=ShibTargetConfig::getConfig();
833 const DOMElement* SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(SHAR));
835 SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Global));
836 const DOMElement* SHIRE=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(SHIRE));
838 SHIRE=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Local));
840 // Initialize log4cpp manually in order to redirect log messages as soon as possible.
841 if (conf.isEnabled(ShibTargetConfig::Logging)) {
842 const XMLCh* logger=NULL;
843 if (conf.isEnabled(ShibTargetConfig::GlobalExtensions))
844 logger=SHAR->getAttributeNS(NULL,SHIBT_L(logger));
845 else if (conf.isEnabled(ShibTargetConfig::LocalExtensions))
846 logger=SHIRE->getAttributeNS(NULL,SHIBT_L(logger));
847 if (!logger || !*logger)
848 logger=ReloadableXMLFileImpl::m_root->getAttributeNS(NULL,SHIBT_L(logger));
849 if (logger && *logger) {
850 auto_ptr_char logpath(logger);
851 cerr << "loading new logging configuration from " << logpath.get() << "\n";
853 PropertyConfigurator::configure(logpath.get());
854 cerr << "New logging configuration loaded, check log destination for process status..." << "\n";
856 catch (ConfigureFailure& e) {
857 cerr << "Error reading logging configuration: " << e.what() << "\n";
862 // First load any property sets.
863 map<string,string> root_remap;
864 root_remap["SHAR"]="Global";
865 root_remap["SHIRE"]="Local";
866 load(ReloadableXMLFileImpl::m_root,log,this,&root_remap);
868 // Much of the processing can only occur on the first instantiation.
870 // Now load any extensions to insure any needed plugins are registered.
872 saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Extensions));
874 exts=saml::XML::getFirstChildElement(exts,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Library));
876 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
878 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
879 log.debug("loaded global extension library %s",path.get());
881 catch (SAMLException& e) {
882 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
883 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
884 log.fatal("unable to load mandatory global extension library %s: %s", path.get(), e.what());
888 log.crit("unable to load optional global extension library %s: %s", path.get(), e.what());
890 exts=saml::XML::getNextSiblingElement(exts,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Library));
894 if (conf.isEnabled(ShibTargetConfig::GlobalExtensions)) {
895 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Extensions));
897 exts=saml::XML::getFirstChildElement(exts,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Library));
899 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
901 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
902 log.debug("loaded Global extension library %s",path.get());
904 catch (SAMLException& e) {
905 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
906 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
907 log.fatal("unable to load mandatory Global extension library %s: %s", path.get(), e.what());
911 log.crit("unable to load optional Global extension library %s: %s", path.get(), e.what());
913 exts=saml::XML::getNextSiblingElement(exts,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Library));
918 if (conf.isEnabled(ShibTargetConfig::LocalExtensions)) {
919 exts=saml::XML::getFirstChildElement(SHIRE,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Extensions));
921 exts=saml::XML::getFirstChildElement(exts,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Library));
923 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
925 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
926 log.debug("loaded Local extension library %s",path.get());
928 catch (SAMLException& e) {
929 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
930 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
931 log.fatal("unable to load mandatory Local extension library %s: %s", path.get(), e.what());
935 log.crit("unable to load optional Local extension library %s: %s", path.get(), e.what());
937 exts=saml::XML::getNextSiblingElement(exts,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Library));
942 // Instantiate the Listener and SessionCache objects.
943 if (conf.isEnabled(ShibTargetConfig::Listener)) {
944 IPlugIn* plugin=NULL;
945 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(UnixListener));
947 log.info("building Listener of type %s...",shibtarget::XML::UnixListenerType);
948 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::UnixListenerType,exts);
951 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(TCPListener));
953 log.info("building Listener of type %s...",shibtarget::XML::TCPListenerType);
954 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::TCPListenerType,exts);
957 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Listener));
959 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
960 log.info("building Listener of type %s...",type.get());
961 plugin=shibConf.getPlugMgr().newPlugin(type.get(),exts);
964 log.fatal("can't build Listener object, missing conf:Listener element?");
965 throw ConfigurationException("can't build Listener object, missing conf:Listener element?");
970 IListener* listen=dynamic_cast<IListener*>(plugin);
972 m_outer->m_listener=listen;
975 log.fatal("plugin was not a Listener object");
976 throw UnsupportedExtensionException("plugin was not a Listener object");
981 if (conf.isEnabled(ShibTargetConfig::Caching)) {
982 IPlugIn* plugin=NULL;
983 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(MemorySessionCache));
985 log.info("building Session Cache of type %s...",shibtarget::XML::MemorySessionCacheType);
986 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::MemorySessionCacheType,exts);
989 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(MySQLSessionCache));
991 log.info("building Session Cache of type %s...",shibtarget::XML::MySQLSessionCacheType);
992 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::MySQLSessionCacheType,exts);
995 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(SessionCache));
997 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
998 log.info("building Session Cache of type %s...",type.get());
999 plugin=shibConf.getPlugMgr().newPlugin(type.get(),exts);
1002 log.fatal("can't build Session Cache object, missing conf:SessionCache element?");
1003 throw ConfigurationException("can't build Session Cache object, missing conf:SessionCache element?");
1008 ISessionCache* cache=dynamic_cast<ISessionCache*>(plugin);
1010 m_outer->m_sessionCache=cache;
1013 log.fatal("plugin was not a Session Cache object");
1014 throw UnsupportedExtensionException("plugin was not a Session Cache object");
1019 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(MySQLReplayCache));
1021 log.info("building Replay Cache of type %s...",shibtarget::XML::MySQLReplayCacheType);
1022 m_outer->m_replayCache=IReplayCache::getInstance(shibtarget::XML::MySQLSessionCacheType,exts);
1025 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(ReplayCache));
1027 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
1028 log.info("building Replay Cache of type %s...",type.get());
1029 m_outer->m_replayCache=IReplayCache::getInstance(type.get(),exts);
1032 // OpenSAML default provider.
1033 log.info("building default Replay Cache...");
1034 m_outer->m_replayCache=IReplayCache::getInstance();
1040 // Back to the fully dynamic stuff...next up is the Request Mapper.
1041 if (conf.isEnabled(ShibTargetConfig::RequestMapper)) {
1042 const DOMElement* child=saml::XML::getFirstChildElement(SHIRE,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(RequestMapProvider));
1044 auto_ptr_char type(child->getAttributeNS(NULL,SHIBT_L(type)));
1045 log.info("building Request Mapper of type %s...",type.get());
1046 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),child);
1048 IRequestMapper* reqmap=dynamic_cast<IRequestMapper*>(plugin);
1050 m_requestMapper=reqmap;
1053 log.fatal("plugin was not a Request Mapper object");
1054 throw UnsupportedExtensionException("plugin was not a Request Mapper object");
1059 log.fatal("can't build Request Mapper object, missing conf:RequestMapProvider element?");
1060 throw ConfigurationException("can't build Request Mapper object, missing conf:RequestMapProvider element?");
1064 // Now we load any credentials providers.
1066 if (conf.isEnabled(ShibTargetConfig::Credentials)) {
1067 nlist=ReloadableXMLFileImpl::m_root->getElementsByTagNameNS(
1068 ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(CredentialsProvider)
1070 for (int i=0; nlist && i<nlist->getLength(); i++) {
1071 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
1072 log.info("building Credentials provider of type %s...",type.get());
1073 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
1075 ICredentials* creds=dynamic_cast<ICredentials*>(plugin);
1077 m_creds.push_back(creds);
1080 log.fatal("plugin was not a Credentials provider");
1081 throw UnsupportedExtensionException("plugin was not a Credentials provider");
1087 // Load the default application. This actually has a fixed ID of "default". ;-)
1088 const DOMElement* app=saml::XML::getFirstChildElement(
1089 ReloadableXMLFileImpl::m_root,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Applications)
1092 log.fatal("can't build default Application object, missing conf:Applications element?");
1093 throw ConfigurationException("can't build default Application object, missing conf:Applications element?");
1095 XMLApplication* defapp=new XMLApplication(m_outer, m_creds, app);
1096 m_appmap[defapp->getId()]=defapp;
1098 // Load any overrides.
1099 nlist=app->getElementsByTagNameNS(ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Application));
1100 for (int i=0; nlist && i<nlist->getLength(); i++) {
1101 XMLApplication* iapp=new XMLApplication(m_outer,m_creds,static_cast<DOMElement*>(nlist->item(i)),defapp);
1102 if (m_appmap.find(iapp->getId())!=m_appmap.end()) {
1103 log.fatal("found conf:Application element with duplicate Id attribute");
1104 throw ConfigurationException("found conf:Application element with duplicate Id attribute");
1106 m_appmap[iapp->getId()]=iapp;
1109 catch (SAMLException& e) {
1110 log.errorStream() << "Error while loading SP configuration: " << e.what() << CategoryStream::ENDLINE;
1115 log.error("Unexpected error while loading SP configuration");
1121 XMLConfigImpl::~XMLConfigImpl()
1123 delete m_requestMapper;
1124 for (map<string,IApplication*>::iterator i=m_appmap.begin(); i!=m_appmap.end(); i++)
1126 for (vector<ICredentials*>::iterator j=m_creds.begin(); j!=m_creds.end(); j++)