2 * Copyright 2001-2005 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 * shib-ini.h -- config file handling, now XML-based
25 #include <shib/shib-threads.h>
26 #include <log4cpp/Category.hh>
27 #include <log4cpp/PropertyConfigurator.hh>
29 #include <sys/types.h>
34 using namespace shibboleth;
35 using namespace shibtarget;
36 using namespace log4cpp;
38 namespace shibtarget {
40 // Application configuration wrapper
41 class XMLApplication : public virtual IApplication, public XMLPropertySet, public DOMNodeFilter
44 XMLApplication(const IConfig*, const Iterator<ICredentials*>& creds, const DOMElement* e, const XMLApplication* base=NULL);
45 ~XMLApplication() { cleanup(); }
48 pair<bool,bool> getBool(const char* name, const char* ns=NULL) const;
49 pair<bool,const char*> getString(const char* name, const char* ns=NULL) const;
50 pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const;
51 pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const;
52 pair<bool,int> getInt(const char* name, const char* ns=NULL) const;
53 const IPropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const;
56 const char* getId() const {return getString("id").second;}
57 const char* getHash() const {return m_hash.c_str();}
58 Iterator<SAMLAttributeDesignator*> getAttributeDesignators() const;
59 Iterator<IAAP*> getAAPProviders() const;
60 Iterator<IMetadata*> getMetadataProviders() const;
61 Iterator<ITrust*> getTrustProviders() const;
62 Iterator<const XMLCh*> getAudiences() const;
63 const IPropertySet* getCredentialUse(const IEntityDescriptor* provider) const;
64 const SAMLBrowserProfile* getBrowserProfile() const {return m_profile;}
65 const SAMLBinding* getBinding(const XMLCh* binding) const
66 {return XMLString::compareString(SAMLBinding::SOAP,binding) ? NULL : m_binding;}
67 SAMLBrowserProfile::ArtifactMapper* getArtifactMapper() const {return new STArtifactMapper(this);}
71 const IRoleDescriptor* role=NULL,
72 const Iterator<ITrust*>& trusts=EMPTY(ITrust*)
74 const IHandler* getDefaultSessionInitiator() const;
75 const IHandler* getSessionInitiatorById(const char* id) const;
76 const IHandler* getDefaultAssertionConsumerService() const;
77 const IHandler* getAssertionConsumerServiceByIndex(unsigned short index) const;
78 Iterator<const IHandler*> getAssertionConsumerServicesByBinding(const XMLCh* binding) const;
79 Iterator<const IHandler*> getHandlers(const char* path) const;
81 // Provides filter to exclude special config elements.
82 short acceptNode(const DOMNode* node) const;
86 const IConfig* m_ini; // this is ok because its locking scope includes us
87 const XMLApplication* m_base;
89 vector<SAMLAttributeDesignator*> m_designators;
91 vector<IMetadata*> m_metadatas;
92 vector<ITrust*> m_trusts;
93 vector<const XMLCh*> m_audiences;
94 ShibBrowserProfile* m_profile;
95 SAMLBinding* m_binding;
96 ShibHTTPHook* m_bindingHook;
98 // vectors manage object life for handlers and their property sets
99 vector<IHandler*> m_handlers;
100 vector<XMLPropertySet*> m_handlerProps;
102 // maps location (path info) to applicable handlers
103 map<string,vector<const IHandler*> > m_handlerMap;
105 // maps unique indexes to consumer services
106 map<unsigned int,const IHandler*> m_acsIndexMap;
108 // pointer to default consumer service
109 const IHandler* m_acsDefault;
111 // maps binding strings to supporting consumer service(s)
113 typedef map<xstring,vector<const IHandler*> > ACSBindingMap;
115 typedef map<string,vector<const IHandler*> > ACSBindingMap;
117 ACSBindingMap m_acsBindingMap;
119 // maps unique ID strings to session initiators
120 map<string,const IHandler*> m_sessionInitMap;
122 // pointer to default session initiator
123 const IHandler* m_sessionInitDefault;
125 XMLPropertySet* m_credDefault;
127 map<xstring,XMLPropertySet*> m_credMap;
129 map<const XMLCh*,XMLPropertySet*> m_credMap;
133 // Top-level configuration implementation
135 class XMLConfigImpl : public ReloadableXMLFileImpl, public XMLPropertySet, public DOMNodeFilter
138 XMLConfigImpl(const char* pathname, bool first, const XMLConfig* outer)
139 : ReloadableXMLFileImpl(pathname), m_outer(outer), m_requestMapper(NULL) { init(first); }
140 XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer)
141 : ReloadableXMLFileImpl(e), m_outer(outer), m_requestMapper(NULL) { init(first); }
144 IRequestMapper* m_requestMapper;
145 map<string,IApplication*> m_appmap;
146 vector<ICredentials*> m_creds;
147 vector<IAttributeFactory*> m_attrFactories;
149 // Provides filter to exclude special config elements.
150 short acceptNode(const DOMNode* node) const;
153 void init(bool first);
154 const XMLConfig* m_outer;
157 class XMLConfig : public IConfig, public ReloadableXMLFile
160 XMLConfig(const DOMElement* e) : ReloadableXMLFile(e), m_listener(NULL), m_sessionCache(NULL), m_replayCache(NULL) {}
164 delete m_sessionCache;
166 delete m_replayCache;
172 void init() { getImplementation(); }
175 pair<bool,bool> getBool(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getBool(name,ns);}
176 pair<bool,const char*> getString(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getString(name,ns);}
177 pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getXMLString(name,ns);}
178 pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getUnsignedInt(name,ns);}
179 pair<bool,int> getInt(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getInt(name,ns);}
180 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);}
181 const DOMElement* getElement() const {return static_cast<XMLConfigImpl*>(m_impl)->getElement();}
184 IListener* getListener() const {return m_listener;}
185 ISessionCache* getSessionCache() const {return m_sessionCache;}
186 IReplayCache* getReplayCache() const {return m_replayCache;}
187 IRequestMapper* getRequestMapper() const {return static_cast<XMLConfigImpl*>(m_impl)->m_requestMapper;}
188 const IApplication* getApplication(const char* applicationId) const {
189 map<string,IApplication*>::const_iterator i=static_cast<XMLConfigImpl*>(m_impl)->m_appmap.find(applicationId);
190 return (i!=static_cast<XMLConfigImpl*>(m_impl)->m_appmap.end()) ? i->second : NULL;
192 Iterator<ICredentials*> getCredentialsProviders() const {return static_cast<XMLConfigImpl*>(m_impl)->m_creds;}
195 virtual ReloadableXMLFileImpl* newImplementation(const char* pathname, bool first=true) const;
196 virtual ReloadableXMLFileImpl* newImplementation(const DOMElement* e, bool first=true) const;
199 friend class XMLConfigImpl;
200 mutable IListener* m_listener;
201 mutable ISessionCache* m_sessionCache;
202 mutable IReplayCache* m_replayCache;
206 IConfig* STConfig::ShibTargetConfigFactory(const DOMElement* e)
208 return new XMLConfig(e);
211 XMLPropertySet::~XMLPropertySet()
213 for (map<string,pair<char*,const XMLCh*> >::iterator i=m_map.begin(); i!=m_map.end(); i++)
214 XMLString::release(&(i->second.first));
215 for_each(m_nested.begin(),m_nested.end(),shibtarget::cleanup_pair<string,IPropertySet>());
218 void XMLPropertySet::load(
221 DOMNodeFilter* filter,
222 const std::map<std::string,std::string>* remapper
226 saml::NDC ndc("load");
230 // Process each attribute as a property.
231 DOMNamedNodeMap* attrs=m_root->getAttributes();
232 for (XMLSize_t i=0; i<attrs->getLength(); i++) {
233 DOMNode* a=attrs->item(i);
234 if (!XMLString::compareString(a->getNamespaceURI(),saml::XML::XMLNS_NS))
236 char* val=XMLString::transcode(a->getNodeValue());
238 auto_ptr_char ns(a->getNamespaceURI());
239 auto_ptr_char name(a->getLocalName());
240 const char* realname=name.get();
242 map<string,string>::const_iterator remap=remapper->find(realname);
243 if (remap!=remapper->end()) {
244 log.warn("remapping property (%s) to (%s)",realname,remap->second.c_str());
245 realname=remap->second.c_str();
249 m_map[string("{") + ns.get() + '}' + realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
250 log.debug("added property {%s}%s (%s)",ns.get(),realname,val);
253 m_map[realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
254 log.debug("added property %s (%s)",realname,val);
259 // Process non-excluded elements as nested sets.
260 DOMTreeWalker* walker=
261 static_cast<DOMDocumentTraversal*>(
262 m_root->getOwnerDocument())->createTreeWalker(const_cast<DOMElement*>(m_root),DOMNodeFilter::SHOW_ELEMENT,filter,false
264 e=static_cast<DOMElement*>(walker->firstChild());
266 auto_ptr_char ns(e->getNamespaceURI());
267 auto_ptr_char name(e->getLocalName());
268 const char* realname=name.get();
270 map<string,string>::const_iterator remap=remapper->find(realname);
271 if (remap!=remapper->end()) {
272 log.warn("remapping property set (%s) to (%s)",realname,remap->second.c_str());
273 realname=remap->second.c_str();
278 key=string("{") + ns.get() + '}' + realname;
281 if (m_nested.find(key)!=m_nested.end())
282 log.warn("load() skipping duplicate property set: %s",key.c_str());
284 XMLPropertySet* set=new XMLPropertySet();
285 set->load(e,log,filter,remapper);
287 log.debug("added nested property set: %s",key.c_str());
289 e=static_cast<DOMElement*>(walker->nextSibling());
294 pair<bool,bool> XMLPropertySet::getBool(const char* name, const char* ns) const
296 pair<bool,bool> ret(false,false);
297 map<string,pair<char*,const XMLCh*> >::const_iterator i;
300 i=m_map.find(string("{") + ns + '}' + name);
304 if (i!=m_map.end()) {
306 ret.second=(!strcmp(i->second.first,"true") || !strcmp(i->second.first,"1"));
311 pair<bool,const char*> XMLPropertySet::getString(const char* name, const char* ns) const
313 pair<bool,const char*> ret(false,NULL);
314 map<string,pair<char*,const XMLCh*> >::const_iterator i;
317 i=m_map.find(string("{") + ns + '}' + name);
321 if (i!=m_map.end()) {
323 ret.second=i->second.first;
328 pair<bool,const XMLCh*> XMLPropertySet::getXMLString(const char* name, const char* ns) const
330 pair<bool,const XMLCh*> ret(false,NULL);
331 map<string,pair<char*,const XMLCh*> >::const_iterator i;
334 i=m_map.find(string("{") + ns + '}' + name);
338 if (i!=m_map.end()) {
340 ret.second=i->second.second;
345 pair<bool,unsigned int> XMLPropertySet::getUnsignedInt(const char* name, const char* ns) const
347 pair<bool,unsigned int> ret(false,0);
348 map<string,pair<char*,const XMLCh*> >::const_iterator i;
351 i=m_map.find(string("{") + ns + '}' + name);
355 if (i!=m_map.end()) {
357 ret.second=strtol(i->second.first,NULL,10);
362 pair<bool,int> XMLPropertySet::getInt(const char* name, const char* ns) const
364 pair<bool,int> ret(false,0);
365 map<string,pair<char*,const XMLCh*> >::const_iterator i;
368 i=m_map.find(string("{") + ns + '}' + name);
372 if (i!=m_map.end()) {
374 ret.second=atoi(i->second.first);
379 const IPropertySet* XMLPropertySet::getPropertySet(const char* name, const char* ns) const
381 map<string,IPropertySet*>::const_iterator i;
384 i=m_nested.find(string("{") + ns + '}' + name);
386 i=m_nested.find(name);
388 return (i!=m_nested.end()) ? i->second : NULL;
391 XMLApplication::XMLApplication(
393 const Iterator<ICredentials*>& creds,
395 const XMLApplication* base
396 ) : m_ini(ini), m_base(base), m_profile(NULL), m_binding(NULL), m_bindingHook(NULL),
397 m_credDefault(NULL), m_sessionInitDefault(NULL), m_acsDefault(NULL)
400 saml::NDC ndc("XMLApplication");
402 Category& log=Category::getInstance("shibtarget.XMLApplication");
405 // First load any property sets.
406 map<string,string> root_remap;
407 root_remap["shire"]="session";
408 root_remap["shireURL"]="handlerURL";
409 root_remap["shireSSL"]="handlerSSL";
410 load(e,log,this,&root_remap);
411 const IPropertySet* propcheck=getPropertySet("Errors");
412 if (propcheck && !propcheck->getString("session").first)
413 throw ConfigurationException("<Errors> element requires 'session' (or deprecated 'shire') attribute");
414 propcheck=getPropertySet("Sessions");
415 if (propcheck && !propcheck->getString("handlerURL").first)
416 throw ConfigurationException("<Sessions> element requires 'handlerURL' (or deprecated 'shireURL') attribute");
419 m_hash+=getString("providerId").second;
420 m_hash=SAMLArtifact::toHex(SAMLArtifactType0001::generateSourceId(m_hash.c_str()));
422 ShibTargetConfig& conf=ShibTargetConfig::getConfig();
423 SAMLConfig& shibConf=SAMLConfig::getConfig();
426 bool hardACS=false, hardSessionInit=false;
427 DOMElement* handler=saml::XML::getFirstChildElement(propcheck->getElement());
429 // A handler is split across a property set and the plugin itself, which is based on the Binding property.
430 // We build both objects first and then insert them into various structures for lookup.
432 XMLPropertySet* hprops=new XMLPropertySet();
434 hprops->load(handler,log,this); // filter irrelevant for now, no embedded elements expected
435 const char* bindprop=hprops->getString("Binding").second;
437 throw ConfigurationException("Handler element has no Binding attribute, skipping it...");
438 IPlugIn* hplug=shibConf.getPlugMgr().newPlugin(bindprop,handler);
439 hobj=dynamic_cast<IHandler*>(hplug);
442 throw UnsupportedProfileException(
443 "Plugin for binding ($1) does not implement IHandler interface.",params(1,bindprop)
447 catch (SAMLException& ex) {
448 // If we get here, the handler's not built, so dispose of the property set.
449 log.error("caught exception processing a handler element: %s",ex.what());
456 // Save off the objects after giving the property set to the handler for its use.
457 hobj->setProperties(hprops);
458 m_handlers.push_back(hobj);
459 m_handlerProps.push_back(hprops);
461 // Check for it in the location map.
462 const char* location=hprops->getString("Location").second;
463 if (m_handlerMap.count(location)==0)
464 m_handlerMap[location]=vector<const IHandler*>(1,hobj);
466 m_handlerMap[location].push_back(hobj);
468 // If it's an ACS or SI, handle index/id mappings and defaulting.
469 if (saml::XML::isElementNamed(handler,shibtarget::XML::SAML2META_NS,SHIBT_L(AssertionConsumerService))) {
472 const XMLCh* binding=hprops->getXMLString("Binding").second;
474 const char* binding=hprops->getString("Binding").second;
476 if (m_acsBindingMap.count(binding)==0)
477 m_acsBindingMap[binding]=vector<const IHandler*>(1,hobj);
479 m_acsBindingMap[binding].push_back(hobj);
480 m_acsIndexMap[hprops->getUnsignedInt("index").second]=hobj;
483 pair<bool,bool> defprop=hprops->getBool("isDefault");
485 if (defprop.second) {
490 else if (!m_acsDefault)
494 else if (saml::XML::isElementNamed(handler,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SessionInitiator))) {
495 pair<bool,const char*> si_id=hprops->getString("id");
496 if (si_id.first && si_id.second)
497 m_sessionInitMap[si_id.second]=hobj;
498 if (!hardSessionInit) {
499 pair<bool,bool> defprop=hprops->getBool("isDefault");
501 if (defprop.second) {
502 hardSessionInit=true;
503 m_sessionInitDefault=hobj;
506 else if (!m_sessionInitDefault)
507 m_sessionInitDefault=hobj;
510 handler=saml::XML::getNextSiblingElement(handler);
513 // If no handlers defined at the root, assume a legacy configuration.
514 if (!m_base && m_handlers.empty()) {
515 // A legacy config installs a SAML POST handler and a Shib session-initiator
516 // at the root handler location. We use the Sessions element itself as the
518 auto_ptr_char b1(Constants::SHIB_SESSIONINIT_PROFILE_URI);
519 IPlugIn* hplug=shibConf.getPlugMgr().newPlugin(b1.get(),propcheck->getElement());
520 IHandler* h1=dynamic_cast<IHandler*>(hplug);
523 throw UnsupportedProfileException(
524 "Plugin for binding ($1) does not implement IHandler interface.",params(1,b1.get())
527 h1->setProperties(propcheck);
528 m_handlers.push_back(h1);
529 m_handlerMap[""]=vector<const IHandler*>(1,h1);
530 m_sessionInitDefault=h1;
532 auto_ptr_char b2(SAMLBrowserProfile::BROWSER_POST);
533 hplug=shibConf.getPlugMgr().newPlugin(b1.get(),propcheck->getElement());
534 IHandler* h2=dynamic_cast<IHandler*>(hplug);
537 throw UnsupportedProfileException(
538 "Plugin for binding ($1) does not implement IHandler interface.",params(1,b2.get())
541 h2->setProperties(propcheck);
542 m_handlers.push_back(h2);
543 m_handlerMap[""].push_back(h2);
547 // Process general configuration elements.
549 DOMNodeList* nlist=e->getElementsByTagNameNS(saml::XML::SAML_NS,L(AttributeDesignator));
550 for (i=0; nlist && i<nlist->getLength(); i++)
551 if (nlist->item(i)->getParentNode()->isSameNode(e))
552 m_designators.push_back(new SAMLAttributeDesignator(static_cast<DOMElement*>(nlist->item(i))));
554 nlist=e->getElementsByTagNameNS(saml::XML::SAML_NS,L(Audience));
555 for (i=0; nlist && i<nlist->getLength(); i++)
556 if (nlist->item(i)->getParentNode()->isSameNode(e))
557 m_audiences.push_back(nlist->item(i)->getFirstChild()->getNodeValue());
559 // Always include our own providerId as an audience.
560 m_audiences.push_back(getXMLString("providerId").second);
562 if (conf.isEnabled(ShibTargetConfig::AAP)) {
563 nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(AAPProvider));
564 for (i=0; nlist && i<nlist->getLength(); i++) {
565 if (nlist->item(i)->getParentNode()->isSameNode(e)) {
566 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
567 log.info("building AAP provider of type %s...",type.get());
569 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
570 IAAP* aap=dynamic_cast<IAAP*>(plugin);
572 m_aaps.push_back(aap);
575 log.crit("plugin was not an AAP provider");
578 catch (SAMLException& ex) {
579 log.crit("error building AAP provider: %s",ex.what());
585 if (conf.isEnabled(ShibTargetConfig::Metadata)) {
586 nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MetadataProvider));
587 for (i=0; nlist && i<nlist->getLength(); i++) {
588 if (nlist->item(i)->getParentNode()->isSameNode(e)) {
589 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
590 log.info("building metadata provider of type %s...",type.get());
592 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
593 IMetadata* md=dynamic_cast<IMetadata*>(plugin);
595 m_metadatas.push_back(md);
598 log.crit("plugin was not a metadata provider");
601 catch (SAMLException& ex) {
602 log.crit("error building metadata provider: %s",ex.what());
606 nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(FederationProvider));
607 for (i=0; nlist && i<nlist->getLength(); i++) {
608 if (nlist->item(i)->getParentNode()->isSameNode(e)) {
609 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
610 log.info("building metadata provider of type %s...",type.get());
612 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
613 IMetadata* md=dynamic_cast<IMetadata*>(plugin);
615 m_metadatas.push_back(md);
618 log.crit("plugin was not a metadata provider");
621 catch (SAMLException& ex) {
622 log.crit("error building metadata provider: %s",ex.what());
628 if (conf.isEnabled(ShibTargetConfig::Trust)) {
629 nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(TrustProvider));
630 for (i=0; nlist && i<nlist->getLength(); i++) {
631 if (nlist->item(i)->getParentNode()->isSameNode(e)) {
632 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
633 log.info("building trust provider of type %s...",type.get());
635 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
636 ITrust* trust=dynamic_cast<ITrust*>(plugin);
638 m_trusts.push_back(trust);
641 log.crit("plugin was not a trust provider");
644 catch (SAMLException& ex) {
645 log.crit("error building trust provider: %s",ex.what());
651 // Finally, load credential mappings.
652 const DOMElement* cu=saml::XML::getFirstChildElement(e,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(CredentialUse));
654 m_credDefault=new XMLPropertySet();
655 m_credDefault->load(cu,log,this);
656 cu=saml::XML::getFirstChildElement(cu,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(RelyingParty));
658 XMLPropertySet* rp=new XMLPropertySet();
659 rp->load(cu,log,this);
660 m_credMap[cu->getAttributeNS(NULL,SHIBT_L(Name))]=rp;
661 cu=saml::XML::getNextSiblingElement(cu,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(RelyingParty));
665 if (conf.isEnabled(ShibTargetConfig::OutOfProcess)) {
666 // Really finally, build local browser profile and binding objects.
667 m_profile=new ShibBrowserProfile(
669 getMetadataProviders(),
672 m_bindingHook=new ShibHTTPHook(
676 m_binding=SAMLBinding::getInstance(SAMLBinding::SOAP);
677 SAMLSOAPHTTPBinding* bptr=dynamic_cast<SAMLSOAPHTTPBinding*>(m_binding);
679 log.fatal("binding implementation was not SOAP over HTTP");
680 throw UnsupportedExtensionException("binding implementation was not SOAP over HTTP");
682 bptr->addHook(m_bindingHook,m_bindingHook); // the hook is its own global context
685 catch (SAMLException& e) {
686 log.errorStream() << "Error while processing applicaton element: " << e.what() << CategoryStream::ENDLINE;
692 log.error("Unexpected error while processing application element");
699 void XMLApplication::cleanup()
701 delete m_bindingHook;
704 for_each(m_handlers.begin(),m_handlers.end(),shibtarget::cleanup<IHandler>());
706 delete m_credDefault;
708 for_each(m_credMap.begin(),m_credMap.end(),shibtarget::cleanup_pair<xstring,XMLPropertySet>());
710 for_each(m_credMap.begin(),m_credMap.end(),shibtarget::cleanup_pair<const XMLCh*,XMLPropertySet>());
712 for_each(m_designators.begin(),m_designators.end(),shibtarget::cleanup<SAMLAttributeDesignator>());
713 for_each(m_aaps.begin(),m_aaps.end(),shibtarget::cleanup<IAAP>());
714 for_each(m_metadatas.begin(),m_metadatas.end(),shibtarget::cleanup<IMetadata>());
715 for_each(m_trusts.begin(),m_trusts.end(),shibtarget::cleanup<ITrust>());
718 short XMLApplication::acceptNode(const DOMNode* node) const
720 if (saml::XML::isElementNamed(static_cast<const DOMElement*>(node),saml::XML::SAML_NS,L(AttributeDesignator)))
721 return FILTER_REJECT;
722 else if (saml::XML::isElementNamed(static_cast<const DOMElement*>(node),saml::XML::SAML_NS,L(Audience)))
723 return FILTER_REJECT;
724 const XMLCh* name=node->getLocalName();
725 if (!XMLString::compareString(name,SHIBT_L(Application)) ||
726 !XMLString::compareString(name,SHIBT_L(AssertionConsumerService)) ||
727 !XMLString::compareString(name,SHIBT_L(SingleLogoutService)) ||
728 !XMLString::compareString(name,SHIBT_L(DiagnosticService)) ||
729 !XMLString::compareString(name,SHIBT_L(SessionInitiator)) ||
730 !XMLString::compareString(name,SHIBT_L(AAPProvider)) ||
731 !XMLString::compareString(name,SHIBT_L(CredentialUse)) ||
732 !XMLString::compareString(name,SHIBT_L(RelyingParty)) ||
733 !XMLString::compareString(name,SHIBT_L(FederationProvider)) ||
734 !XMLString::compareString(name,SHIBT_L(MetadataProvider)) ||
735 !XMLString::compareString(name,SHIBT_L(TrustProvider)))
736 return FILTER_REJECT;
738 return FILTER_ACCEPT;
741 pair<bool,bool> XMLApplication::getBool(const char* name, const char* ns) const
743 pair<bool,bool> ret=XMLPropertySet::getBool(name,ns);
746 return m_base ? m_base->getBool(name,ns) : ret;
749 pair<bool,const char*> XMLApplication::getString(const char* name, const char* ns) const
751 pair<bool,const char*> ret=XMLPropertySet::getString(name,ns);
754 return m_base ? m_base->getString(name,ns) : ret;
757 pair<bool,const XMLCh*> XMLApplication::getXMLString(const char* name, const char* ns) const
759 pair<bool,const XMLCh*> ret=XMLPropertySet::getXMLString(name,ns);
762 return m_base ? m_base->getXMLString(name,ns) : ret;
765 pair<bool,unsigned int> XMLApplication::getUnsignedInt(const char* name, const char* ns) const
767 pair<bool,unsigned int> ret=XMLPropertySet::getUnsignedInt(name,ns);
770 return m_base ? m_base->getUnsignedInt(name,ns) : ret;
773 pair<bool,int> XMLApplication::getInt(const char* name, const char* ns) const
775 pair<bool,int> ret=XMLPropertySet::getInt(name,ns);
778 return m_base ? m_base->getInt(name,ns) : ret;
781 const IPropertySet* XMLApplication::getPropertySet(const char* name, const char* ns) const
783 const IPropertySet* ret=XMLPropertySet::getPropertySet(name,ns);
786 return m_base->getPropertySet(name,ns);
789 Iterator<SAMLAttributeDesignator*> XMLApplication::getAttributeDesignators() const
791 if (!m_designators.empty() || !m_base)
792 return m_designators;
793 return m_base->getAttributeDesignators();
796 Iterator<IAAP*> XMLApplication::getAAPProviders() const
798 return (m_aaps.empty() && m_base) ? m_base->getAAPProviders() : m_aaps;
801 Iterator<IMetadata*> XMLApplication::getMetadataProviders() const
803 return (m_metadatas.empty() && m_base) ? m_base->getMetadataProviders() : m_metadatas;
806 Iterator<ITrust*> XMLApplication::getTrustProviders() const
808 return (m_trusts.empty() && m_base) ? m_base->getTrustProviders() : m_trusts;
811 Iterator<const XMLCh*> XMLApplication::getAudiences() const
813 return (m_audiences.empty() && m_base) ? m_base->getAudiences() : m_audiences;
816 const IPropertySet* XMLApplication::getCredentialUse(const IEntityDescriptor* provider) const
818 if (!m_credDefault && m_base)
819 return m_base->getCredentialUse(provider);
822 map<xstring,XMLPropertySet*>::const_iterator i=m_credMap.find(provider->getId());
823 if (i!=m_credMap.end())
825 const IEntitiesDescriptor* group=provider->getEntitiesDescriptor();
827 if (group->getName()) {
828 i=m_credMap.find(group->getName());
829 if (i!=m_credMap.end())
832 group=group->getEntitiesDescriptor();
835 map<const XMLCh*,XMLPropertySet*>::const_iterator i=m_credMap.begin();
836 for (; i!=m_credMap.end(); i++) {
837 if (!XMLString::compareString(i->first,provider->getId()))
839 const IEntitiesDescriptor* group=provider->getEntitiesDescriptor();
841 if (!XMLString::compareString(i->first,group->getName()))
843 group=group->getEntitiesDescriptor();
847 return m_credDefault;
850 void XMLApplication::validateToken(SAMLAssertion* token, time_t ts, const IRoleDescriptor* role, const Iterator<ITrust*>& trusts) const
853 saml::NDC ndc("validateToken");
855 Category& log=Category::getInstance("shibtarget.XMLApplication");
857 // First we verify the time conditions, using the specified timestamp, if non-zero.
858 SAMLConfig& config=SAMLConfig::getConfig();
860 const SAMLDateTime* notBefore=token->getNotBefore();
861 if (notBefore && ts+config.clock_skew_secs < notBefore->getEpoch())
862 throw ExpiredAssertionException("Assertion is not yet valid.");
863 const SAMLDateTime* notOnOrAfter=token->getNotOnOrAfter();
864 if (notOnOrAfter && notOnOrAfter->getEpoch() <= ts-config.clock_skew_secs)
865 throw ExpiredAssertionException("Assertion is no longer valid.");
868 // Now we process conditions. Only audience restrictions at the moment.
869 Iterator<SAMLCondition*> conditions=token->getConditions();
870 while (conditions.hasNext()) {
871 SAMLCondition* cond=conditions.next();
872 const SAMLAudienceRestrictionCondition* ac=dynamic_cast<const SAMLAudienceRestrictionCondition*>(cond);
876 log.error("unrecognized Condition in assertion (%s)",os.str().c_str());
877 throw UnsupportedExtensionException("Assertion contains an unrecognized condition.");
879 else if (!ac->eval(getAudiences())) {
882 log.error("unacceptable AudienceRestrictionCondition in assertion (%s)",os.str().c_str());
883 throw UnsupportedProfileException("Assertion contains an unacceptable AudienceRestrictionCondition.");
888 log.warn("no metadata provided, so no signature validation was performed");
892 const IPropertySet* credUse=getCredentialUse(role->getEntityDescriptor());
893 pair<bool,bool> signedAssertions=credUse ? credUse->getBool("signedAssertions") : make_pair(false,false);
896 if (token->isSigned() && !t.validate(*token,role))
897 throw TrustException("Assertion signature did not validate.");
898 else if (signedAssertions.first && signedAssertions.second)
899 throw TrustException("Assertion was unsigned, violating policy based on the issuer.");
902 const IHandler* XMLApplication::getDefaultSessionInitiator() const
904 if (m_sessionInitDefault) return m_sessionInitDefault;
905 return m_base ? m_base->getDefaultSessionInitiator() : NULL;
908 const IHandler* XMLApplication::getSessionInitiatorById(const char* id) const
910 map<string,const IHandler*>::const_iterator i=m_sessionInitMap.find(id);
911 if (i!=m_sessionInitMap.end()) return i->second;
912 return m_base ? m_base->getSessionInitiatorById(id) : NULL;
915 const IHandler* XMLApplication::getDefaultAssertionConsumerService() const
917 if (m_acsDefault) return m_acsDefault;
918 return m_base ? m_base->getDefaultAssertionConsumerService() : NULL;
921 const IHandler* XMLApplication::getAssertionConsumerServiceByIndex(unsigned short index) const
923 map<unsigned int,const IHandler*>::const_iterator i=m_acsIndexMap.find(index);
924 if (i!=m_acsIndexMap.end()) return i->second;
925 return m_base ? m_base->getAssertionConsumerServiceByIndex(index) : NULL;
928 Iterator<const IHandler*> XMLApplication::getAssertionConsumerServicesByBinding(const XMLCh* binding) const
931 ACSBindingMap::const_iterator i=m_acsBindingMap.find(binding);
933 auto_ptr_char temp(binding);
934 ACSBindingMap::const_iterator i=m_acsBindingMap.find(temp.get());
936 if (i!=m_acsBindingMap.end())
938 return m_base ? m_base->getAssertionConsumerServicesByBinding(binding) : EMPTY(const IHandler*);
941 Iterator<const IHandler*> XMLApplication::getHandlers(const char* path) const
944 map<string,vector<const IHandler*> >::const_iterator i=m_handlerMap.find(wrap.substr(0,wrap.find('?')));
945 if (i!=m_handlerMap.end())
947 return m_base ? m_base->getHandlers(path) : EMPTY(const IHandler*);
950 ReloadableXMLFileImpl* XMLConfig::newImplementation(const char* pathname, bool first) const
952 return new XMLConfigImpl(pathname,first,this);
955 ReloadableXMLFileImpl* XMLConfig::newImplementation(const DOMElement* e, bool first) const
957 return new XMLConfigImpl(e,first,this);
960 short XMLConfigImpl::acceptNode(const DOMNode* node) const
962 if (XMLString::compareString(node->getNamespaceURI(),shibtarget::XML::SHIBTARGET_NS))
963 return FILTER_ACCEPT;
964 const XMLCh* name=node->getLocalName();
965 if (!XMLString::compareString(name,SHIBT_L(Applications)) ||
966 !XMLString::compareString(name,SHIBT_L(AttributeFactory)) ||
967 !XMLString::compareString(name,SHIBT_L(CredentialsProvider)) ||
968 !XMLString::compareString(name,SHIBT_L(Extensions)) ||
969 !XMLString::compareString(name,SHIBT_L(Implementation)) ||
970 !XMLString::compareString(name,SHIBT_L(Listener)) ||
971 !XMLString::compareString(name,SHIBT_L(MemorySessionCache)) ||
972 !XMLString::compareString(name,SHIBT_L(MySQLReplayCache)) ||
973 !XMLString::compareString(name,SHIBT_L(MySQLSessionCache)) ||
974 !XMLString::compareString(name,SHIBT_L(RequestMap)) ||
975 !XMLString::compareString(name,SHIBT_L(RequestMapProvider)) ||
976 !XMLString::compareString(name,SHIBT_L(ReplayCache)) ||
977 !XMLString::compareString(name,SHIBT_L(SessionCache)) ||
978 !XMLString::compareString(name,SHIBT_L(TCPListener)) ||
979 !XMLString::compareString(name,SHIBT_L(UnixListener)))
980 return FILTER_REJECT;
982 return FILTER_ACCEPT;
985 void XMLConfigImpl::init(bool first)
988 saml::NDC ndc("init");
990 Category& log=Category::getInstance("shibtarget.Config");
993 if (!saml::XML::isElementNamed(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(ShibbolethTargetConfig)) &&
994 !saml::XML::isElementNamed(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SPConfig))) {
995 log.error("Construction requires a valid configuration file: (conf:SPConfig as root element)");
996 throw ConfigurationException("Construction requires a valid configuration file: (conf:SPConfig as root element)");
999 SAMLConfig& shibConf=SAMLConfig::getConfig();
1000 ShibTargetConfig& conf=ShibTargetConfig::getConfig();
1001 const DOMElement* SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SHAR));
1003 SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Global));
1005 SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(OutOfProcess));
1006 const DOMElement* SHIRE=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SHIRE));
1008 SHIRE=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Local));
1010 SHIRE=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(InProcess));
1012 // Initialize log4cpp manually in order to redirect log messages as soon as possible.
1013 if (conf.isEnabled(ShibTargetConfig::Logging)) {
1014 const XMLCh* logger=NULL;
1015 if (conf.isEnabled(ShibTargetConfig::OutOfProcess))
1016 logger=SHAR->getAttributeNS(NULL,SHIBT_L(logger));
1017 else if (conf.isEnabled(ShibTargetConfig::InProcess))
1018 logger=SHIRE->getAttributeNS(NULL,SHIBT_L(logger));
1019 if (!logger || !*logger)
1020 logger=ReloadableXMLFileImpl::m_root->getAttributeNS(NULL,SHIBT_L(logger));
1021 if (logger && *logger) {
1022 auto_ptr_char logpath(logger);
1023 log.debug("loading new logging configuration from (%s), check log destination for status of configuration",logpath.get());
1025 PropertyConfigurator::configure(logpath.get());
1027 catch (ConfigureFailure& e) {
1028 log.error("Error reading logging configuration: %s",e.what());
1033 // First load any property sets.
1034 map<string,string> root_remap;
1035 root_remap["SHAR"]="OutOfProcess";
1036 root_remap["SHIRE"]="InProcess";
1037 root_remap["Global"]="OutOfProcess";
1038 root_remap["Local"]="InProcess";
1039 load(ReloadableXMLFileImpl::m_root,log,this,&root_remap);
1041 // Much of the processing can only occur on the first instantiation.
1043 // Now load any extensions to insure any needed plugins are registered.
1045 saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Extensions));
1047 exts=saml::XML::getFirstChildElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1049 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
1051 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
1052 log.debug("loaded global extension library %s",path.get());
1054 catch (SAMLException& e) {
1055 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
1056 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
1057 log.fatal("unable to load mandatory global extension library %s: %s", path.get(), e.what());
1061 log.crit("unable to load optional global extension library %s: %s", path.get(), e.what());
1063 exts=saml::XML::getNextSiblingElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1067 if (conf.isEnabled(ShibTargetConfig::OutOfProcess)) {
1068 exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Extensions));
1070 exts=saml::XML::getFirstChildElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1072 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
1074 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
1075 log.debug("loaded Global extension library %s",path.get());
1077 catch (SAMLException& e) {
1078 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
1079 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
1080 log.fatal("unable to load mandatory Global extension library %s: %s", path.get(), e.what());
1084 log.crit("unable to load optional Global extension library %s: %s", path.get(), e.what());
1086 exts=saml::XML::getNextSiblingElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1091 if (conf.isEnabled(ShibTargetConfig::InProcess)) {
1092 exts=saml::XML::getFirstChildElement(SHIRE,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Extensions));
1094 exts=saml::XML::getFirstChildElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1096 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
1098 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
1099 log.debug("loaded Local extension library %s",path.get());
1101 catch (SAMLException& e) {
1102 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
1103 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
1104 log.fatal("unable to load mandatory Local extension library %s: %s", path.get(), e.what());
1108 log.crit("unable to load optional Local extension library %s: %s", path.get(), e.what());
1110 exts=saml::XML::getNextSiblingElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1115 // Instantiate the Listener and SessionCache objects.
1116 if (conf.isEnabled(ShibTargetConfig::Listener)) {
1117 IPlugIn* plugin=NULL;
1118 exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(UnixListener));
1120 log.info("building Listener of type %s...",shibtarget::XML::UnixListenerType);
1121 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::UnixListenerType,exts);
1124 exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(TCPListener));
1126 log.info("building Listener of type %s...",shibtarget::XML::TCPListenerType);
1127 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::TCPListenerType,exts);
1130 exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Listener));
1132 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
1133 log.info("building Listener of type %s...",type.get());
1134 plugin=shibConf.getPlugMgr().newPlugin(type.get(),exts);
1137 log.fatal("can't build Listener object, missing conf:Listener element?");
1138 throw ConfigurationException("can't build Listener object, missing conf:Listener element?");
1143 IListener* listen=dynamic_cast<IListener*>(plugin);
1145 m_outer->m_listener=listen;
1148 log.fatal("plugin was not a Listener object");
1149 throw UnsupportedExtensionException("plugin was not a Listener object");
1154 if (conf.isEnabled(ShibTargetConfig::Caching)) {
1155 IPlugIn* plugin=NULL;
1156 const DOMElement* container=conf.isEnabled(ShibTargetConfig::OutOfProcess) ? SHAR : SHIRE;
1157 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MemorySessionCache));
1159 log.info("building Session Cache of type %s...",shibtarget::XML::MemorySessionCacheType);
1160 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::MemorySessionCacheType,exts);
1163 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(ODBCSessionCache));
1165 log.info("building Session Cache of type %s...",shibtarget::XML::ODBCSessionCacheType);
1166 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::ODBCSessionCacheType,exts);
1169 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MySQLSessionCache));
1171 log.info("building Session Cache of type %s...",shibtarget::XML::MySQLSessionCacheType);
1172 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::MySQLSessionCacheType,exts);
1175 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SessionCache));
1177 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
1178 log.info("building Session Cache of type %s...",type.get());
1179 plugin=shibConf.getPlugMgr().newPlugin(type.get(),exts);
1182 log.info("session cache not specified, building Session Cache of type %s...",shibtarget::XML::MemorySessionCacheType);
1183 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::MemorySessionCacheType,exts);
1189 ISessionCache* cache=dynamic_cast<ISessionCache*>(plugin);
1191 m_outer->m_sessionCache=cache;
1194 log.fatal("plugin was not a Session Cache object");
1195 throw UnsupportedExtensionException("plugin was not a Session Cache object");
1200 container=conf.isEnabled(ShibTargetConfig::OutOfProcess) ? SHAR : SHIRE;
1201 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(ODBCReplayCache));
1203 log.info("building Replay Cache of type %s...",shibtarget::XML::ODBCReplayCacheType);
1204 m_outer->m_replayCache=IReplayCache::getInstance(shibtarget::XML::ODBCReplayCacheType,exts);
1207 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MySQLReplayCache));
1209 log.info("building Replay Cache of type %s...",shibtarget::XML::MySQLReplayCacheType);
1210 m_outer->m_replayCache=IReplayCache::getInstance(shibtarget::XML::MySQLReplayCacheType,exts);
1213 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(ReplayCache));
1215 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
1216 log.info("building Replay Cache of type %s...",type.get());
1217 m_outer->m_replayCache=IReplayCache::getInstance(type.get(),exts);
1220 // OpenSAML default provider.
1221 log.info("building default Replay Cache...");
1222 m_outer->m_replayCache=IReplayCache::getInstance();
1229 // Back to the fully dynamic stuff...next up is the Request Mapper.
1230 if (conf.isEnabled(ShibTargetConfig::RequestMapper)) {
1231 const DOMElement* child=saml::XML::getFirstChildElement(SHIRE,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(RequestMapProvider));
1233 auto_ptr_char type(child->getAttributeNS(NULL,SHIBT_L(type)));
1234 log.info("building Request Mapper of type %s...",type.get());
1235 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),child);
1237 IRequestMapper* reqmap=dynamic_cast<IRequestMapper*>(plugin);
1239 m_requestMapper=reqmap;
1242 log.fatal("plugin was not a Request Mapper object");
1243 throw UnsupportedExtensionException("plugin was not a Request Mapper object");
1248 log.fatal("can't build Request Mapper object, missing conf:RequestMapProvider element?");
1249 throw ConfigurationException("can't build Request Mapper object, missing conf:RequestMapProvider element?");
1253 // Now we load any credentials providers.
1255 if (conf.isEnabled(ShibTargetConfig::Credentials)) {
1256 nlist=ReloadableXMLFileImpl::m_root->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(CredentialsProvider));
1257 for (unsigned int i=0; nlist && i<nlist->getLength(); i++) {
1258 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
1259 log.info("building credentials provider of type %s...",type.get());
1261 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
1263 ICredentials* creds=dynamic_cast<ICredentials*>(plugin);
1265 m_creds.push_back(creds);
1268 log.crit("plugin was not a credentials provider");
1272 catch (SAMLException& ex) {
1273 log.crit("error building credentials provider: %s",ex.what());
1278 // Now we load any attribute factories
1279 nlist=ReloadableXMLFileImpl::m_root->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(AttributeFactory));
1280 for (unsigned int i=0; nlist && i<nlist->getLength(); i++) {
1281 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
1282 log.info("building Attribute factory of type %s...",type.get());
1284 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
1286 IAttributeFactory* fact=dynamic_cast<IAttributeFactory*>(plugin);
1288 m_attrFactories.push_back(fact);
1289 ShibConfig::getConfig().regAttributeMapping(
1290 static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,L(AttributeName)),
1296 log.crit("plugin was not an Attribute factory");
1300 catch (SAMLException& ex) {
1301 log.crit("error building Attribute factory: %s",ex.what());
1305 // Load the default application. This actually has a fixed ID of "default". ;-)
1306 const DOMElement* app=saml::XML::getFirstChildElement(
1307 ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Applications)
1310 log.fatal("can't build default Application object, missing conf:Applications element?");
1311 throw ConfigurationException("can't build default Application object, missing conf:Applications element?");
1313 XMLApplication* defapp=new XMLApplication(m_outer, m_creds, app);
1314 m_appmap[defapp->getId()]=defapp;
1316 // Load any overrides.
1317 nlist=app->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Application));
1318 for (unsigned int j=0; nlist && j<nlist->getLength(); j++) {
1319 auto_ptr<XMLApplication> iapp(new XMLApplication(m_outer,m_creds,static_cast<DOMElement*>(nlist->item(j)),defapp));
1320 if (m_appmap.find(iapp->getId())!=m_appmap.end())
1321 log.crit("found conf:Application element with duplicate Id attribute, ignoring it");
1323 m_appmap[iapp->getId()]=iapp.release();
1326 catch (SAMLException& e) {
1327 log.errorStream() << "Error while loading SP configuration: " << e.what() << CategoryStream::ENDLINE;
1328 throw ConfigurationException(e.what());
1332 log.error("Unexpected error while loading SP configuration");
1338 XMLConfigImpl::~XMLConfigImpl()
1340 delete m_requestMapper;
1341 for_each(m_appmap.begin(),m_appmap.end(),cleanup_pair<string,IApplication>());
1342 for_each(m_creds.begin(),m_creds.end(),cleanup<ICredentials>());
1343 ShibConfig::getConfig().clearAttributeMappings();
1344 for_each(m_attrFactories.begin(),m_attrFactories.end(),cleanup<IAttributeFactory>());