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 DOMElement* e, const XMLApplication* base=NULL);
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 Iterator<SAMLAttributeDesignator*> getAttributeDesignators() const;
91 Iterator<IAAP*> getAAPProviders() const;
92 Iterator<IMetadata*> getMetadataProviders() const;
93 Iterator<ITrust*> getTrustProviders() const;
94 Iterator<IRevocation*> getRevocationProviders() const;
95 Iterator<const XMLCh*> getAudiences() const;
96 const char* getTLSCred(const IEntityDescriptor* provider) const {return getCredentialUse(provider).first.c_str();}
97 const char* getSigningCred(const IEntityDescriptor* provider) const {return getCredentialUse(provider).second.c_str();}
98 SAMLBrowserProfile* getBrowserProfile() const {return m_profile;}
100 // Provides filter to exclude special config elements.
101 short acceptNode(const DOMNode* node) const;
104 const IConfig* m_ini; // this is ok because its locking scope includes us
105 const XMLApplication* m_base;
106 vector<SAMLAttributeDesignator*> m_designators;
107 vector<IAAP*> m_aaps;
108 vector<IMetadata*> m_metadatas;
109 vector<ITrust*> m_trusts;
110 vector<IRevocation*> m_revocations;
111 vector<const XMLCh*> m_audiences;
112 pair<string,string> m_credDefault;
113 ShibBrowserProfile* m_profile;
115 map<xstring,pair<string,string> > m_credMap;
117 map<const XMLCh*,pair<string,string> > m_credMap;
119 const pair<string,string>& getCredentialUse(const IEntityDescriptor* provider) const;
122 // Top-level configuration implementation
124 class XMLConfigImpl : public ReloadableXMLFileImpl, public XMLPropertySet, public DOMNodeFilter
127 XMLConfigImpl(const char* pathname, bool first, const XMLConfig* outer)
128 : ReloadableXMLFileImpl(pathname), m_outer(outer), m_requestMapper(NULL) { init(first); }
129 XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer)
130 : ReloadableXMLFileImpl(e), m_outer(outer), m_requestMapper(NULL) { init(first); }
133 IRequestMapper* m_requestMapper;
134 map<string,IApplication*> m_appmap;
135 vector<ICredentials*> m_creds;
137 // Provides filter to exclude special config elements.
138 short acceptNode(const DOMNode* node) const;
141 void init(bool first);
142 const XMLConfig* m_outer;
145 class XMLConfig : public IConfig, public ReloadableXMLFile
148 XMLConfig(const DOMElement* e) : ReloadableXMLFile(e), m_listener(NULL), m_sessionCache(NULL), m_replayCache(NULL) {}
149 ~XMLConfig() {delete m_listener; delete m_sessionCache; delete m_replayCache;}
152 pair<bool,bool> getBool(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getBool(name,ns);}
153 pair<bool,const char*> getString(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getString(name,ns);}
154 pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getXMLString(name,ns);}
155 pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getUnsignedInt(name,ns);}
156 pair<bool,int> getInt(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getInt(name,ns);}
157 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);}
158 const DOMElement* getElement() const {return static_cast<XMLConfigImpl*>(m_impl)->getElement();}
161 const IListener* getListener() const {return m_listener;}
162 ISessionCache* getSessionCache() const {return m_sessionCache;}
163 IReplayCache* getReplayCache() const {return m_replayCache;}
164 IRequestMapper* getRequestMapper() const {return static_cast<XMLConfigImpl*>(m_impl)->m_requestMapper;}
165 const IApplication* getApplication(const char* applicationId) const
167 map<string,IApplication*>::const_iterator i=static_cast<XMLConfigImpl*>(m_impl)->m_appmap.find(applicationId);
168 return (i!=static_cast<XMLConfigImpl*>(m_impl)->m_appmap.end()) ? i->second : NULL;
170 Iterator<ICredentials*> getCredentialsProviders() const {return static_cast<XMLConfigImpl*>(m_impl)->m_creds;}
173 virtual ReloadableXMLFileImpl* newImplementation(const char* pathname, bool first=true) const;
174 virtual ReloadableXMLFileImpl* newImplementation(const DOMElement* e, bool first=true) const;
177 friend class XMLConfigImpl;
178 mutable IListener* m_listener;
179 mutable ISessionCache* m_sessionCache;
180 mutable IReplayCache* m_replayCache;
184 IConfig* STConfig::ShibTargetConfigFactory(const DOMElement* e)
186 XMLConfig* ret=new XMLConfig(e);
188 ret->getImplementation();
197 XMLPropertySet::~XMLPropertySet()
199 for (map<string,pair<char*,const XMLCh*> >::iterator i=m_map.begin(); i!=m_map.end(); i++)
200 XMLString::release(&(i->second.first));
201 for (map<string,IPropertySet*>::iterator j=m_nested.begin(); j!=m_nested.end(); j++)
205 void XMLPropertySet::load(const DOMElement* e, Category& log, DOMNodeFilter* filter)
210 // Process each attribute as a property.
211 DOMNamedNodeMap* attrs=m_root->getAttributes();
212 for (XMLSize_t i=0; i<attrs->getLength(); i++) {
213 DOMNode* a=attrs->item(i);
214 if (!XMLString::compareString(a->getNamespaceURI(),saml::XML::XMLNS_NS))
216 char* val=XMLString::transcode(a->getNodeValue());
218 auto_ptr_char ns(a->getNamespaceURI());
219 auto_ptr_char name(a->getLocalName());
221 m_map[string("{") + ns.get() + '}' + name.get()]=pair<char*,const XMLCh*>(val,a->getNodeValue());
222 log.debug("added property {%s}%s (%s)",ns.get(),name.get(),val);
225 m_map[name.get()]=pair<char*,const XMLCh*>(val,a->getNodeValue());
226 log.debug("added property %s (%s)",name.get(),val);
231 // Process non-excluded elements as nested sets.
232 DOMTreeWalker* walker=
233 static_cast<DOMDocumentTraversal*>(
234 m_root->getOwnerDocument())->createTreeWalker(const_cast<DOMElement*>(m_root),DOMNodeFilter::SHOW_ELEMENT,filter,false
236 e=static_cast<DOMElement*>(walker->firstChild());
238 auto_ptr_char ns(e->getNamespaceURI());
239 auto_ptr_char name(e->getLocalName());
242 key=string("{") + ns.get() + '}' + name.get();
245 if (m_nested.find(key)!=m_nested.end())
246 log.warn("load() skipping duplicate property set: %s",key.c_str());
248 XMLPropertySet* set=new XMLPropertySet();
249 set->load(e,log,filter);
251 log.debug("added nested property set: %s",key.c_str());
253 e=static_cast<DOMElement*>(walker->nextSibling());
258 pair<bool,bool> XMLPropertySet::getBool(const char* name, const char* ns) const
260 pair<bool,bool> ret=pair<bool,bool>(false,false);
261 map<string,pair<char*,const XMLCh*> >::const_iterator i;
264 i=m_map.find(string("{") + ns + '}' + name);
268 if (i!=m_map.end()) {
270 ret.second=(!strcmp(i->second.first,"true") || !strcmp(i->second.first,"1"));
275 pair<bool,const char*> XMLPropertySet::getString(const char* name, const char* ns) const
277 pair<bool,const char*> ret=pair<bool,const char*>(false,NULL);
278 map<string,pair<char*,const XMLCh*> >::const_iterator i;
281 i=m_map.find(string("{") + ns + '}' + name);
285 if (i!=m_map.end()) {
287 ret.second=i->second.first;
292 pair<bool,const XMLCh*> XMLPropertySet::getXMLString(const char* name, const char* ns) const
294 pair<bool,const XMLCh*> ret=pair<bool,const XMLCh*>(false,NULL);
295 map<string,pair<char*,const XMLCh*> >::const_iterator i;
298 i=m_map.find(string("{") + ns + '}' + name);
302 if (i!=m_map.end()) {
304 ret.second=i->second.second;
309 pair<bool,unsigned int> XMLPropertySet::getUnsignedInt(const char* name, const char* ns) const
311 pair<bool,unsigned int> ret=pair<bool,unsigned int>(false,0);
312 map<string,pair<char*,const XMLCh*> >::const_iterator i;
315 i=m_map.find(string("{") + ns + '}' + name);
319 if (i!=m_map.end()) {
321 ret.second=strtol(i->second.first,NULL,10);
326 pair<bool,int> XMLPropertySet::getInt(const char* name, const char* ns) const
328 pair<bool,int> ret=pair<bool,int>(false,0);
329 map<string,pair<char*,const XMLCh*> >::const_iterator i;
332 i=m_map.find(string("{") + ns + '}' + name);
336 if (i!=m_map.end()) {
338 ret.second=atoi(i->second.first);
343 const IPropertySet* XMLPropertySet::getPropertySet(const char* name, const char* ns) const
345 map<string,IPropertySet*>::const_iterator i;
348 i=m_nested.find(string("{") + ns + '}' + name);
350 i=m_nested.find(name);
352 return (i!=m_nested.end()) ? i->second : NULL;
355 XMLApplication::XMLApplication(const IConfig* ini, const DOMElement* e, const XMLApplication* base)
356 : m_ini(ini), m_base(base), m_profile(NULL)
358 NDC ndc("XMLApplication");
359 Category& log=Category::getInstance("shibtarget.XMLApplication");
362 // First load any property sets.
365 ShibTargetConfig& conf=ShibTargetConfig::getConfig();
366 SAMLConfig& shibConf=SAMLConfig::getConfig();
368 DOMNodeList* nlist=e->getElementsByTagNameNS(saml::XML::SAML_NS,L(AttributeDesignator));
369 for (i=0; nlist && i<nlist->getLength(); i++) {
370 m_designators.push_back(new SAMLAttributeDesignator(static_cast<DOMElement*>(nlist->item(i))));
373 nlist=e->getElementsByTagNameNS(saml::XML::SAML_NS,L(Audience));
374 for (i=0; nlist && i<nlist->getLength(); i++) {
375 m_audiences.push_back(nlist->item(i)->getFirstChild()->getNodeValue());
377 // Always include our own providerId as an audience.
378 m_audiences.push_back(getXMLString("providerId").second);
380 if (conf.isEnabled(ShibTargetConfig::AAP)) {
381 nlist=e->getElementsByTagNameNS(ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(AAPProvider));
382 for (i=0; nlist && i<nlist->getLength(); i++) {
383 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
384 log.info("building AAP provider of type %s...",type.get());
385 IPlugIn* plugin=shibConf.m_plugMgr.newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
386 IAAP* aap=dynamic_cast<IAAP*>(plugin);
388 m_aaps.push_back(aap);
391 log.fatal("plugin was not an AAP provider");
392 throw UnsupportedExtensionException("plugin was not an AAP provider");
397 if (conf.isEnabled(ShibTargetConfig::Metadata)) {
398 nlist=e->getElementsByTagNameNS(ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(FederationProvider));
399 for (i=0; nlist && i<nlist->getLength(); i++) {
400 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
401 log.info("building federation/metadata provider of type %s...",type.get());
402 IPlugIn* plugin=shibConf.m_plugMgr.newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
403 IMetadata* md=dynamic_cast<IMetadata*>(plugin);
405 m_metadatas.push_back(md);
408 log.fatal("plugin was not a federation/metadata provider");
409 throw UnsupportedExtensionException("plugin was not a federation/metadata provider");
414 if (conf.isEnabled(ShibTargetConfig::Trust)) {
415 nlist=e->getElementsByTagNameNS(ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(TrustProvider));
416 for (i=0; nlist && i<nlist->getLength(); i++) {
417 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
418 log.info("building trust provider of type %s...",type.get());
419 IPlugIn* plugin=shibConf.m_plugMgr.newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
420 ITrust* trust=dynamic_cast<ITrust*>(plugin);
422 m_trusts.push_back(trust);
425 log.fatal("plugin was not a trust provider");
426 throw UnsupportedExtensionException("plugin was not a trust provider");
429 nlist=e->getElementsByTagNameNS(ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(RevocationProvider));
430 for (i=0; nlist && i<nlist->getLength(); i++) {
431 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
432 log.info("building revocation provider of type %s...",type.get());
433 IPlugIn* plugin=shibConf.m_plugMgr.newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
434 IRevocation* rev=dynamic_cast<IRevocation*>(plugin);
436 m_revocations.push_back(rev);
439 log.fatal("plugin was not a revocation provider");
440 throw UnsupportedExtensionException("plugin was not a revocation provider");
445 // Finally, load credential mappings.
446 const DOMElement* cu=saml::XML::getFirstChildElement(e,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(CredentialUse));
448 auto_ptr_char TLS(cu->getAttributeNS(NULL,SHIBT_L(TLS)));
449 auto_ptr_char Signing(cu->getAttributeNS(NULL,SHIBT_L(Signing)));
450 m_credDefault.first=TLS.get();
451 m_credDefault.second=Signing.get();
452 cu=saml::XML::getFirstChildElement(cu,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(RelyingParty));
454 auto_ptr_char TLS2(cu->getAttributeNS(NULL,SHIBT_L(TLS)));
455 auto_ptr_char Signing2(cu->getAttributeNS(NULL,SHIBT_L(Signing)));
456 m_credMap[cu->getAttributeNS(NULL,SHIBT_L(Name))]=pair<string,string>(TLS2.get(),Signing2.get());
457 cu=saml::XML::getNextSiblingElement(cu,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(RelyingParty));
461 if (conf.isEnabled(ShibTargetConfig::SessionCache)) {
462 // Really finally, build a local browser profile object.
463 m_profile=new ShibBrowserProfile(
464 getMetadataProviders(),
465 getRevocationProviders(),
471 this->~XMLApplication(); // does this work?
476 XMLApplication::~XMLApplication()
479 Iterator<SAMLAttributeDesignator*> i(m_designators);
482 Iterator<IAAP*> j(m_aaps);
485 Iterator<IMetadata*> k(m_metadatas);
488 Iterator<ITrust*> l(m_trusts);
491 Iterator<IRevocation*> m(m_revocations);
496 short XMLApplication::acceptNode(const DOMNode* node) const
498 if (saml::XML::isElementNamed(static_cast<const DOMElement*>(node),saml::XML::SAML_NS,L(AttributeDesignator)))
499 return FILTER_REJECT;
500 else if (saml::XML::isElementNamed(static_cast<const DOMElement*>(node),saml::XML::SAML_NS,L(Audience)))
501 return FILTER_REJECT;
502 if (XMLString::compareString(node->getNamespaceURI(),ShibTargetConfig::SHIBTARGET_NS))
503 return FILTER_ACCEPT;
504 const XMLCh* name=node->getLocalName();
505 if (!XMLString::compareString(name,SHIBT_L(Application)) ||
506 !XMLString::compareString(name,SHIBT_L(AAPProvider)) ||
507 !XMLString::compareString(name,SHIBT_L(CredentialUse)) ||
508 !XMLString::compareString(name,SHIBT_L(FederationProvider)) ||
509 !XMLString::compareString(name,SHIBT_L(RevocationProvider)) ||
510 !XMLString::compareString(name,SHIBT_L(TrustProvider)))
511 return FILTER_REJECT;
513 return FILTER_ACCEPT;
516 pair<bool,bool> XMLApplication::getBool(const char* name, const char* ns) const
518 pair<bool,bool> ret=XMLPropertySet::getBool(name,ns);
521 return m_base ? m_base->getBool(name,ns) : ret;
524 pair<bool,const char*> XMLApplication::getString(const char* name, const char* ns) const
526 pair<bool,const char*> ret=XMLPropertySet::getString(name,ns);
529 return m_base ? m_base->getString(name,ns) : ret;
532 pair<bool,const XMLCh*> XMLApplication::getXMLString(const char* name, const char* ns) const
534 pair<bool,const XMLCh*> ret=XMLPropertySet::getXMLString(name,ns);
537 return m_base ? m_base->getXMLString(name,ns) : ret;
540 pair<bool,unsigned int> XMLApplication::getUnsignedInt(const char* name, const char* ns) const
542 pair<bool,unsigned int> ret=XMLPropertySet::getUnsignedInt(name,ns);
545 return m_base ? m_base->getUnsignedInt(name,ns) : ret;
548 pair<bool,int> XMLApplication::getInt(const char* name, const char* ns) const
550 pair<bool,int> ret=XMLPropertySet::getInt(name,ns);
553 return m_base ? m_base->getInt(name,ns) : ret;
556 const IPropertySet* XMLApplication::getPropertySet(const char* name, const char* ns) const
558 const IPropertySet* ret=XMLPropertySet::getPropertySet(name,ns);
561 return m_base->getPropertySet(name,ns);
564 Iterator<SAMLAttributeDesignator*> XMLApplication::getAttributeDesignators() const
566 if (!m_designators.empty() || !m_base)
567 return m_designators;
568 return m_base->getAttributeDesignators();
571 Iterator<IAAP*> XMLApplication::getAAPProviders() const
573 return (m_aaps.empty() && m_base) ? m_base->getAAPProviders() : m_aaps;
576 Iterator<IMetadata*> XMLApplication::getMetadataProviders() const
578 return (m_metadatas.empty() && m_base) ? m_base->getMetadataProviders() : m_metadatas;
581 Iterator<ITrust*> XMLApplication::getTrustProviders() const
583 return (m_trusts.empty() && m_base) ? m_base->getTrustProviders() : m_trusts;
586 Iterator<IRevocation*> XMLApplication::getRevocationProviders() const
588 return (m_revocations.empty() && m_base) ? m_base->getRevocationProviders() : m_revocations;
591 Iterator<const XMLCh*> XMLApplication::getAudiences() const
593 return (m_audiences.empty() && m_base) ? m_base->getAudiences() : m_audiences;
596 const pair<string,string>& XMLApplication::getCredentialUse(const IEntityDescriptor* provider) const
598 if (m_credDefault.first.empty() && m_base)
599 return m_base->getCredentialUse(provider);
602 map<xstring,pair<string,string> >::const_iterator i=m_credMap.find(provider->getId());
603 if (i!=m_credMap.end())
605 const IEntitiesDescriptor* group=provider->getEntitiesDescriptor();
607 i=m_credMap.find(group->getName());
608 if (i!=m_credMap.end())
610 group=group->getEntitiesDescriptor();
613 map<const XMLCh*,pair<string,string> >::const_iterator i=m_credMap.begin();
614 for (; i!=m_credMap.end(); i++) {
615 if (!XMLString::compareString(i->first,provider->getId()))
617 const IEntitiesDescriptor* group=provider->getEntitiesDescriptor();
619 if (!XMLString::compareString(i->first,group->getName()))
621 group=group->getEntitiesDescriptor();
625 return m_credDefault;
628 ReloadableXMLFileImpl* XMLConfig::newImplementation(const char* pathname, bool first) const
630 return new XMLConfigImpl(pathname,first,this);
633 ReloadableXMLFileImpl* XMLConfig::newImplementation(const DOMElement* e, bool first) const
635 return new XMLConfigImpl(e,first,this);
638 short XMLConfigImpl::acceptNode(const DOMNode* node) const
640 if (XMLString::compareString(node->getNamespaceURI(),ShibTargetConfig::SHIBTARGET_NS))
641 return FILTER_ACCEPT;
642 const XMLCh* name=node->getLocalName();
643 if (!XMLString::compareString(name,SHIBT_L(Applications)) ||
644 !XMLString::compareString(name,SHIBT_L(CredentialsProvider)) ||
645 !XMLString::compareString(name,SHIBT_L(Extensions)) ||
646 !XMLString::compareString(name,SHIBT_L(Implementation)) ||
647 !XMLString::compareString(name,SHIBT_L(Listener)) ||
648 !XMLString::compareString(name,SHIBT_L(MemorySessionCache)) ||
649 !XMLString::compareString(name,SHIBT_L(MySQLSessionCache)) ||
650 !XMLString::compareString(name,SHIBT_L(RequestMap)) ||
651 !XMLString::compareString(name,SHIBT_L(RequestMapProvider)) ||
652 !XMLString::compareString(name,SHIBT_L(SessionCache)) ||
653 !XMLString::compareString(name,SHIBT_L(TCPListener)) ||
654 !XMLString::compareString(name,SHIBT_L(UnixListener)))
655 return FILTER_REJECT;
657 return FILTER_ACCEPT;
660 void XMLConfigImpl::init(bool first)
662 NDC ndc("XMLConfigImpl");
663 Category& log=Category::getInstance("shibtarget.XMLConfig");
666 if (!saml::XML::isElementNamed(ReloadableXMLFileImpl::m_root,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(ShibbolethTargetConfig))) {
667 log.error("Construction requires a valid configuration file: (conf:ShibbolethTargetConfig as root element)");
668 throw MalformedException("Construction requires a valid configuration file: (conf:ShibbolethTargetConfig as root element)");
671 SAMLConfig& shibConf=SAMLConfig::getConfig();
672 ShibTargetConfig& conf=ShibTargetConfig::getConfig();
673 const DOMElement* SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(SHAR));
674 const DOMElement* SHIRE=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(SHIRE));
676 // Initialize log4cpp manually in order to redirect log messages as soon as possible.
677 if (conf.isEnabled(ShibTargetConfig::Logging)) {
678 const XMLCh* logger=NULL;
679 if (conf.isEnabled(ShibTargetConfig::SHARExtensions))
680 logger=SHAR->getAttributeNS(NULL,SHIBT_L(logger));
681 else if (conf.isEnabled(ShibTargetConfig::SHIREExtensions))
682 logger=SHIRE->getAttributeNS(NULL,SHIBT_L(logger));
683 if (!logger || !*logger)
684 logger=ReloadableXMLFileImpl::m_root->getAttributeNS(NULL,SHIBT_L(logger));
685 if (logger && *logger) {
686 auto_ptr_char logpath(logger);
687 cerr << "loading new logging configuration from " << logpath.get() << "\n";
689 PropertyConfigurator::configure(logpath.get());
690 cerr << "New logging configuration loaded, check log destination for process status..." << "\n";
692 catch (ConfigureFailure& e) {
693 cerr << "Error reading logging configuration: " << e.what() << "\n";
698 // First load any property sets.
699 load(ReloadableXMLFileImpl::m_root,log,this);
701 // Much of the processing can only occur on the first instantiation.
703 // Now load any extensions to insure any needed plugins are registered.
705 saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Extensions));
707 exts=saml::XML::getFirstChildElement(exts,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Library));
709 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
711 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
712 log.debug("loaded global extension library %s",path.get());
714 catch (SAMLException& e) {
715 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
716 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
717 log.fatal("unable to load mandatory global extension library %s: %s", path.get(), e.what());
721 log.crit("unable to load optional global extension library %s: %s", path.get(), e.what());
723 exts=saml::XML::getNextSiblingElement(exts,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Library));
727 if (conf.isEnabled(ShibTargetConfig::SHARExtensions)) {
728 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Extensions));
730 exts=saml::XML::getFirstChildElement(exts,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Library));
732 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
734 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
735 log.debug("loaded SHAR extension library %s",path.get());
737 catch (SAMLException& e) {
738 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
739 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
740 log.fatal("unable to load mandatory SHAR extension library %s: %s", path.get(), e.what());
744 log.crit("unable to load optional SHAR extension library %s: %s", path.get(), e.what());
746 exts=saml::XML::getNextSiblingElement(exts,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Library));
751 if (conf.isEnabled(ShibTargetConfig::SHIREExtensions)) {
752 exts=saml::XML::getFirstChildElement(SHIRE,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Extensions));
754 exts=saml::XML::getFirstChildElement(exts,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Library));
756 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
758 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
759 log.debug("loaded SHIRE extension library %s",path.get());
761 catch (SAMLException& e) {
762 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
763 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
764 log.fatal("unable to load mandatory SHIRE extension library %s: %s", path.get(), e.what());
768 log.crit("unable to load optional SHIRE extension library %s: %s", path.get(), e.what());
770 exts=saml::XML::getNextSiblingElement(exts,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Library));
775 // Instantiate the Listener and SessionCache objects.
776 if (conf.isEnabled(ShibTargetConfig::Listener)) {
777 IPlugIn* plugin=NULL;
778 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(UnixListener));
780 log.info("building Listener of type %s...",shibtarget::XML::UnixListenerType);
781 plugin=shibConf.m_plugMgr.newPlugin(shibtarget::XML::UnixListenerType,exts);
784 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(TCPListener));
786 log.info("building Listener of type %s...",shibtarget::XML::TCPListenerType);
787 plugin=shibConf.m_plugMgr.newPlugin(shibtarget::XML::TCPListenerType,exts);
790 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Listener));
792 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
793 log.info("building Listener of type %s...",type.get());
794 plugin=shibConf.m_plugMgr.newPlugin(type.get(),exts);
797 log.fatal("can't build Listener object, missing conf:Listener element?");
798 throw MalformedException("can't build Listener object, missing conf:Listener element?");
803 IListener* listen=dynamic_cast<IListener*>(plugin);
805 m_outer->m_listener=listen;
808 log.fatal("plugin was not a Listener object");
809 throw UnsupportedExtensionException("plugin was not a Listener object");
814 if (conf.isEnabled(ShibTargetConfig::SessionCache)) {
815 IPlugIn* plugin=NULL;
816 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(MemorySessionCache));
818 log.info("building Session Cache of type %s...",shibtarget::XML::MemorySessionCacheType);
819 plugin=shibConf.m_plugMgr.newPlugin(shibtarget::XML::MemorySessionCacheType,exts);
822 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(MySQLSessionCache));
824 log.info("building Session Cache of type %s...",shibtarget::XML::MySQLSessionCacheType);
825 plugin=shibConf.m_plugMgr.newPlugin(shibtarget::XML::MySQLSessionCacheType,exts);
828 exts=saml::XML::getFirstChildElement(SHAR,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(SessionCache));
830 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
831 log.info("building Session Cache of type %s...",type.get());
832 plugin=shibConf.m_plugMgr.newPlugin(type.get(),exts);
835 log.fatal("can't build Session Cache object, missing conf:SessionCache element?");
836 throw MalformedException("can't build Session Cache object, missing conf:SessionCache element?");
841 ISessionCache* cache=dynamic_cast<ISessionCache*>(plugin);
843 m_outer->m_sessionCache=cache;
846 log.fatal("plugin was not a Session Cache object");
847 throw UnsupportedExtensionException("plugin was not a Session Cache object");
851 // For now, just default the replay cache.
852 // TODO: make it configurable/pluggable
853 m_outer->m_replayCache=IReplayCache::getInstance();
857 // Back to the fully dynamic stuff...next up is the Request Mapper.
858 if (conf.isEnabled(ShibTargetConfig::RequestMapper)) {
859 const DOMElement* child=saml::XML::getFirstChildElement(SHIRE,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(RequestMapProvider));
861 auto_ptr_char type(child->getAttributeNS(NULL,SHIBT_L(type)));
862 log.info("building Request Mapper of type %s...",type.get());
863 IPlugIn* plugin=shibConf.m_plugMgr.newPlugin(type.get(),child);
865 IRequestMapper* reqmap=dynamic_cast<IRequestMapper*>(plugin);
867 m_requestMapper=reqmap;
870 log.fatal("plugin was not a Request Mapper object");
871 throw UnsupportedExtensionException("plugin was not a Request Mapper object");
876 log.fatal("can't build Request Mapper object, missing conf:RequestMapProvider element?");
877 throw MalformedException("can't build Request Mapper object, missing conf:RequestMapProvider element?");
881 // Now we load any credentials providers.
883 if (conf.isEnabled(ShibTargetConfig::Credentials)) {
884 nlist=ReloadableXMLFileImpl::m_root->getElementsByTagNameNS(
885 ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(CredentialsProvider)
887 for (int i=0; nlist && i<nlist->getLength(); i++) {
888 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
889 log.info("building Credentials provider of type %s...",type.get());
890 IPlugIn* plugin=shibConf.m_plugMgr.newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
892 ICredentials* creds=dynamic_cast<ICredentials*>(plugin);
894 m_creds.push_back(creds);
897 log.fatal("plugin was not a Credentials provider");
898 throw UnsupportedExtensionException("plugin was not a Credentials provider");
904 // Load the default application. This actually has a fixed ID of "default". ;-)
905 const DOMElement* app=saml::XML::getFirstChildElement(
906 ReloadableXMLFileImpl::m_root,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Applications)
909 log.fatal("can't build default Application object, missing conf:Applications element?");
910 throw SAMLException("can't build default Application object, missing conf:Applications element?");
912 XMLApplication* defapp=new XMLApplication(m_outer, app);
913 m_appmap[defapp->getId()]=defapp;
915 // Load any overrides.
916 nlist=app->getElementsByTagNameNS(ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(Application));
917 for (int i=0; nlist && i<nlist->getLength(); i++) {
918 XMLApplication* iapp=new XMLApplication(m_outer,static_cast<DOMElement*>(nlist->item(i)),defapp);
919 if (m_appmap.find(iapp->getId())!=m_appmap.end()) {
920 log.fatal("found conf:Application element with duplicate Id attribute");
921 throw SAMLException("found conf:Application element with duplicate Id attribute");
923 m_appmap[iapp->getId()]=iapp;
926 catch (SAMLException& e) {
927 log.errorStream() << "Error while loading target configuration: " << e.what() << CategoryStream::ENDLINE;
928 this->~XMLConfigImpl();
933 log.error("Unexpected error while loading target configuration");
934 this->~XMLConfigImpl();
940 XMLConfigImpl::~XMLConfigImpl()
942 delete m_requestMapper;
943 for (map<string,IApplication*>::iterator i=m_appmap.begin(); i!=m_appmap.end(); i++)
945 for (vector<ICredentials*>::iterator j=m_creds.begin(); j!=m_creds.end(); j++)