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 <log4cpp/Category.hh>
26 #include <log4cpp/PropertyConfigurator.hh>
28 #include <sys/types.h>
33 using namespace shibboleth;
34 using namespace shibtarget;
35 using namespace log4cpp;
37 namespace shibtarget {
39 // Application configuration wrapper
40 class XMLApplication : public virtual IApplication, public XMLPropertySet, public DOMNodeFilter
43 XMLApplication(const IConfig*, const Iterator<ICredentials*>& creds, const DOMElement* e, const XMLApplication* base=NULL);
44 ~XMLApplication() { cleanup(); }
47 pair<bool,bool> getBool(const char* name, const char* ns=NULL) const;
48 pair<bool,const char*> getString(const char* name, const char* ns=NULL) const;
49 pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const;
50 pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const;
51 pair<bool,int> getInt(const char* name, const char* ns=NULL) const;
52 const IPropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const;
55 const char* getId() const {return getString("id").second;}
56 const char* getHash() const {return m_hash.c_str();}
57 Iterator<SAMLAttributeDesignator*> getAttributeDesignators() const;
58 Iterator<IAAP*> getAAPProviders() const;
59 Iterator<IMetadata*> getMetadataProviders() const;
60 Iterator<ITrust*> getTrustProviders() const;
61 Iterator<const XMLCh*> getAudiences() const;
62 const IPropertySet* getCredentialUse(const IEntityDescriptor* provider) const;
63 const SAMLBrowserProfile* getBrowserProfile() const {return m_profile;}
64 const SAMLBinding* getBinding(const XMLCh* binding) const
65 {return XMLString::compareString(SAMLBinding::SOAP,binding) ? NULL : m_binding;}
66 SAMLBrowserProfile::ArtifactMapper* getArtifactMapper() const {return new STArtifactMapper(this);}
70 const IRoleDescriptor* role=NULL,
71 const Iterator<ITrust*>& trusts=EMPTY(ITrust*)
73 const IHandler* getDefaultSessionInitiator() const;
74 const IHandler* getSessionInitiatorById(const char* id) const;
75 const IHandler* getDefaultAssertionConsumerService() const;
76 const IHandler* getAssertionConsumerServiceByIndex(unsigned short index) const;
77 Iterator<const IHandler*> getAssertionConsumerServicesByBinding(const XMLCh* binding) const;
78 const IHandler* getHandler(const char* path) const;
80 // Provides filter to exclude special config elements.
81 short acceptNode(const DOMNode* node) const;
85 const IConfig* m_ini; // this is ok because its locking scope includes us
86 const XMLApplication* m_base;
88 vector<SAMLAttributeDesignator*> m_designators;
90 vector<IMetadata*> m_metadatas;
91 vector<ITrust*> m_trusts;
92 vector<const XMLCh*> m_audiences;
93 ShibBrowserProfile* m_profile;
94 SAMLBinding* m_binding;
95 ShibHTTPHook* m_bindingHook;
97 // vectors manage object life for handlers and their property sets
98 vector<IHandler*> m_handlers;
99 vector<XMLPropertySet*> m_handlerProps;
101 // maps location (path info) to applicable handlers
102 map<string,const IHandler*> m_handlerMap;
104 // maps unique indexes to consumer services
105 map<unsigned int,const IHandler*> m_acsIndexMap;
107 // pointer to default consumer service
108 const IHandler* m_acsDefault;
110 // maps binding strings to supporting consumer service(s)
112 typedef map<xstring,vector<const IHandler*> > ACSBindingMap;
114 typedef map<string,vector<const IHandler*> > ACSBindingMap;
116 ACSBindingMap m_acsBindingMap;
118 // maps unique ID strings to session initiators
119 map<string,const IHandler*> m_sessionInitMap;
121 // pointer to default session initiator
122 const IHandler* m_sessionInitDefault;
124 XMLPropertySet* m_credDefault;
126 map<xstring,XMLPropertySet*> m_credMap;
128 map<const XMLCh*,XMLPropertySet*> m_credMap;
132 // Top-level configuration implementation
134 class XMLConfigImpl : public ReloadableXMLFileImpl, public XMLPropertySet, public DOMNodeFilter
137 XMLConfigImpl(const char* pathname, bool first, const XMLConfig* outer)
138 : ReloadableXMLFileImpl(pathname), m_outer(outer), m_requestMapper(NULL) { init(first); }
139 XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer)
140 : ReloadableXMLFileImpl(e), m_outer(outer), m_requestMapper(NULL) { init(first); }
143 IRequestMapper* m_requestMapper;
144 map<string,IApplication*> m_appmap;
145 vector<ICredentials*> m_creds;
146 vector<IAttributeFactory*> m_attrFactories;
148 // Provides filter to exclude special config elements.
149 short acceptNode(const DOMNode* node) const;
152 void init(bool first);
153 const XMLConfig* m_outer;
156 class XMLConfig : public IConfig, public ReloadableXMLFile
159 XMLConfig(const DOMElement* e) : ReloadableXMLFile(e), m_listener(NULL), m_sessionCache(NULL), m_replayCache(NULL) {}
163 delete m_sessionCache;
165 delete m_replayCache;
171 void init() { getImplementation(); }
174 pair<bool,bool> getBool(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getBool(name,ns);}
175 pair<bool,const char*> getString(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getString(name,ns);}
176 pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getXMLString(name,ns);}
177 pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getUnsignedInt(name,ns);}
178 pair<bool,int> getInt(const char* name, const char* ns=NULL) const {return static_cast<XMLConfigImpl*>(m_impl)->getInt(name,ns);}
179 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);}
180 const DOMElement* getElement() const {return static_cast<XMLConfigImpl*>(m_impl)->getElement();}
183 IListener* getListener() const {return m_listener;}
184 ISessionCache* getSessionCache() const {return m_sessionCache;}
185 IReplayCache* getReplayCache() const {return m_replayCache;}
186 IRequestMapper* getRequestMapper() const {return static_cast<XMLConfigImpl*>(m_impl)->m_requestMapper;}
187 const IApplication* getApplication(const char* applicationId) const {
188 map<string,IApplication*>::const_iterator i=static_cast<XMLConfigImpl*>(m_impl)->m_appmap.find(applicationId);
189 return (i!=static_cast<XMLConfigImpl*>(m_impl)->m_appmap.end()) ? i->second : NULL;
191 Iterator<ICredentials*> getCredentialsProviders() const {return static_cast<XMLConfigImpl*>(m_impl)->m_creds;}
194 virtual ReloadableXMLFileImpl* newImplementation(const char* pathname, bool first=true) const;
195 virtual ReloadableXMLFileImpl* newImplementation(const DOMElement* e, bool first=true) const;
198 friend class XMLConfigImpl;
199 mutable IListener* m_listener;
200 mutable ISessionCache* m_sessionCache;
201 mutable IReplayCache* m_replayCache;
205 IConfig* STConfig::ShibTargetConfigFactory(const DOMElement* e)
207 return new XMLConfig(e);
210 XMLPropertySet::~XMLPropertySet()
212 for (map<string,pair<char*,const XMLCh*> >::iterator i=m_map.begin(); i!=m_map.end(); i++)
213 XMLString::release(&(i->second.first));
214 for_each(m_nested.begin(),m_nested.end(),shibtarget::cleanup_pair<string,IPropertySet>());
217 void XMLPropertySet::load(
220 DOMNodeFilter* filter,
221 const std::map<std::string,std::string>* remapper
225 saml::NDC ndc("load");
229 // Process each attribute as a property.
230 DOMNamedNodeMap* attrs=m_root->getAttributes();
231 for (XMLSize_t i=0; i<attrs->getLength(); i++) {
232 DOMNode* a=attrs->item(i);
233 if (!XMLString::compareString(a->getNamespaceURI(),saml::XML::XMLNS_NS))
235 char* val=XMLString::transcode(a->getNodeValue());
237 auto_ptr_char ns(a->getNamespaceURI());
238 auto_ptr_char name(a->getLocalName());
239 const char* realname=name.get();
241 map<string,string>::const_iterator remap=remapper->find(realname);
242 if (remap!=remapper->end()) {
243 log.warn("remapping property (%s) to (%s)",realname,remap->second.c_str());
244 realname=remap->second.c_str();
248 m_map[string("{") + ns.get() + '}' + realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
249 log.debug("added property {%s}%s (%s)",ns.get(),realname,val);
252 m_map[realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
253 log.debug("added property %s (%s)",realname,val);
258 // Process non-excluded elements as nested sets.
259 DOMTreeWalker* walker=
260 static_cast<DOMDocumentTraversal*>(
261 m_root->getOwnerDocument())->createTreeWalker(const_cast<DOMElement*>(m_root),DOMNodeFilter::SHOW_ELEMENT,filter,false
263 e=static_cast<DOMElement*>(walker->firstChild());
265 auto_ptr_char ns(e->getNamespaceURI());
266 auto_ptr_char name(e->getLocalName());
267 const char* realname=name.get();
269 map<string,string>::const_iterator remap=remapper->find(realname);
270 if (remap!=remapper->end()) {
271 log.warn("remapping property set (%s) to (%s)",realname,remap->second.c_str());
272 realname=remap->second.c_str();
277 key=string("{") + ns.get() + '}' + realname;
280 if (m_nested.find(key)!=m_nested.end())
281 log.warn("load() skipping duplicate property set: %s",key.c_str());
283 XMLPropertySet* set=new XMLPropertySet();
284 set->load(e,log,filter,remapper);
286 log.debug("added nested property set: %s",key.c_str());
288 e=static_cast<DOMElement*>(walker->nextSibling());
293 pair<bool,bool> XMLPropertySet::getBool(const char* name, const char* ns) const
295 pair<bool,bool> ret(false,false);
296 map<string,pair<char*,const XMLCh*> >::const_iterator i;
299 i=m_map.find(string("{") + ns + '}' + name);
303 if (i!=m_map.end()) {
305 ret.second=(!strcmp(i->second.first,"true") || !strcmp(i->second.first,"1"));
310 pair<bool,const char*> XMLPropertySet::getString(const char* name, const char* ns) const
312 pair<bool,const char*> ret(false,NULL);
313 map<string,pair<char*,const XMLCh*> >::const_iterator i;
316 i=m_map.find(string("{") + ns + '}' + name);
320 if (i!=m_map.end()) {
322 ret.second=i->second.first;
327 pair<bool,const XMLCh*> XMLPropertySet::getXMLString(const char* name, const char* ns) const
329 pair<bool,const XMLCh*> ret(false,NULL);
330 map<string,pair<char*,const XMLCh*> >::const_iterator i;
333 i=m_map.find(string("{") + ns + '}' + name);
337 if (i!=m_map.end()) {
339 ret.second=i->second.second;
344 pair<bool,unsigned int> XMLPropertySet::getUnsignedInt(const char* name, const char* ns) const
346 pair<bool,unsigned int> ret(false,0);
347 map<string,pair<char*,const XMLCh*> >::const_iterator i;
350 i=m_map.find(string("{") + ns + '}' + name);
354 if (i!=m_map.end()) {
356 ret.second=strtol(i->second.first,NULL,10);
361 pair<bool,int> XMLPropertySet::getInt(const char* name, const char* ns) const
363 pair<bool,int> ret(false,0);
364 map<string,pair<char*,const XMLCh*> >::const_iterator i;
367 i=m_map.find(string("{") + ns + '}' + name);
371 if (i!=m_map.end()) {
373 ret.second=atoi(i->second.first);
378 const IPropertySet* XMLPropertySet::getPropertySet(const char* name, const char* ns) const
380 map<string,IPropertySet*>::const_iterator i;
383 i=m_nested.find(string("{") + ns + '}' + name);
385 i=m_nested.find(name);
387 return (i!=m_nested.end()) ? i->second : NULL;
390 XMLApplication::XMLApplication(
392 const Iterator<ICredentials*>& creds,
394 const XMLApplication* base
395 ) : m_ini(ini), m_base(base), m_profile(NULL), m_binding(NULL), m_bindingHook(NULL),
396 m_credDefault(NULL), m_sessionInitDefault(NULL), m_acsDefault(NULL)
399 saml::NDC ndc("XMLApplication");
401 Category& log=Category::getInstance("shibtarget.XMLApplication");
404 // First load any property sets.
405 map<string,string> root_remap;
406 root_remap["shire"]="session";
407 root_remap["shireURL"]="handlerURL";
408 root_remap["shireSSL"]="handlerSSL";
409 load(e,log,this,&root_remap);
410 const IPropertySet* propcheck=getPropertySet("Errors");
411 if (propcheck && !propcheck->getString("session").first)
412 throw ConfigurationException("<Errors> element requires 'session' (or deprecated 'shire') attribute");
413 propcheck=getPropertySet("Sessions");
414 if (propcheck && !propcheck->getString("handlerURL").first)
415 throw ConfigurationException("<Sessions> element requires 'handlerURL' (or deprecated 'shireURL') attribute");
418 m_hash+=getString("providerId").second;
419 m_hash=SAMLArtifact::toHex(SAMLArtifactType0001::generateSourceId(m_hash.c_str()));
421 ShibTargetConfig& conf=ShibTargetConfig::getConfig();
422 SAMLConfig& shibConf=SAMLConfig::getConfig();
425 bool hardACS=false, hardSessionInit=false;
426 DOMElement* handler=saml::XML::getFirstChildElement(propcheck->getElement());
428 // A handler is split across a property set and the plugin itself, which is based on the Binding property.
429 // We build both objects first and then insert them into various structures for lookup.
431 XMLPropertySet* hprops=new XMLPropertySet();
433 hprops->load(handler,log,this); // filter irrelevant for now, no embedded elements expected
434 const char* bindprop=hprops->getString("Binding").second;
436 throw ConfigurationException("Handler element has no Binding attribute, skipping it...");
437 IPlugIn* hplug=shibConf.getPlugMgr().newPlugin(bindprop,handler);
438 hobj=dynamic_cast<IHandler*>(hplug);
441 throw UnsupportedProfileException(
442 "Plugin for binding ($1) does not implement IHandler interface.",params(1,bindprop)
446 catch (SAMLException& ex) {
447 // If we get here, the handler's not built, so dispose of the property set.
448 log.error("caught exception processing a handler element: %s",ex.what());
453 const char* location=hprops ? hprops->getString("Location").second : NULL;
457 handler=saml::XML::getNextSiblingElement(handler);
461 // Save off the objects after giving the property set to the handler for its use.
462 hobj->setProperties(hprops);
463 m_handlers.push_back(hobj);
464 m_handlerProps.push_back(hprops);
466 // Insert into location map.
467 if (*location == '/')
468 m_handlerMap[location]=hobj;
470 m_handlerMap[string("/") + location]=hobj;
472 // If it's an ACS or SI, handle index/id mappings and defaulting.
473 if (saml::XML::isElementNamed(handler,shibtarget::XML::SAML2META_NS,SHIBT_L(AssertionConsumerService))) {
476 const XMLCh* binding=hprops->getXMLString("Binding").second;
478 const char* binding=hprops->getString("Binding").second;
480 if (m_acsBindingMap.count(binding)==0)
481 m_acsBindingMap[binding]=vector<const IHandler*>(1,hobj);
483 m_acsBindingMap[binding].push_back(hobj);
484 m_acsIndexMap[hprops->getUnsignedInt("index").second]=hobj;
487 pair<bool,bool> defprop=hprops->getBool("isDefault");
489 if (defprop.second) {
494 else if (!m_acsDefault)
498 else if (saml::XML::isElementNamed(handler,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SessionInitiator))) {
499 pair<bool,const char*> si_id=hprops->getString("id");
500 if (si_id.first && si_id.second)
501 m_sessionInitMap[si_id.second]=hobj;
502 if (!hardSessionInit) {
503 pair<bool,bool> defprop=hprops->getBool("isDefault");
505 if (defprop.second) {
506 hardSessionInit=true;
507 m_sessionInitDefault=hobj;
510 else if (!m_sessionInitDefault)
511 m_sessionInitDefault=hobj;
514 handler=saml::XML::getNextSiblingElement(handler);
517 // If no handlers defined at the root, assume a legacy configuration.
518 if (!m_base && m_handlers.empty()) {
519 // A legacy config installs a SAML POST handler at the root handler location.
520 // We use the Sessions element itself as the IPropertySet.
522 auto_ptr_char b1(Constants::SHIB_SESSIONINIT_PROFILE_URI);
523 IPlugIn* hplug=shibConf.getPlugMgr().newPlugin(b1.get(),propcheck->getElement());
524 IHandler* h1=dynamic_cast<IHandler*>(hplug);
527 throw UnsupportedProfileException(
528 "Plugin for binding ($1) does not implement IHandler interface.",params(1,b1.get())
531 h1->setProperties(propcheck);
532 m_handlers.push_back(h1);
533 m_sessionInitDefault=h1;
535 auto_ptr_char b2(SAMLBrowserProfile::BROWSER_POST);
536 hplug=shibConf.getPlugMgr().newPlugin(b2.get(),propcheck->getElement());
537 IHandler* h2=dynamic_cast<IHandler*>(hplug);
540 throw UnsupportedProfileException(
541 "Plugin for binding ($1) does not implement IHandler interface.",params(1,b2.get())
544 h2->setProperties(propcheck);
545 m_handlers.push_back(h2);
546 m_handlerMap[""] = h2;
550 // Process general configuration elements.
552 DOMNodeList* nlist=e->getElementsByTagNameNS(saml::XML::SAML_NS,L(AttributeDesignator));
553 for (i=0; nlist && i<nlist->getLength(); i++)
554 if (nlist->item(i)->getParentNode()->isSameNode(e))
555 m_designators.push_back(new SAMLAttributeDesignator(static_cast<DOMElement*>(nlist->item(i))));
557 nlist=e->getElementsByTagNameNS(saml::XML::SAML_NS,L(Audience));
558 for (i=0; nlist && i<nlist->getLength(); i++)
559 if (nlist->item(i)->getParentNode()->isSameNode(e))
560 m_audiences.push_back(nlist->item(i)->getFirstChild()->getNodeValue());
562 // Always include our own providerId as an audience.
563 m_audiences.push_back(getXMLString("providerId").second);
565 if (conf.isEnabled(ShibTargetConfig::AAP)) {
566 nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(AAPProvider));
567 for (i=0; nlist && i<nlist->getLength(); i++) {
568 if (nlist->item(i)->getParentNode()->isSameNode(e)) {
569 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
570 log.info("building AAP provider of type %s...",type.get());
572 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
573 IAAP* aap=dynamic_cast<IAAP*>(plugin);
575 m_aaps.push_back(aap);
578 log.crit("plugin was not an AAP provider");
581 catch (SAMLException& ex) {
582 log.crit("error building AAP provider: %s",ex.what());
588 if (conf.isEnabled(ShibTargetConfig::Metadata)) {
589 nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MetadataProvider));
590 for (i=0; nlist && i<nlist->getLength(); i++) {
591 if (nlist->item(i)->getParentNode()->isSameNode(e)) {
592 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
593 log.info("building metadata provider of type %s...",type.get());
595 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
596 IMetadata* md=dynamic_cast<IMetadata*>(plugin);
598 m_metadatas.push_back(md);
601 log.crit("plugin was not a metadata provider");
604 catch (SAMLException& ex) {
605 log.crit("error building metadata provider: %s",ex.what());
609 nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(FederationProvider));
610 for (i=0; nlist && i<nlist->getLength(); i++) {
611 if (nlist->item(i)->getParentNode()->isSameNode(e)) {
612 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
613 log.info("building metadata provider of type %s...",type.get());
615 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
616 IMetadata* md=dynamic_cast<IMetadata*>(plugin);
618 m_metadatas.push_back(md);
621 log.crit("plugin was not a metadata provider");
624 catch (SAMLException& ex) {
625 log.crit("error building metadata provider: %s",ex.what());
631 if (conf.isEnabled(ShibTargetConfig::Trust)) {
632 nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(TrustProvider));
633 for (i=0; nlist && i<nlist->getLength(); i++) {
634 if (nlist->item(i)->getParentNode()->isSameNode(e)) {
635 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
636 log.info("building trust provider of type %s...",type.get());
638 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
639 ITrust* trust=dynamic_cast<ITrust*>(plugin);
641 m_trusts.push_back(trust);
644 log.crit("plugin was not a trust provider");
647 catch (SAMLException& ex) {
648 log.crit("error building trust provider: %s",ex.what());
654 // Finally, load credential mappings.
655 const DOMElement* cu=saml::XML::getFirstChildElement(e,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(CredentialUse));
657 m_credDefault=new XMLPropertySet();
658 m_credDefault->load(cu,log,this);
659 cu=saml::XML::getFirstChildElement(cu,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(RelyingParty));
661 XMLPropertySet* rp=new XMLPropertySet();
662 rp->load(cu,log,this);
663 m_credMap[cu->getAttributeNS(NULL,SHIBT_L(Name))]=rp;
664 cu=saml::XML::getNextSiblingElement(cu,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(RelyingParty));
668 if (conf.isEnabled(ShibTargetConfig::OutOfProcess)) {
669 // Really finally, build local browser profile and binding objects.
670 m_profile=new ShibBrowserProfile(
672 getMetadataProviders(),
675 m_bindingHook=new ShibHTTPHook(
679 m_binding=SAMLBinding::getInstance(SAMLBinding::SOAP);
680 SAMLSOAPHTTPBinding* bptr=dynamic_cast<SAMLSOAPHTTPBinding*>(m_binding);
682 log.fatal("binding implementation was not SOAP over HTTP");
683 throw UnsupportedExtensionException("binding implementation was not SOAP over HTTP");
685 bptr->addHook(m_bindingHook,m_bindingHook); // the hook is its own global context
688 catch (SAMLException& e) {
689 log.errorStream() << "Error while processing applicaton element: " << e.what() << CategoryStream::ENDLINE;
695 log.error("Unexpected error while processing application element");
702 void XMLApplication::cleanup()
704 delete m_bindingHook;
707 for_each(m_handlers.begin(),m_handlers.end(),shibtarget::cleanup<IHandler>());
709 delete m_credDefault;
711 for_each(m_credMap.begin(),m_credMap.end(),shibtarget::cleanup_pair<xstring,XMLPropertySet>());
713 for_each(m_credMap.begin(),m_credMap.end(),shibtarget::cleanup_pair<const XMLCh*,XMLPropertySet>());
715 for_each(m_designators.begin(),m_designators.end(),shibtarget::cleanup<SAMLAttributeDesignator>());
716 for_each(m_aaps.begin(),m_aaps.end(),shibtarget::cleanup<IAAP>());
717 for_each(m_metadatas.begin(),m_metadatas.end(),shibtarget::cleanup<IMetadata>());
718 for_each(m_trusts.begin(),m_trusts.end(),shibtarget::cleanup<ITrust>());
721 short XMLApplication::acceptNode(const DOMNode* node) const
723 if (saml::XML::isElementNamed(static_cast<const DOMElement*>(node),saml::XML::SAML_NS,L(AttributeDesignator)))
724 return FILTER_REJECT;
725 else if (saml::XML::isElementNamed(static_cast<const DOMElement*>(node),saml::XML::SAML_NS,L(Audience)))
726 return FILTER_REJECT;
727 const XMLCh* name=node->getLocalName();
728 if (!XMLString::compareString(name,SHIBT_L(Application)) ||
729 !XMLString::compareString(name,SHIBT_L(AssertionConsumerService)) ||
730 !XMLString::compareString(name,SHIBT_L(SingleLogoutService)) ||
731 !XMLString::compareString(name,SHIBT_L(DiagnosticService)) ||
732 !XMLString::compareString(name,SHIBT_L(SessionInitiator)) ||
733 !XMLString::compareString(name,SHIBT_L(AAPProvider)) ||
734 !XMLString::compareString(name,SHIBT_L(CredentialUse)) ||
735 !XMLString::compareString(name,SHIBT_L(RelyingParty)) ||
736 !XMLString::compareString(name,SHIBT_L(FederationProvider)) ||
737 !XMLString::compareString(name,SHIBT_L(MetadataProvider)) ||
738 !XMLString::compareString(name,SHIBT_L(TrustProvider)))
739 return FILTER_REJECT;
741 return FILTER_ACCEPT;
744 pair<bool,bool> XMLApplication::getBool(const char* name, const char* ns) const
746 pair<bool,bool> ret=XMLPropertySet::getBool(name,ns);
749 return m_base ? m_base->getBool(name,ns) : ret;
752 pair<bool,const char*> XMLApplication::getString(const char* name, const char* ns) const
754 pair<bool,const char*> ret=XMLPropertySet::getString(name,ns);
757 return m_base ? m_base->getString(name,ns) : ret;
760 pair<bool,const XMLCh*> XMLApplication::getXMLString(const char* name, const char* ns) const
762 pair<bool,const XMLCh*> ret=XMLPropertySet::getXMLString(name,ns);
765 return m_base ? m_base->getXMLString(name,ns) : ret;
768 pair<bool,unsigned int> XMLApplication::getUnsignedInt(const char* name, const char* ns) const
770 pair<bool,unsigned int> ret=XMLPropertySet::getUnsignedInt(name,ns);
773 return m_base ? m_base->getUnsignedInt(name,ns) : ret;
776 pair<bool,int> XMLApplication::getInt(const char* name, const char* ns) const
778 pair<bool,int> ret=XMLPropertySet::getInt(name,ns);
781 return m_base ? m_base->getInt(name,ns) : ret;
784 const IPropertySet* XMLApplication::getPropertySet(const char* name, const char* ns) const
786 const IPropertySet* ret=XMLPropertySet::getPropertySet(name,ns);
789 return m_base->getPropertySet(name,ns);
792 Iterator<SAMLAttributeDesignator*> XMLApplication::getAttributeDesignators() const
794 if (!m_designators.empty() || !m_base)
795 return m_designators;
796 return m_base->getAttributeDesignators();
799 Iterator<IAAP*> XMLApplication::getAAPProviders() const
801 return (m_aaps.empty() && m_base) ? m_base->getAAPProviders() : m_aaps;
804 Iterator<IMetadata*> XMLApplication::getMetadataProviders() const
806 return (m_metadatas.empty() && m_base) ? m_base->getMetadataProviders() : m_metadatas;
809 Iterator<ITrust*> XMLApplication::getTrustProviders() const
811 return (m_trusts.empty() && m_base) ? m_base->getTrustProviders() : m_trusts;
814 Iterator<const XMLCh*> XMLApplication::getAudiences() const
816 return (m_audiences.empty() && m_base) ? m_base->getAudiences() : m_audiences;
819 const IPropertySet* XMLApplication::getCredentialUse(const IEntityDescriptor* provider) const
821 if (!m_credDefault && m_base)
822 return m_base->getCredentialUse(provider);
825 map<xstring,XMLPropertySet*>::const_iterator i=m_credMap.find(provider->getId());
826 if (i!=m_credMap.end())
828 const IEntitiesDescriptor* group=provider->getEntitiesDescriptor();
830 if (group->getName()) {
831 i=m_credMap.find(group->getName());
832 if (i!=m_credMap.end())
835 group=group->getEntitiesDescriptor();
838 map<const XMLCh*,XMLPropertySet*>::const_iterator i=m_credMap.begin();
839 for (; i!=m_credMap.end(); i++) {
840 if (!XMLString::compareString(i->first,provider->getId()))
842 const IEntitiesDescriptor* group=provider->getEntitiesDescriptor();
844 if (!XMLString::compareString(i->first,group->getName()))
846 group=group->getEntitiesDescriptor();
850 return m_credDefault;
853 void XMLApplication::validateToken(SAMLAssertion* token, time_t ts, const IRoleDescriptor* role, const Iterator<ITrust*>& trusts) const
856 saml::NDC ndc("validateToken");
858 Category& log=Category::getInstance("shibtarget.XMLApplication");
860 // First we verify the time conditions, using the specified timestamp, if non-zero.
861 SAMLConfig& config=SAMLConfig::getConfig();
863 const SAMLDateTime* notBefore=token->getNotBefore();
864 if (notBefore && ts+config.clock_skew_secs < notBefore->getEpoch())
865 throw ExpiredAssertionException("Assertion is not yet valid.");
866 const SAMLDateTime* notOnOrAfter=token->getNotOnOrAfter();
867 if (notOnOrAfter && notOnOrAfter->getEpoch() <= ts-config.clock_skew_secs)
868 throw ExpiredAssertionException("Assertion is no longer valid.");
871 // Now we process conditions. Only audience restrictions at the moment.
872 Iterator<SAMLCondition*> conditions=token->getConditions();
873 while (conditions.hasNext()) {
874 SAMLCondition* cond=conditions.next();
875 const SAMLAudienceRestrictionCondition* ac=dynamic_cast<const SAMLAudienceRestrictionCondition*>(cond);
879 log.error("unrecognized Condition in assertion (%s)",os.str().c_str());
880 throw UnsupportedExtensionException("Assertion contains an unrecognized condition.");
882 else if (!ac->eval(getAudiences())) {
885 log.error("unacceptable AudienceRestrictionCondition in assertion (%s)",os.str().c_str());
886 throw UnsupportedProfileException("Assertion contains an unacceptable AudienceRestrictionCondition.");
891 log.warn("no metadata provided, so no signature validation was performed");
895 const IPropertySet* credUse=getCredentialUse(role->getEntityDescriptor());
896 pair<bool,bool> signedAssertions=credUse ? credUse->getBool("signedAssertions") : make_pair(false,false);
899 if (token->isSigned() && !t.validate(*token,role))
900 throw TrustException("Assertion signature did not validate.");
901 else if (signedAssertions.first && signedAssertions.second)
902 throw TrustException("Assertion was unsigned, violating policy based on the issuer.");
905 const IHandler* XMLApplication::getDefaultSessionInitiator() const
907 if (m_sessionInitDefault) return m_sessionInitDefault;
908 return m_base ? m_base->getDefaultSessionInitiator() : NULL;
911 const IHandler* XMLApplication::getSessionInitiatorById(const char* id) const
913 map<string,const IHandler*>::const_iterator i=m_sessionInitMap.find(id);
914 if (i!=m_sessionInitMap.end()) return i->second;
915 return m_base ? m_base->getSessionInitiatorById(id) : NULL;
918 const IHandler* XMLApplication::getDefaultAssertionConsumerService() const
920 if (m_acsDefault) return m_acsDefault;
921 return m_base ? m_base->getDefaultAssertionConsumerService() : NULL;
924 const IHandler* XMLApplication::getAssertionConsumerServiceByIndex(unsigned short index) const
926 map<unsigned int,const IHandler*>::const_iterator i=m_acsIndexMap.find(index);
927 if (i!=m_acsIndexMap.end()) return i->second;
928 return m_base ? m_base->getAssertionConsumerServiceByIndex(index) : NULL;
931 Iterator<const IHandler*> XMLApplication::getAssertionConsumerServicesByBinding(const XMLCh* binding) const
934 ACSBindingMap::const_iterator i=m_acsBindingMap.find(binding);
936 auto_ptr_char temp(binding);
937 ACSBindingMap::const_iterator i=m_acsBindingMap.find(temp.get());
939 if (i!=m_acsBindingMap.end())
941 return m_base ? m_base->getAssertionConsumerServicesByBinding(binding) : EMPTY(const IHandler*);
944 const IHandler* XMLApplication::getHandler(const char* path) const
947 map<string,const IHandler*>::const_iterator i=m_handlerMap.find(wrap.substr(0,wrap.find('?')));
948 if (i!=m_handlerMap.end())
950 return m_base ? m_base->getHandler(path) : NULL;
953 ReloadableXMLFileImpl* XMLConfig::newImplementation(const char* pathname, bool first) const
955 return new XMLConfigImpl(pathname,first,this);
958 ReloadableXMLFileImpl* XMLConfig::newImplementation(const DOMElement* e, bool first) const
960 return new XMLConfigImpl(e,first,this);
963 short XMLConfigImpl::acceptNode(const DOMNode* node) const
965 if (XMLString::compareString(node->getNamespaceURI(),shibtarget::XML::SHIBTARGET_NS))
966 return FILTER_ACCEPT;
967 const XMLCh* name=node->getLocalName();
968 if (!XMLString::compareString(name,SHIBT_L(Applications)) ||
969 !XMLString::compareString(name,SHIBT_L(AttributeFactory)) ||
970 !XMLString::compareString(name,SHIBT_L(CredentialsProvider)) ||
971 !XMLString::compareString(name,SHIBT_L(Extensions)) ||
972 !XMLString::compareString(name,SHIBT_L(Implementation)) ||
973 !XMLString::compareString(name,SHIBT_L(Listener)) ||
974 !XMLString::compareString(name,SHIBT_L(MemorySessionCache)) ||
975 !XMLString::compareString(name,SHIBT_L(MySQLReplayCache)) ||
976 !XMLString::compareString(name,SHIBT_L(MySQLSessionCache)) ||
977 !XMLString::compareString(name,SHIBT_L(RequestMap)) ||
978 !XMLString::compareString(name,SHIBT_L(RequestMapProvider)) ||
979 !XMLString::compareString(name,SHIBT_L(ReplayCache)) ||
980 !XMLString::compareString(name,SHIBT_L(SessionCache)) ||
981 !XMLString::compareString(name,SHIBT_L(TCPListener)) ||
982 !XMLString::compareString(name,SHIBT_L(UnixListener)))
983 return FILTER_REJECT;
985 return FILTER_ACCEPT;
988 void XMLConfigImpl::init(bool first)
991 saml::NDC ndc("init");
993 Category& log=Category::getInstance("shibtarget.Config");
996 if (!saml::XML::isElementNamed(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(ShibbolethTargetConfig)) &&
997 !saml::XML::isElementNamed(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SPConfig))) {
998 log.error("Construction requires a valid configuration file: (conf:SPConfig as root element)");
999 throw ConfigurationException("Construction requires a valid configuration file: (conf:SPConfig as root element)");
1002 SAMLConfig& shibConf=SAMLConfig::getConfig();
1003 ShibTargetConfig& conf=ShibTargetConfig::getConfig();
1004 const DOMElement* SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SHAR));
1006 SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Global));
1008 SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(OutOfProcess));
1009 const DOMElement* SHIRE=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SHIRE));
1011 SHIRE=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Local));
1013 SHIRE=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(InProcess));
1015 // Initialize log4cpp manually in order to redirect log messages as soon as possible.
1016 if (conf.isEnabled(ShibTargetConfig::Logging)) {
1017 const XMLCh* logger=NULL;
1018 if (conf.isEnabled(ShibTargetConfig::OutOfProcess))
1019 logger=SHAR->getAttributeNS(NULL,SHIBT_L(logger));
1020 else if (conf.isEnabled(ShibTargetConfig::InProcess))
1021 logger=SHIRE->getAttributeNS(NULL,SHIBT_L(logger));
1022 if (!logger || !*logger)
1023 logger=ReloadableXMLFileImpl::m_root->getAttributeNS(NULL,SHIBT_L(logger));
1024 if (logger && *logger) {
1025 auto_ptr_char logpath(logger);
1026 log.debug("loading new logging configuration from (%s), check log destination for status of configuration",logpath.get());
1028 PropertyConfigurator::configure(logpath.get());
1030 catch (ConfigureFailure& e) {
1031 log.error("Error reading logging configuration: %s",e.what());
1036 // First load any property sets.
1037 map<string,string> root_remap;
1038 root_remap["SHAR"]="OutOfProcess";
1039 root_remap["SHIRE"]="InProcess";
1040 root_remap["Global"]="OutOfProcess";
1041 root_remap["Local"]="InProcess";
1042 load(ReloadableXMLFileImpl::m_root,log,this,&root_remap);
1044 // Much of the processing can only occur on the first instantiation.
1046 // Now load any extensions to insure any needed plugins are registered.
1048 saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Extensions));
1050 exts=saml::XML::getFirstChildElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1052 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
1054 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
1055 log.debug("loaded global extension library %s",path.get());
1057 catch (SAMLException& e) {
1058 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
1059 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
1060 log.fatal("unable to load mandatory global extension library %s: %s", path.get(), e.what());
1064 log.crit("unable to load optional global extension library %s: %s", path.get(), e.what());
1066 exts=saml::XML::getNextSiblingElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1070 if (conf.isEnabled(ShibTargetConfig::OutOfProcess)) {
1071 exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Extensions));
1073 exts=saml::XML::getFirstChildElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1075 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
1077 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
1078 log.debug("loaded Global extension library %s",path.get());
1080 catch (SAMLException& e) {
1081 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
1082 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
1083 log.fatal("unable to load mandatory Global extension library %s: %s", path.get(), e.what());
1087 log.crit("unable to load optional Global extension library %s: %s", path.get(), e.what());
1089 exts=saml::XML::getNextSiblingElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1094 if (conf.isEnabled(ShibTargetConfig::InProcess)) {
1095 exts=saml::XML::getFirstChildElement(SHIRE,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Extensions));
1097 exts=saml::XML::getFirstChildElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1099 auto_ptr_char path(exts->getAttributeNS(NULL,SHIBT_L(path)));
1101 SAMLConfig::getConfig().saml_register_extension(path.get(),exts);
1102 log.debug("loaded Local extension library %s",path.get());
1104 catch (SAMLException& e) {
1105 const XMLCh* fatal=exts->getAttributeNS(NULL,SHIBT_L(fatal));
1106 if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
1107 log.fatal("unable to load mandatory Local extension library %s: %s", path.get(), e.what());
1111 log.crit("unable to load optional Local extension library %s: %s", path.get(), e.what());
1113 exts=saml::XML::getNextSiblingElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library));
1118 // Instantiate the Listener and SessionCache objects.
1119 if (conf.isEnabled(ShibTargetConfig::Listener)) {
1120 IPlugIn* plugin=NULL;
1121 exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(UnixListener));
1123 log.info("building Listener of type %s...",shibtarget::XML::UnixListenerType);
1124 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::UnixListenerType,exts);
1127 exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(TCPListener));
1129 log.info("building Listener of type %s...",shibtarget::XML::TCPListenerType);
1130 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::TCPListenerType,exts);
1133 exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Listener));
1135 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
1136 log.info("building Listener of type %s...",type.get());
1137 plugin=shibConf.getPlugMgr().newPlugin(type.get(),exts);
1140 log.fatal("can't build Listener object, missing conf:Listener element?");
1141 throw ConfigurationException("can't build Listener object, missing conf:Listener element?");
1146 IListener* listen=dynamic_cast<IListener*>(plugin);
1148 m_outer->m_listener=listen;
1151 log.fatal("plugin was not a Listener object");
1152 throw UnsupportedExtensionException("plugin was not a Listener object");
1157 if (conf.isEnabled(ShibTargetConfig::Caching)) {
1158 IPlugIn* plugin=NULL;
1159 const DOMElement* container=conf.isEnabled(ShibTargetConfig::OutOfProcess) ? SHAR : SHIRE;
1160 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MemorySessionCache));
1162 log.info("building Session Cache of type %s...",shibtarget::XML::MemorySessionCacheType);
1163 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::MemorySessionCacheType,exts);
1166 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(ODBCSessionCache));
1168 log.info("building Session Cache of type %s...",shibtarget::XML::ODBCSessionCacheType);
1169 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::ODBCSessionCacheType,exts);
1172 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MySQLSessionCache));
1174 log.info("building Session Cache of type %s...",shibtarget::XML::MySQLSessionCacheType);
1175 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::MySQLSessionCacheType,exts);
1178 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SessionCache));
1180 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
1181 log.info("building Session Cache of type %s...",type.get());
1182 plugin=shibConf.getPlugMgr().newPlugin(type.get(),exts);
1185 log.info("session cache not specified, building Session Cache of type %s...",shibtarget::XML::MemorySessionCacheType);
1186 plugin=shibConf.getPlugMgr().newPlugin(shibtarget::XML::MemorySessionCacheType,exts);
1192 ISessionCache* cache=dynamic_cast<ISessionCache*>(plugin);
1194 m_outer->m_sessionCache=cache;
1197 log.fatal("plugin was not a Session Cache object");
1198 throw UnsupportedExtensionException("plugin was not a Session Cache object");
1203 container=conf.isEnabled(ShibTargetConfig::OutOfProcess) ? SHAR : SHIRE;
1204 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(ODBCReplayCache));
1206 log.info("building Replay Cache of type %s...",shibtarget::XML::ODBCReplayCacheType);
1207 m_outer->m_replayCache=IReplayCache::getInstance(shibtarget::XML::ODBCReplayCacheType,exts);
1210 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MySQLReplayCache));
1212 log.info("building Replay Cache of type %s...",shibtarget::XML::MySQLReplayCacheType);
1213 m_outer->m_replayCache=IReplayCache::getInstance(shibtarget::XML::MySQLReplayCacheType,exts);
1216 exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(ReplayCache));
1218 auto_ptr_char type(exts->getAttributeNS(NULL,SHIBT_L(type)));
1219 log.info("building Replay Cache of type %s...",type.get());
1220 m_outer->m_replayCache=IReplayCache::getInstance(type.get(),exts);
1223 // OpenSAML default provider.
1224 log.info("building default Replay Cache...");
1225 m_outer->m_replayCache=IReplayCache::getInstance();
1232 // Back to the fully dynamic stuff...next up is the Request Mapper.
1233 if (conf.isEnabled(ShibTargetConfig::RequestMapper)) {
1234 const DOMElement* child=saml::XML::getFirstChildElement(SHIRE,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(RequestMapProvider));
1236 auto_ptr_char type(child->getAttributeNS(NULL,SHIBT_L(type)));
1237 log.info("building Request Mapper of type %s...",type.get());
1238 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),child);
1240 IRequestMapper* reqmap=dynamic_cast<IRequestMapper*>(plugin);
1242 m_requestMapper=reqmap;
1245 log.fatal("plugin was not a Request Mapper object");
1246 throw UnsupportedExtensionException("plugin was not a Request Mapper object");
1251 log.fatal("can't build Request Mapper object, missing conf:RequestMapProvider element?");
1252 throw ConfigurationException("can't build Request Mapper object, missing conf:RequestMapProvider element?");
1256 // Now we load any credentials providers.
1258 if (conf.isEnabled(ShibTargetConfig::Credentials)) {
1259 nlist=ReloadableXMLFileImpl::m_root->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(CredentialsProvider));
1260 for (unsigned int i=0; nlist && i<nlist->getLength(); i++) {
1261 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
1262 log.info("building credentials provider of type %s...",type.get());
1264 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
1266 ICredentials* creds=dynamic_cast<ICredentials*>(plugin);
1268 m_creds.push_back(creds);
1271 log.crit("plugin was not a credentials provider");
1275 catch (SAMLException& ex) {
1276 log.crit("error building credentials provider: %s",ex.what());
1281 // Now we load any attribute factories
1282 nlist=ReloadableXMLFileImpl::m_root->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(AttributeFactory));
1283 for (unsigned int i=0; nlist && i<nlist->getLength(); i++) {
1284 auto_ptr_char type(static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type)));
1285 log.info("building Attribute factory of type %s...",type.get());
1287 IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast<DOMElement*>(nlist->item(i)));
1289 IAttributeFactory* fact=dynamic_cast<IAttributeFactory*>(plugin);
1291 m_attrFactories.push_back(fact);
1292 ShibConfig::getConfig().regAttributeMapping(
1293 static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,L(AttributeName)),
1299 log.crit("plugin was not an Attribute factory");
1303 catch (SAMLException& ex) {
1304 log.crit("error building Attribute factory: %s",ex.what());
1308 // Load the default application. This actually has a fixed ID of "default". ;-)
1309 const DOMElement* app=saml::XML::getFirstChildElement(
1310 ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Applications)
1313 log.fatal("can't build default Application object, missing conf:Applications element?");
1314 throw ConfigurationException("can't build default Application object, missing conf:Applications element?");
1316 XMLApplication* defapp=new XMLApplication(m_outer, m_creds, app);
1317 m_appmap[defapp->getId()]=defapp;
1319 // Load any overrides.
1320 nlist=app->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Application));
1321 for (unsigned int j=0; nlist && j<nlist->getLength(); j++) {
1322 auto_ptr<XMLApplication> iapp(new XMLApplication(m_outer,m_creds,static_cast<DOMElement*>(nlist->item(j)),defapp));
1323 if (m_appmap.find(iapp->getId())!=m_appmap.end())
1324 log.crit("found conf:Application element with duplicate Id attribute, ignoring it");
1326 m_appmap[iapp->getId()]=iapp.release();
1329 catch (SAMLException& e) {
1330 log.errorStream() << "Error while loading SP configuration: " << e.what() << CategoryStream::ENDLINE;
1331 throw ConfigurationException(e.what());
1335 log.error("Unexpected error while loading SP configuration");
1341 XMLConfigImpl::~XMLConfigImpl()
1343 delete m_requestMapper;
1344 for_each(m_appmap.begin(),m_appmap.end(),cleanup_pair<string,IApplication>());
1345 for_each(m_creds.begin(),m_creds.end(),cleanup<ICredentials>());
1346 ShibConfig::getConfig().clearAttributeMappings();
1347 for_each(m_attrFactories.begin(),m_attrFactories.end(),cleanup<IAttributeFactory>());