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) {}
162 delete m_sessionCache;
164 delete m_replayCache;
170 void init() { getImplementation(); }
173 pair<bool,bool> getBool(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getBool(name,ns);}
174 pair<bool,const char*> getString(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getString(name,ns);}
175 pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getXMLString(name,ns);}
176 pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getUnsignedInt(name,ns);}
177 pair<bool,int> getInt(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getInt(name,ns);}
178 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);}
179 const DOMElement* getElement() const {return static_cast<XMLConfigImpl*>(m_impl)->getElement();}
182 IListener* getListener() const {return m_listener;}
183 ISessionCache* getSessionCache() const {return m_sessionCache;}
184 IReplayCache* getReplayCache() const {return m_replayCache;}
185 IRequestMapper* getRequestMapper() const {return static_cast<XMLConfigImpl*>(m_impl)->m_requestMapper;}
186 const IApplication* getApplication(const char* applicationId) const {
187 map<string,IApplication*>::const_iterator i=static_cast<XMLConfigImpl*>(m_impl)->m_appmap.find(applicationId);
188 return (i!=static_cast<XMLConfigImpl*>(m_impl)->m_appmap.end()) ? i->second : NULL;
190 Iterator<ICredentials*> getCredentialsProviders() const {return static_cast<XMLConfigImpl*>(m_impl)->m_creds;}
193 virtual ReloadableXMLFileImpl* newImplementation(const char* pathname, bool first=true) const;
194 virtual ReloadableXMLFileImpl* newImplementation(const DOMElement* e, bool first=true) const;
197 friend class XMLConfigImpl;
198 mutable IListener* m_listener;
199 mutable ISessionCache* m_sessionCache;
200 mutable IReplayCache* m_replayCache;
204 IConfig* STConfig::ShibTargetConfigFactory(const DOMElement* e)
206 return new XMLConfig(e);
209 XMLPropertySet::~XMLPropertySet()
211 for (map<string,pair<char*,const XMLCh*> >::iterator i=m_map.begin(); i!=m_map.end(); i++)
212 XMLString::release(&(i->second.first));
213 for_each(m_nested.begin(),m_nested.end(),shibtarget::cleanup_pair<string,IPropertySet>());
216 void XMLPropertySet::load(
219 DOMNodeFilter* filter,
220 const std::map<std::string,std::string>* remapper
224 saml::NDC ndc("load");
228 // Process each attribute as a property.
229 DOMNamedNodeMap* attrs=m_root->getAttributes();
230 for (XMLSize_t i=0; i<attrs->getLength(); i++) {
231 DOMNode* a=attrs->item(i);
232 if (!XMLString::compareString(a->getNamespaceURI(),saml::XML::XMLNS_NS))
234 char* val=XMLString::transcode(a->getNodeValue());
236 auto_ptr_char ns(a->getNamespaceURI());
237 auto_ptr_char name(a->getLocalName());
238 const char* realname=name.get();
240 map<string,string>::const_iterator remap=remapper->find(realname);
241 if (remap!=remapper->end()) {
242 log.warn("remapping property (%s) to (%s)",realname,remap->second.c_str());
243 realname=remap->second.c_str();
247 m_map[string("{") + ns.get() + '}' + realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
248 log.debug("added property {%s}%s (%s)",ns.get(),realname,val);
251 m_map[realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
252 log.debug("added property %s (%s)",realname,val);
257 // Process non-excluded elements as nested sets.
258 DOMTreeWalker* walker=
259 static_cast<DOMDocumentTraversal*>(
260 m_root->getOwnerDocument())->createTreeWalker(const_cast<DOMElement*>(m_root),DOMNodeFilter::SHOW_ELEMENT,filter,false
262 e=static_cast<DOMElement*>(walker->firstChild());
264 auto_ptr_char ns(e->getNamespaceURI());
265 auto_ptr_char name(e->getLocalName());
266 const char* realname=name.get();
268 map<string,string>::const_iterator remap=remapper->find(realname);
269 if (remap!=remapper->end()) {
270 log.warn("remapping property set (%s) to (%s)",realname,remap->second.c_str());
271 realname=remap->second.c_str();
276 key=string("{") + ns.get() + '}' + realname;
279 if (m_nested.find(key)!=m_nested.end())
280 log.warn("load() skipping duplicate property set: %s",key.c_str());
282 XMLPropertySet* set=new XMLPropertySet();
283 set->load(e,log,filter,remapper);
285 log.debug("added nested property set: %s",key.c_str());
287 e=static_cast<DOMElement*>(walker->nextSibling());
292 pair<bool,bool> XMLPropertySet::getBool(const char* name, const char* ns) const
294 pair<bool,bool> ret(false,false);
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=(!strcmp(i->second.first,"true") || !strcmp(i->second.first,"1"));
309 pair<bool,const char*> XMLPropertySet::getString(const char* name, const char* ns) const
311 pair<bool,const char*> ret(false,NULL);
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=i->second.first;
326 pair<bool,const XMLCh*> XMLPropertySet::getXMLString(const char* name, const char* ns) const
328 pair<bool,const XMLCh*> ret(false,NULL);
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=i->second.second;
343 pair<bool,unsigned int> XMLPropertySet::getUnsignedInt(const char* name, const char* ns) const
345 pair<bool,unsigned int> ret(false,0);
346 map<string,pair<char*,const XMLCh*> >::const_iterator i;
349 i=m_map.find(string("{") + ns + '}' + name);
353 if (i!=m_map.end()) {
355 ret.second=strtol(i->second.first,NULL,10);
360 pair<bool,int> XMLPropertySet::getInt(const char* name, const char* ns) const
362 pair<bool,int> ret(false,0);
363 map<string,pair<char*,const XMLCh*> >::const_iterator i;
366 i=m_map.find(string("{") + ns + '}' + name);
370 if (i!=m_map.end()) {
372 ret.second=atoi(i->second.first);
377 const IPropertySet* XMLPropertySet::getPropertySet(const char* name, const char* ns) const
379 map<string,IPropertySet*>::const_iterator i;
382 i=m_nested.find(string("{") + ns + '}' + name);
384 i=m_nested.find(name);
386 return (i!=m_nested.end()) ? i->second : NULL;
389 XMLApplication::XMLApplication(
391 const Iterator<ICredentials*>& creds,
393 const XMLApplication* base
394 ) : m_ini(ini), m_base(base), m_profile(NULL), m_binding(NULL), m_bindingHook(NULL),
395 m_credDefault(NULL), m_sessionInitDefault(NULL), m_acsDefault(NULL)
398 saml::NDC ndc("XMLApplication");
400 Category& log=Category::getInstance("shibtarget.XMLApplication");
403 // First load any property sets.
404 map<string,string> root_remap;
405 root_remap["shire"]="session";
406 root_remap["shireURL"]="handlerURL";
407 root_remap["shireSSL"]="handlerSSL";
408 load(e,log,this,&root_remap);
409 const IPropertySet* propcheck=getPropertySet("Errors");
410 if (propcheck && !propcheck->getString("session").first)
411 throw ConfigurationException("<Errors> element requires 'session' (or deprecated 'shire') attribute");
412 propcheck=getPropertySet("Sessions");
413 if (propcheck && !propcheck->getString("handlerURL").first)
414 throw ConfigurationException("<Sessions> element requires 'handlerURL' (or deprecated 'shireURL') attribute");
417 m_hash+=getString("providerId").second;
418 m_hash=SAMLArtifact::toHex(SAMLArtifactType0001::generateSourceId(m_hash.c_str()));
420 ShibTargetConfig& conf=ShibTargetConfig::getConfig();
421 SAMLConfig& shibConf=SAMLConfig::getConfig();
424 bool hardACS=false, hardSessionInit=false;
425 DOMElement* handler=saml::XML::getFirstChildElement(propcheck->getElement());
427 // A handler is split across a property set and the plugin itself, which is based on the Binding property.
428 // We build both objects first and then insert them into various structures for lookup.
430 XMLPropertySet* hprops=new XMLPropertySet();
432 hprops->load(handler,log,this); // filter irrelevant for now, no embedded elements expected
433 const char* bindprop=hprops->getString("Binding").second;
435 throw ConfigurationException("Handler element has no Binding attribute, skipping it...");
436 IPlugIn* hplug=shibConf.getPlugMgr().newPlugin(bindprop,handler);
437 hobj=dynamic_cast<IHandler*>(hplug);
440 throw UnsupportedProfileException(
441 "Plugin for binding ($1) does not implement IHandler interface.",params(1,bindprop)
445 catch (SAMLException& ex) {
446 // If we get here, the handler's not built, so dispose of the property set.
447 log.error("caught exception processing a handler element: %s",ex.what());
454 // Save off the objects after giving the property set to the handler for its use.
455 hobj->setProperties(hprops);
456 m_handlers.push_back(hobj);
457 m_handlerProps.push_back(hprops);
459 // Check for it in the location map.
460 const char* location=hprops->getString("Location").second;
461 if (m_handlerMap.count(location)==0)
462 m_handlerMap[location]=vector<const IHandler*>(1,hobj);
464 m_handlerMap[location].push_back(hobj);
466 // If it's an ACS or SI, handle index/id mappings and defaulting.
467 if (saml::XML::isElementNamed(handler,shibtarget::XML::SAML2META_NS,SHIBT_L(AssertionConsumerService))) {
470 const XMLCh* binding=hprops->getXMLString("Binding").second;
472 const char* binding=hprops->getString("Binding").second;
474 if (m_acsBindingMap.count(binding)==0)
475 m_acsBindingMap[binding]=vector<const IHandler*>(1,hobj);
477 m_acsBindingMap[binding].push_back(hobj);
478 m_acsIndexMap[hprops->getUnsignedInt("index").second]=hobj;
481 pair<bool,bool> defprop=hprops->getBool("isDefault");
483 if (defprop.second) {
488 else if (!m_acsDefault)
492 else if (saml::XML::isElementNamed(handler,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SessionInitiator))) {
493 pair<bool,const char*> si_id=hprops->getString("id");
494 if (si_id.first && si_id.second)
495 m_sessionInitMap[si_id.second]=hobj;
496 if (!hardSessionInit) {
497 pair<bool,bool> defprop=hprops->getBool("isDefault");
499 if (defprop.second) {
500 hardSessionInit=true;
501 m_sessionInitDefault=hobj;
504 else if (!m_sessionInitDefault)
505 m_sessionInitDefault=hobj;
508 handler=saml::XML::getNextSiblingElement(handler);
511 // If no handlers defined at the root, assume a legacy configuration.
512 if (!m_base && m_handlers.empty()) {
513 // A legacy config installs a SAML POST handler and a Shib session-initiator
514 // at the root handler location. We use the Sessions element itself as the
516 auto_ptr_char b1(Constants::SHIB_SESSIONINIT_PROFILE_URI);
517 IPlugIn* hplug=shibConf.getPlugMgr().newPlugin(b1.get(),propcheck->getElement());
518 IHandler* h1=dynamic_cast<IHandler*>(hplug);
521 throw UnsupportedProfileException(
522 "Plugin for binding ($1) does not implement IHandler interface.",params(1,b1.get())
525 h1->setProperties(propcheck);
526 m_handlers.push_back(h1);
527 m_handlerMap[""]=vector<const IHandler*>(1,h1);
528 m_sessionInitDefault=h1;
530 auto_ptr_char b2(SAMLBrowserProfile::BROWSER_POST);
531 hplug=shibConf.getPlugMgr().newPlugin(b1.get(),propcheck->getElement());
532 IHandler* h2=dynamic_cast<IHandler*>(hplug);
535 throw UnsupportedProfileException(
536 "Plugin for binding ($1) does not implement IHandler interface.",params(1,b2.get())
539 h2->setProperties(propcheck);
540 m_handlers.push_back(h2);
541 m_handlerMap[""].push_back(h2);
545 // Process general configuration elements.
547 DOMNodeList* nlist=e->getElementsByTagNameNS(saml::XML::SAML_NS,L(AttributeDesignator));
548 for (i=0; nlist && i<nlist->getLength(); i++)
549 if (nlist->item(i)->getParentNode()->isSameNode(e))
550 m_designators.push_back(new SAMLAttributeDesignator(static_cast<DOMElement*>(nlist->item(i))));
552 nlist=e->getElementsByTagNameNS(saml::XML::SAML_NS,L(Audience));
553 for (i=0; nlist && i<nlist->getLength(); i++)
554 if (nlist->item(i)->getParentNode()->isSameNode(e))
555 m_audiences.push_back(nlist->item(i)->getFirstChild()->getNodeValue());
557 // Always include our own providerId as an audience.
558 m_audiences.push_back(getXMLString("providerId").second);
560 if (conf.isEnabled(ShibTargetConfig::AAP)) {
561 nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(AAPProvider));
562 for (i=0; nlist && i<nlist->getLength(); i++) {
563 if (nlist->item(i)->getParentNode()->isSameNode(e)) {
564 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
565 log.info("building AAP provider of type %s...",type.get());
567 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
568 IAAP* aap=dynamic_cast<IAAP*>(plugin);
570 m_aaps.push_back(aap);
573 log.crit("plugin was not an AAP provider");
576 catch (SAMLException& ex) {
577 log.crit("error building AAP provider: %s",ex.what());
583 if (conf.isEnabled(ShibTargetConfig::Metadata)) {
584 nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MetadataProvider));
585 for (i=0; nlist && i<nlist->getLength(); i++) {
586 if (nlist->item(i)->getParentNode()->isSameNode(e)) {
587 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
588 log.info("building metadata provider of type %s...",type.get());
590 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
591 IMetadata* md=dynamic_cast<IMetadata*>(plugin);
593 m_metadatas.push_back(md);
596 log.crit("plugin was not a metadata provider");
599 catch (SAMLException& ex) {
600 log.crit("error building metadata provider: %s",ex.what());
604 nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(FederationProvider));
605 for (i=0; nlist && i<nlist->getLength(); i++) {
606 if (nlist->item(i)->getParentNode()->isSameNode(e)) {
607 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
608 log.info("building metadata provider of type %s...",type.get());
610 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
611 IMetadata* md=dynamic_cast<IMetadata*>(plugin);
613 m_metadatas.push_back(md);
616 log.crit("plugin was not a metadata provider");
619 catch (SAMLException& ex) {
620 log.crit("error building metadata provider: %s",ex.what());
626 if (conf.isEnabled(ShibTargetConfig::Trust)) {
627 nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(TrustProvider));
628 for (i=0; nlist && i<nlist->getLength(); i++) {
629 if (nlist->item(i)->getParentNode()->isSameNode(e)) {
630 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
631 log.info("building trust provider of type %s...",type.get());
633 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
634 ITrust* trust=dynamic_cast<ITrust*>(plugin);
636 m_trusts.push_back(trust);
639 log.crit("plugin was not a trust provider");
642 catch (SAMLException& ex) {
643 log.crit("error building trust provider: %s",ex.what());
649 // Finally, load credential mappings.
650 const DOMElement* cu=saml::XML::getFirstChildElement(e,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(CredentialUse));
652 m_credDefault=new XMLPropertySet();
653 m_credDefault->load(cu,log,this);
654 cu=saml::XML::getFirstChildElement(cu,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(RelyingParty));
656 XMLPropertySet* rp=new XMLPropertySet();
657 rp->load(cu,log,this);
658 m_credMap[cu->getAttributeNS(NULL,SHIBT_L(Name))]=rp;
659 cu=saml::XML::getNextSiblingElement(cu,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(RelyingParty));
663 if (conf.isEnabled(ShibTargetConfig::OutOfProcess)) {
664 // Really finally, build local browser profile and binding objects.
665 m_profile=new ShibBrowserProfile(
667 getMetadataProviders(),
670 m_bindingHook=new ShibHTTPHook(
674 m_binding=SAMLBinding::getInstance(SAMLBinding::SOAP);
675 SAMLSOAPHTTPBinding* bptr=dynamic_cast<SAMLSOAPHTTPBinding*>(m_binding);
677 log.fatal("binding implementation was not SOAP over HTTP");
678 throw UnsupportedExtensionException("binding implementation was not SOAP over HTTP");
680 bptr->addHook(m_bindingHook,m_bindingHook); // the hook is its own global context
683 catch (SAMLException& e) {
684 log.errorStream() << "Error while processing applicaton element: " << e.what() << CategoryStream::ENDLINE;
690 log.error("Unexpected error while processing application element");
697 void XMLApplication::cleanup()
699 delete m_bindingHook;
702 for_each(m_handlers.begin(),m_handlers.end(),shibtarget::cleanup<IHandler>());
704 delete m_credDefault;
706 for_each(m_credMap.begin(),m_credMap.end(),shibtarget::cleanup_pair<xstring,XMLPropertySet>());
708 for_each(m_credMap.begin(),m_credMap.end(),shibtarget::cleanup_pair<const XMLCh*,XMLPropertySet>());
710 for_each(m_designators.begin(),m_designators.end(),shibtarget::cleanup<SAMLAttributeDesignator>());
711 for_each(m_aaps.begin(),m_aaps.end(),shibtarget::cleanup<IAAP>());
712 for_each(m_metadatas.begin(),m_metadatas.end(),shibtarget::cleanup<IMetadata>());
713 for_each(m_trusts.begin(),m_trusts.end(),shibtarget::cleanup<ITrust>());
716 short XMLApplication::acceptNode(const DOMNode* node) const
718 if (saml::XML::isElementNamed(static_cast<const DOMElement*>(node),saml::XML::SAML_NS,L(AttributeDesignator)))
719 return FILTER_REJECT;
720 else if (saml::XML::isElementNamed(static_cast<const DOMElement*>(node),saml::XML::SAML_NS,L(Audience)))
721 return FILTER_REJECT;
722 const XMLCh* name=node->getLocalName();
723 if (!XMLString::compareString(name,SHIBT_L(Application)) ||
724 !XMLString::compareString(name,SHIBT_L(AssertionConsumerService)) ||
725 !XMLString::compareString(name,SHIBT_L(SingleLogoutService)) ||
726 !XMLString::compareString(name,SHIBT_L(DiagnosticService)) ||
727 !XMLString::compareString(name,SHIBT_L(SessionInitiator)) ||
728 !XMLString::compareString(name,SHIBT_L(AAPProvider)) ||
729 !XMLString::compareString(name,SHIBT_L(CredentialUse)) ||
730 !XMLString::compareString(name,SHIBT_L(RelyingParty)) ||
731 !XMLString::compareString(name,SHIBT_L(FederationProvider)) ||
732 !XMLString::compareString(name,SHIBT_L(MetadataProvider)) ||
733 !XMLString::compareString(name,SHIBT_L(TrustProvider)))
734 return FILTER_REJECT;
736 return FILTER_ACCEPT;
739 pair<bool,bool> XMLApplication::getBool(const char* name, const char* ns) const
741 pair<bool,bool> ret=XMLPropertySet::getBool(name,ns);
744 return m_base ? m_base->getBool(name,ns) : ret;
747 pair<bool,const char*> XMLApplication::getString(const char* name, const char* ns) const
749 pair<bool,const char*> ret=XMLPropertySet::getString(name,ns);
752 return m_base ? m_base->getString(name,ns) : ret;
755 pair<bool,const XMLCh*> XMLApplication::getXMLString(const char* name, const char* ns) const
757 pair<bool,const XMLCh*> ret=XMLPropertySet::getXMLString(name,ns);
760 return m_base ? m_base->getXMLString(name,ns) : ret;
763 pair<bool,unsigned int> XMLApplication::getUnsignedInt(const char* name, const char* ns) const
765 pair<bool,unsigned int> ret=XMLPropertySet::getUnsignedInt(name,ns);
768 return m_base ? m_base->getUnsignedInt(name,ns) : ret;
771 pair<bool,int> XMLApplication::getInt(const char* name, const char* ns) const
773 pair<bool,int> ret=XMLPropertySet::getInt(name,ns);
776 return m_base ? m_base->getInt(name,ns) : ret;
779 const IPropertySet* XMLApplication::getPropertySet(const char* name, const char* ns) const
781 const IPropertySet* ret=XMLPropertySet::getPropertySet(name,ns);
784 return m_base->getPropertySet(name,ns);
787 Iterator<SAMLAttributeDesignator*> XMLApplication::getAttributeDesignators() const
789 if (!m_designators.empty() || !m_base)
790 return m_designators;
791 return m_base->getAttributeDesignators();
794 Iterator<IAAP*> XMLApplication::getAAPProviders() const
796 return (m_aaps.empty() && m_base) ? m_base->getAAPProviders() : m_aaps;
799 Iterator<IMetadata*> XMLApplication::getMetadataProviders() const
801 return (m_metadatas.empty() && m_base) ? m_base->getMetadataProviders() : m_metadatas;
804 Iterator<ITrust*> XMLApplication::getTrustProviders() const
806 return (m_trusts.empty() && m_base) ? m_base->getTrustProviders() : m_trusts;
809 Iterator<const XMLCh*> XMLApplication::getAudiences() const
811 return (m_audiences.empty() && m_base) ? m_base->getAudiences() : m_audiences;
814 const IPropertySet* XMLApplication::getCredentialUse(const IEntityDescriptor* provider) const
816 if (!m_credDefault && m_base)
817 return m_base->getCredentialUse(provider);
820 map<xstring,XMLPropertySet*>::const_iterator i=m_credMap.find(provider->getId());
821 if (i!=m_credMap.end())
823 const IEntitiesDescriptor* group=provider->getEntitiesDescriptor();
825 if (group->getName()) {
826 i=m_credMap.find(group->getName());
827 if (i!=m_credMap.end())
830 group=group->getEntitiesDescriptor();
833 map<const XMLCh*,XMLPropertySet*>::const_iterator i=m_credMap.begin();
834 for (; i!=m_credMap.end(); i++) {
835 if (!XMLString::compareString(i->first,provider->getId()))
837 const IEntitiesDescriptor* group=provider->getEntitiesDescriptor();
839 if (!XMLString::compareString(i->first,group->getName()))
841 group=group->getEntitiesDescriptor();
845 return m_credDefault;
848 void XMLApplication::validateToken(SAMLAssertion* token, time_t ts, const IRoleDescriptor* role, const Iterator<ITrust*>& trusts) const
851 saml::NDC ndc("validateToken");
853 Category& log=Category::getInstance("shibtarget.XMLApplication");
855 // First we verify the time conditions, using the specified timestamp, if non-zero.
856 SAMLConfig& config=SAMLConfig::getConfig();
858 const SAMLDateTime* notBefore=token->getNotBefore();
859 if (notBefore && ts+config.clock_skew_secs < notBefore->getEpoch())
860 throw ExpiredAssertionException("Assertion is not yet valid.");
861 const SAMLDateTime* notOnOrAfter=token->getNotOnOrAfter();
862 if (notOnOrAfter && notOnOrAfter->getEpoch() <= ts-config.clock_skew_secs)
863 throw ExpiredAssertionException("Assertion is no longer valid.");
866 // Now we process conditions. Only audience restrictions at the moment.
867 Iterator<SAMLCondition*> conditions=token->getConditions();
868 while (conditions.hasNext()) {
869 SAMLCondition* cond=conditions.next();
870 const SAMLAudienceRestrictionCondition* ac=dynamic_cast<const SAMLAudienceRestrictionCondition*>(cond);
874 log.error("unrecognized Condition in assertion (%s)",os.str().c_str());
875 throw UnsupportedExtensionException("Assertion contains an unrecognized condition.");
877 else if (!ac->eval(getAudiences())) {
880 log.error("unacceptable AudienceRestrictionCondition in assertion (%s)",os.str().c_str());
881 throw UnsupportedProfileException("Assertion contains an unacceptable AudienceRestrictionCondition.");
886 log.warn("no metadata provided, so no signature validation was performed");
890 const IPropertySet* credUse=getCredentialUse(role->getEntityDescriptor());
891 pair<bool,bool> signedAssertions=credUse ? credUse->getBool("signedAssertions") : make_pair(false,false);
894 if (token->isSigned() && !t.validate(*token,role))
895 throw TrustException("Assertion signature did not validate.");
896 else if (signedAssertions.first && signedAssertions.second)
897 throw TrustException("Assertion was unsigned, violating policy based on the issuer.");
900 const IHandler* XMLApplication::getDefaultSessionInitiator() const
902 if (m_sessionInitDefault) return m_sessionInitDefault;
903 return m_base ? m_base->getDefaultSessionInitiator() : NULL;
906 const IHandler* XMLApplication::getSessionInitiatorById(const char* id) const
908 map<string,const IHandler*>::const_iterator i=m_sessionInitMap.find(id);
909 if (i!=m_sessionInitMap.end()) return i->second;
910 return m_base ? m_base->getSessionInitiatorById(id) : NULL;
913 const IHandler* XMLApplication::getDefaultAssertionConsumerService() const
915 if (m_acsDefault) return m_acsDefault;
916 return m_base ? m_base->getDefaultAssertionConsumerService() : NULL;
919 const IHandler* XMLApplication::getAssertionConsumerServiceByIndex(unsigned short index) const
921 map<unsigned int,const IHandler*>::const_iterator i=m_acsIndexMap.find(index);
922 if (i!=m_acsIndexMap.end()) return i->second;
923 return m_base ? m_base->getAssertionConsumerServiceByIndex(index) : NULL;
926 Iterator<const IHandler*> XMLApplication::getAssertionConsumerServicesByBinding(const XMLCh* binding) const
929 ACSBindingMap::const_iterator i=m_acsBindingMap.find(binding);
931 auto_ptr_char temp(binding);
932 ACSBindingMap::const_iterator i=m_acsBindingMap.find(temp.get());
934 if (i!=m_acsBindingMap.end())
936 return m_base ? m_base->getAssertionConsumerServicesByBinding(binding) : EMPTY(const IHandler*);
939 Iterator<const IHandler*> XMLApplication::getHandlers(const char* path) const
942 map<string,vector<const IHandler*> >::const_iterator i=m_handlerMap.find(wrap.substr(0,wrap.find('?')));
943 if (i!=m_handlerMap.end())
945 return m_base ? m_base->getHandlers(path) : EMPTY(const IHandler*);
948 ReloadableXMLFileImpl* XMLConfig::newImplementation(const char* pathname, bool first) const
950 return new XMLConfigImpl(pathname,first,this);
953 ReloadableXMLFileImpl* XMLConfig::newImplementation(const DOMElement* e, bool first) const
955 return new XMLConfigImpl(e,first,this);
958 short XMLConfigImpl::acceptNode(const DOMNode* node) const
960 if (XMLString::compareString(node->getNamespaceURI(),shibtarget::XML::SHIBTARGET_NS))
961 return FILTER_ACCEPT;
962 const XMLCh* name=node->getLocalName();
963 if (!XMLString::compareString(name,SHIBT_L(Applications)) ||
964 !XMLString::compareString(name,SHIBT_L(AttributeFactory)) ||
965 !XMLString::compareString(name,SHIBT_L(CredentialsProvider)) ||
966 !XMLString::compareString(name,SHIBT_L(Extensions)) ||
967 !XMLString::compareString(name,SHIBT_L(Implementation)) ||
968 !XMLString::compareString(name,SHIBT_L(Listener)) ||
969 !XMLString::compareString(name,SHIBT_L(MemorySessionCache)) ||
970 !XMLString::compareString(name,SHIBT_L(MySQLReplayCache)) ||
971 !XMLString::compareString(name,SHIBT_L(MySQLSessionCache)) ||
972 !XMLString::compareString(name,SHIBT_L(RequestMap)) ||
973 !XMLString::compareString(name,SHIBT_L(RequestMapProvider)) ||
974 !XMLString::compareString(name,SHIBT_L(ReplayCache)) ||
975 !XMLString::compareString(name,SHIBT_L(SessionCache)) ||
976 !XMLString::compareString(name,SHIBT_L(TCPListener)) ||
977 !XMLString::compareString(name,SHIBT_L(UnixListener)))
978 return FILTER_REJECT;
980 return FILTER_ACCEPT;
983 void XMLConfigImpl::init(bool first)
986 saml::NDC ndc("init");
988 Category& log=Category::getInstance("shibtarget.Config");
991 if (!saml::XML::isElementNamed(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(ShibbolethTargetConfig)) &&
992 !saml::XML::isElementNamed(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SPConfig))) {
993 log.error("Construction requires a valid configuration file: (conf:SPConfig as root element)");
994 throw ConfigurationException("Construction requires a valid configuration file: (conf:SPConfig as root element)");
997 SAMLConfig& shibConf=SAMLConfig::getConfig();
998 ShibTargetConfig& conf=ShibTargetConfig::getConfig();
999 const DOMElement* SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SHAR));
1001 SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Global));
1003 SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(OutOfProcess));
1004 const DOMElement* SHIRE=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SHIRE));
1006 SHIRE=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Local));
1008 SHIRE=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(InProcess));
1010 // Initialize log4cpp manually in order to redirect log messages as soon as possible.
1011 if (conf.isEnabled(ShibTargetConfig::Logging)) {
1012 const XMLCh* logger=NULL;
1013 if (conf.isEnabled(ShibTargetConfig::OutOfProcess))
1014 logger=SHAR->getAttributeNS(NULL,SHIBT_L(logger));
1015 else if (conf.isEnabled(ShibTargetConfig::InProcess))
1016 logger=SHIRE->getAttributeNS(NULL,SHIBT_L(logger));
1017 if (!logger || !*logger)
1018 logger=ReloadableXMLFileImpl::m_root->getAttributeNS(NULL,SHIBT_L(logger));
1019 if (logger && *logger) {
1020 auto_ptr_char logpath(logger);
1021 log.debug("loading new logging configuration from (%s), check log destination for status of configuration",logpath.get());
1023 PropertyConfigurator::configure(logpath.get());
1025 catch (ConfigureFailure& e) {
1026 log.error("Error reading logging configuration: %s",e.what());
1031 // First load any property sets.
1032 map<string,string> root_remap;
1033 root_remap["SHAR"]="OutOfProcess";
1034 root_remap["SHIRE"]="InProcess";
1035 root_remap["Global"]="OutOfProcess";
1036 root_remap["Local"]="InProcess";
1037 load(ReloadableXMLFileImpl::m_root,log,this,&root_remap);
1039 // Much of the processing can only occur on the first instantiation.
1041 // Now load any extensions to insure any needed plugins are registered.
1043 saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Extensions));
1045 exts=saml::XML::getFirstChildElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1047 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
1049 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
1050 log.debug("loaded global extension library %s",path.get());
1052 catch (SAMLException& e) {
1053 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
1054 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
1055 log.fatal("unable to load mandatory global extension library %s: %s", path.get(), e.what());
1059 log.crit("unable to load optional global extension library %s: %s", path.get(), e.what());
1061 exts=saml::XML::getNextSiblingElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1065 if (conf.isEnabled(ShibTargetConfig::OutOfProcess)) {
1066 exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Extensions));
1068 exts=saml::XML::getFirstChildElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1070 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
1072 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
1073 log.debug("loaded Global extension library %s",path.get());
1075 catch (SAMLException& e) {
1076 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
1077 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
1078 log.fatal("unable to load mandatory Global extension library %s: %s", path.get(), e.what());
1082 log.crit("unable to load optional Global extension library %s: %s", path.get(), e.what());
1084 exts=saml::XML::getNextSiblingElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1089 if (conf.isEnabled(ShibTargetConfig::InProcess)) {
1090 exts=saml::XML::getFirstChildElement(SHIRE,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Extensions));
1092 exts=saml::XML::getFirstChildElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1094 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
1096 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
1097 log.debug("loaded Local extension library %s",path.get());
1099 catch (SAMLException& e) {
1100 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
1101 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
1102 log.fatal("unable to load mandatory Local extension library %s: %s", path.get(), e.what());
1106 log.crit("unable to load optional Local extension library %s: %s", path.get(), e.what());
1108 exts=saml::XML::getNextSiblingElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1113 // Instantiate the Listener and SessionCache objects.
1114 if (conf.isEnabled(ShibTargetConfig::Listener)) {
1115 IPlugIn* plugin=NULL;
1116 exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(UnixListener));
1118 log.info("building Listener of type %s...",shibtarget::XML::UnixListenerType);
1119 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::UnixListenerType,exts);
1122 exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(TCPListener));
1124 log.info("building Listener of type %s...",shibtarget::XML::TCPListenerType);
1125 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::TCPListenerType,exts);
1128 exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Listener));
1130 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
1131 log.info("building Listener of type %s...",type.get());
1132 plugin=shibConf.getPlugMgr().newPlugin(type.get(),exts);
1135 log.fatal("can't build Listener object, missing conf:Listener element?");
1136 throw ConfigurationException("can't build Listener object, missing conf:Listener element?");
1141 IListener* listen=dynamic_cast<IListener*>(plugin);
1143 m_outer->m_listener=listen;
1146 log.fatal("plugin was not a Listener object");
1147 throw UnsupportedExtensionException("plugin was not a Listener object");
1152 if (conf.isEnabled(ShibTargetConfig::Caching)) {
1153 IPlugIn* plugin=NULL;
1154 const DOMElement* container=conf.isEnabled(ShibTargetConfig::OutOfProcess) ? SHAR : SHIRE;
1155 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MemorySessionCache));
1157 log.info("building Session Cache of type %s...",shibtarget::XML::MemorySessionCacheType);
1158 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::MemorySessionCacheType,exts);
1161 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(ODBCSessionCache));
1163 log.info("building Session Cache of type %s...",shibtarget::XML::ODBCSessionCacheType);
1164 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::ODBCSessionCacheType,exts);
1167 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MySQLSessionCache));
1169 log.info("building Session Cache of type %s...",shibtarget::XML::MySQLSessionCacheType);
1170 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::MySQLSessionCacheType,exts);
1173 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SessionCache));
1175 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
1176 log.info("building Session Cache of type %s...",type.get());
1177 plugin=shibConf.getPlugMgr().newPlugin(type.get(),exts);
1180 log.info("session cache not specified, building Session Cache of type %s...",shibtarget::XML::MemorySessionCacheType);
1181 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::MemorySessionCacheType,exts);
1187 ISessionCache* cache=dynamic_cast<ISessionCache*>(plugin);
1189 m_outer->m_sessionCache=cache;
1192 log.fatal("plugin was not a Session Cache object");
1193 throw UnsupportedExtensionException("plugin was not a Session Cache object");
1198 container=conf.isEnabled(ShibTargetConfig::OutOfProcess) ? SHAR : SHIRE;
1199 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(ODBCReplayCache));
1201 log.info("building Replay Cache of type %s...",shibtarget::XML::ODBCReplayCacheType);
1202 m_outer->m_replayCache=IReplayCache::getInstance(shibtarget::XML::ODBCReplayCacheType,exts);
1205 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MySQLReplayCache));
1207 log.info("building Replay Cache of type %s...",shibtarget::XML::MySQLReplayCacheType);
1208 m_outer->m_replayCache=IReplayCache::getInstance(shibtarget::XML::MySQLReplayCacheType,exts);
1211 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(ReplayCache));
1213 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
1214 log.info("building Replay Cache of type %s...",type.get());
1215 m_outer->m_replayCache=IReplayCache::getInstance(type.get(),exts);
1218 // OpenSAML default provider.
1219 log.info("building default Replay Cache...");
1220 m_outer->m_replayCache=IReplayCache::getInstance();
1227 // Back to the fully dynamic stuff...next up is the Request Mapper.
1228 if (conf.isEnabled(ShibTargetConfig::RequestMapper)) {
1229 const DOMElement* child=saml::XML::getFirstChildElement(SHIRE,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(RequestMapProvider));
1231 auto_ptr_char type(child->getAttributeNS(NULL,SHIBT_L(type)));
1232 log.info("building Request Mapper of type %s...",type.get());
1233 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),child);
1235 IRequestMapper* reqmap=dynamic_cast<IRequestMapper*>(plugin);
1237 m_requestMapper=reqmap;
1240 log.fatal("plugin was not a Request Mapper object");
1241 throw UnsupportedExtensionException("plugin was not a Request Mapper object");
1246 log.fatal("can't build Request Mapper object, missing conf:RequestMapProvider element?");
1247 throw ConfigurationException("can't build Request Mapper object, missing conf:RequestMapProvider element?");
1251 // Now we load any credentials providers.
1253 if (conf.isEnabled(ShibTargetConfig::Credentials)) {
1254 nlist=ReloadableXMLFileImpl::m_root->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(CredentialsProvider));
1255 for (unsigned int i=0; nlist && i<nlist->getLength(); i++) {
1256 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
1257 log.info("building credentials provider of type %s...",type.get());
1259 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
1261 ICredentials* creds=dynamic_cast<ICredentials*>(plugin);
1263 m_creds.push_back(creds);
1266 log.crit("plugin was not a credentials provider");
1270 catch (SAMLException& ex) {
1271 log.crit("error building credentials provider: %s",ex.what());
1276 // Now we load any attribute factories
1277 nlist=ReloadableXMLFileImpl::m_root->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(AttributeFactory));
1278 for (unsigned int i=0; nlist && i<nlist->getLength(); i++) {
1279 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
1280 log.info("building Attribute factory of type %s...",type.get());
1282 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
1284 IAttributeFactory* fact=dynamic_cast<IAttributeFactory*>(plugin);
1286 m_attrFactories.push_back(fact);
1287 ShibConfig::getConfig().regAttributeMapping(
1288 static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,L(AttributeName)),
1294 log.crit("plugin was not an Attribute factory");
1298 catch (SAMLException& ex) {
1299 log.crit("error building Attribute factory: %s",ex.what());
1303 // Load the default application. This actually has a fixed ID of "default". ;-)
1304 const DOMElement* app=saml::XML::getFirstChildElement(
1305 ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Applications)
1308 log.fatal("can't build default Application object, missing conf:Applications element?");
1309 throw ConfigurationException("can't build default Application object, missing conf:Applications element?");
1311 XMLApplication* defapp=new XMLApplication(m_outer, m_creds, app);
1312 m_appmap[defapp->getId()]=defapp;
1314 // Load any overrides.
1315 nlist=app->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Application));
1316 for (unsigned int j=0; nlist && j<nlist->getLength(); j++) {
1317 auto_ptr<XMLApplication> iapp(new XMLApplication(m_outer,m_creds,static_cast<DOMElement*>(nlist->item(j)),defapp));
1318 if (m_appmap.find(iapp->getId())!=m_appmap.end())
1319 log.crit("found conf:Application element with duplicate Id attribute, ignoring it");
1321 m_appmap[iapp->getId()]=iapp.release();
1324 catch (SAMLException& e) {
1325 log.errorStream() << "Error while loading SP configuration: " << e.what() << CategoryStream::ENDLINE;
1326 throw ConfigurationException(e.what());
1330 log.error("Unexpected error while loading SP configuration");
1336 XMLConfigImpl::~XMLConfigImpl()
1338 delete m_requestMapper;
1339 for_each(m_appmap.begin(),m_appmap.end(),cleanup_pair<string,IApplication>());
1340 for_each(m_creds.begin(),m_creds.end(),cleanup<ICredentials>());
1341 ShibConfig::getConfig().clearAttributeMappings();
1342 for_each(m_attrFactories.begin(),m_attrFactories.end(),cleanup<IAttributeFactory>());