2 * The Shibboleth License, Version 1.
4 * University Corporation for Advanced Internet Development, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * Redistributions of source code must retain the above copyright notice, this
12 * list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution, if any, must include
17 * the following acknowledgment: "This product includes software developed by
18 * the University Corporation for Advanced Internet Development
19 * <http://www.ucaid.edu>Internet2 Project. Alternately, this acknowledegement
20 * may appear in the software itself, if and wherever such third-party
21 * acknowledgments normally appear.
23 * Neither the name of Shibboleth nor the names of its contributors, nor
24 * Internet2, nor the University Corporation for Advanced Internet Development,
25 * Inc., nor UCAID may be used to endorse or promote products derived from this
26 * software without specific prior written permission. For written permission,
27 * please contact shibboleth@shibboleth.org
29 * Products derived from this software may not be called Shibboleth, Internet2,
30 * UCAID, or the University Corporation for Advanced Internet Development, nor
31 * may Shibboleth appear in their name, without prior written permission of the
32 * University Corporation for Advanced Internet Development.
35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
36 * AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
38 * PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED AND THE ENTIRE RISK
39 * OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH LICENSEE.
40 * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY
41 * CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC. BE LIABLE FOR ANY DIRECT,
42 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
43 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 /* XMLMetadata.cpp - a metadata implementation that uses an XML-based registry
60 #include <sys/types.h>
63 #include <log4cpp/Category.hh>
64 #include <xercesc/util/XMLChar.hpp>
65 #include <xsec/enc/XSECCryptoException.hpp>
66 #include <xsec/enc/XSECKeyInfoResolverDefault.hpp>
67 #include <xsec/enc/OpenSSL/OpenSSLCryptoX509.hpp>
69 using namespace shibboleth;
71 using namespace log4cpp;
76 class XMLMetadataImpl : public ReloadableXMLFileImpl
79 class ContactPerson : public IContactPerson
82 ContactPerson(const DOMElement* e);
85 ContactType getType() const { return m_type; }
86 const char* getCompany() const { return m_company.get(); }
87 const char* getGivenName() const { return m_givenName.get(); }
88 const char* getSurName() const { return m_surName.get(); }
89 Iterator<string> getEmailAddresses() const { return m_emails; }
90 Iterator<string> getTelephoneNumbers() const { return m_phones; }
91 const DOMElement* getElement() const { return m_root; }
94 const DOMElement* m_root;
96 auto_ptr<char> m_givenName,m_surName,m_company;
97 vector<string> m_emails,m_phones;
100 class Organization : public IOrganization
103 Organization(const DOMElement* e);
106 const char* getName(const char* lang="en") const { return forLang(m_names,lang); }
107 const char* getDisplayName(const char* lang="en") const { return forLang(m_displays,lang); }
108 const char* getURL(const char* lang="en") const { return forLang(m_urls,lang); }
109 const DOMElement* getElement() const { return m_root; }
112 const char* forLang(const map<string,string>& m, const char* lang) const {
113 map<string,string>::const_iterator i=m.find(lang);
114 return (i==m.end()) ? NULL : i->second.c_str();
116 const DOMElement* m_root;
117 map<string,string> m_names,m_displays,m_urls;
120 class EntityDescriptor;
122 class EncryptionMethod : public XENCEncryptionMethod
125 EncryptionMethod(const DOMElement* e);
126 ~EncryptionMethod() {}
128 const XMLCh * getAlgorithm(void) const { return m_alg; }
129 const XMLCh * getDigestMethod(void) const { return m_digest; }
130 const XMLCh * getOAEPparams(void) const { return m_params; }
131 int getKeySize(void) const { return m_size; }
132 DOMElement* getElement(void) const { return const_cast<DOMElement*>(m_root); }
133 void setDigestMethod(const XMLCh * method) {throw exception();}
134 void setOAEPparams(const XMLCh * params) {throw exception();}
135 void setKeySize(int size) {throw exception();}
138 const DOMElement* m_root;
140 const XMLCh* m_digest;
141 const XMLCh* m_params;
145 class KeyDescriptor : public IKeyDescriptor
148 KeyDescriptor(const DOMElement* e);
151 KeyUse getUse() const { return m_use; }
152 DSIGKeyInfoList* getKeyInfo() const { return &m_klist; }
153 saml::Iterator<const XENCEncryptionMethod*> getEncryptionMethods() const { return m_methods; }
154 const DOMElement* getElement() const { return m_root; }
157 const DOMElement* m_root;
159 mutable DSIGKeyInfoList m_klist;
160 vector<const XENCEncryptionMethod*> m_methods;
163 class Role : public virtual IRoleDescriptor
166 Role(const EntityDescriptor* provider, time_t validUntil, const DOMElement* e);
170 const IEntityDescriptor* getEntityDescriptor() const {return m_provider;}
171 Iterator<const XMLCh*> getProtocolSupportEnumeration() const {return m_protocolEnum;}
172 bool hasSupport(const XMLCh* protocol) const;
173 const char* getErrorURL() const {return (m_errorURL ? m_errorURL : m_provider->getErrorURL());}
174 bool isValid() const {return time(NULL) < m_validUntil;}
175 Iterator<const IKeyDescriptor*> getKeyDescriptors() const {return m_keys;}
176 const IOrganization* getOrganization() const {return m_org;}
177 Iterator<const IContactPerson*> getContactPersons() const
178 {return (m_contacts.empty() ? m_provider->getContactPersons() : m_contacts);}
179 const DOMElement* getElement() const {return m_root;}
182 vector<const XMLCh*> m_protocolEnum;
183 vector<const IKeyDescriptor*> m_keys;
186 const EntityDescriptor* m_provider;
187 const DOMElement* m_root;
188 XMLCh* m_protocolEnumCopy;
191 vector<const IContactPerson*> m_contacts;
195 class Endpoint : public virtual IEndpoint
198 Endpoint(const DOMElement* e) : m_root(e),
199 m_binding(e->getAttributeNS(NULL,L(Binding))),
200 m_location(e->getAttributeNS(NULL,SHIB_L(Location))),
201 m_resploc(e->getAttributeNS(NULL,SHIB_L(ResponseLocation))) {}
202 Endpoint(const XMLCh* binding, const XMLCh* loc)
203 : m_root(NULL), m_binding(binding), m_location(loc), m_resploc(NULL) {}
206 const XMLCh* getBinding() const { return m_binding; }
207 const XMLCh* getLocation() const { return m_location; }
208 const XMLCh* getResponseLocation() const { return m_resploc; }
209 const DOMElement* getElement() const { return m_root; }
212 const DOMElement* m_root;
213 const XMLCh* m_binding;
214 const XMLCh* m_location;
215 const XMLCh* m_resploc;
218 class IndexedEndpoint : public Endpoint, public virtual IIndexedEndpoint
221 IndexedEndpoint(const DOMElement* e) : Endpoint(e), m_index(XMLString::parseInt(e->getAttributeNS(NULL,SHIB_L(index)))) {}
222 unsigned short getIndex() const {return m_index;}
225 unsigned short m_index;
228 class EndpointManager : public IEndpointManager
231 EndpointManager() : m_soft(NULL), m_hard(NULL) {}
233 for (vector<const IEndpoint*>::iterator i=m_endpoints.begin(); i!=m_endpoints.end(); i++)
234 delete const_cast<IEndpoint*>(*i);
236 saml::Iterator<const IEndpoint*> getEndpoints() const {return m_endpoints;}
237 const IEndpoint* getDefaultEndpoint() const {
238 if (m_hard) return m_hard;
239 if (m_soft) return m_soft;
240 if (!m_endpoints.empty()) return *(m_endpoints.begin());
243 const IEndpoint* getEndpointByIndex(unsigned short index) const {
244 for (vector<const IEndpoint*>::const_iterator i=m_endpoints.begin(); i!=m_endpoints.end(); i++) {
245 const IIndexedEndpoint* temp=dynamic_cast<const IIndexedEndpoint*>(*i);
246 if (temp && index==temp->getIndex())
251 const IEndpoint* getEndpointByBinding(const XMLCh* binding) const {
252 for (vector<const IEndpoint*>::const_iterator i=m_endpoints.begin(); i!=m_endpoints.end(); i++)
253 if (!XMLString::compareString(binding,(*i)->getBinding()))
257 void add(IEndpoint* e) {
258 m_endpoints.push_back(e);
259 if (!m_hard && e->getElement()) {
260 const XMLCh* v=e->getElement()->getAttributeNS(NULL,SHIB_L(isDefault));
261 if (v && (*v==chDigit_1 || *v==chLatin_t)) // explicit default
263 else if ((!v || !*v) && !m_soft) // implicit default
266 else if (!m_hard && !m_soft) {
267 // No default yet, so this one qualifies as an implicit.
273 vector<const IEndpoint*> m_endpoints;
274 const IEndpoint* m_soft; // Soft default (not explicit)
275 const IEndpoint* m_hard; // Hard default (explicit)
278 class SSORole : public Role, public virtual ISSODescriptor
281 SSORole(const EntityDescriptor* provider, time_t validUntil, const DOMElement* e);
283 const IEndpointManager* getArtifactResolutionServiceManager() const {return &m_artifact;}
284 const IEndpointManager* getSingleLogoutServiceManager() const {return &m_logout;}
285 const IEndpointManager* getManageNameIDServiceManager() const {return &m_nameid;}
286 saml::Iterator<const XMLCh*> getNameIDFormats() const {return m_formats;}
289 EndpointManager m_artifact,m_logout,m_nameid;
290 vector<const XMLCh*> m_formats;
293 class ScopedRole : public virtual IScopedRoleDescriptor
296 ScopedRole(const DOMElement* e);
297 saml::Iterator<std::pair<const XMLCh*,bool> > getScopes() const {return m_scopes;}
300 vector<pair<const XMLCh*,bool> > m_scopes;
303 class IDPRole : public SSORole, public ScopedRole, public virtual IIDPSSODescriptor
306 IDPRole(const EntityDescriptor* provider, time_t validUntil, const DOMElement* e);
308 bool getWantAuthnRequestsSigned() const {return m_wantAuthnRequestsSigned;}
309 const IEndpointManager* getSingleSignOnServiceManager() const {return &m_sso;}
310 const IEndpointManager* getNameIDMappingServiceManager() const {return &m_mapping;}
311 const IEndpointManager* getAssertionIDRequestServiceManager() const {return &m_idreq;}
312 saml::Iterator<const XMLCh*> getAttributeProfiles() const {return m_attrprofs;}
313 saml::Iterator<const saml::SAMLAttribute*> getAttributes() const {return m_attrs;}
316 EndpointManager m_sso,m_mapping,m_idreq;
317 vector<const XMLCh*> m_attrprofs;
318 vector<const SAMLAttribute*> m_attrs;
319 bool m_wantAuthnRequestsSigned;
320 const XMLCh* m_sourceId;
321 friend class EntityDescriptor;
324 class AARole : public Role, public ScopedRole, public virtual IAttributeAuthorityDescriptor
327 AARole(const EntityDescriptor* provider, time_t validUntil, const DOMElement* e);
329 const IEndpointManager* getAttributeServiceManager() const {return &m_query;}
330 const IEndpointManager* getAssertionIDRequestServiceManager() const {return &m_idreq;}
331 saml::Iterator<const XMLCh*> getNameIDFormats() const {return m_formats;}
332 saml::Iterator<const XMLCh*> getAttributeProfiles() const {return m_attrprofs;}
333 saml::Iterator<const saml::SAMLAttribute*> getAttributes() const {return m_attrs;}
336 EndpointManager m_query,m_idreq;
337 vector<const XMLCh*> m_formats,m_attrprofs;
338 vector<const SAMLAttribute*> m_attrs;
341 class EntityDescriptor : public IEntityDescriptor
346 XMLMetadataImpl* wrapper,
347 time_t validUntil=LONG_MAX,
348 const IEntitiesDescriptor* parent=NULL
353 const XMLCh* getId() const {return m_id;}
354 bool isValid() const {return time(NULL) < m_validUntil;}
355 Iterator<const IRoleDescriptor*> getRoleDescriptors() const {return m_roles;}
356 const IIDPSSODescriptor* getIDPSSODescriptor(const XMLCh* protocol) const;
357 const ISPSSODescriptor* getSPSSODescriptor(const XMLCh* protocol) const {return NULL;}
358 const IAuthnAuthorityDescriptor* getAuthnAuthorityDescriptor(const XMLCh* protocol) const {return NULL;}
359 const IAttributeAuthorityDescriptor* getAttributeAuthorityDescriptor(const XMLCh* protocol) const;
360 const IPDPDescriptor* getPDPDescriptor(const XMLCh* protocol) const {return NULL;}
361 const IAffiliationDescriptor* getAffiliationDescriptor() const {return NULL;}
362 const IOrganization* getOrganization() const {return m_org;}
363 Iterator<const IContactPerson*> getContactPersons() const {return m_contacts;}
364 saml::Iterator<std::pair<const XMLCh*,const XMLCh*> > getAdditionalMetadataLocations() const {return m_locs;}
365 const IEntitiesDescriptor* getEntitiesDescriptor() const {return m_parent;}
366 const DOMElement* getElement() const {return m_root;}
369 const char* getErrorURL() const {return m_errorURL.get();}
370 time_t getValidUntil() const {return m_validUntil;}
372 const DOMElement* m_root;
373 const IEntitiesDescriptor* m_parent;
375 auto_ptr<char> m_errorURL;
376 IOrganization* m_org;
377 vector<const IContactPerson*> m_contacts;
378 vector<const IRoleDescriptor*> m_roles;
379 vector<pair<const XMLCh*,const XMLCh*> > m_locs;
383 class EntitiesDescriptor : public IEntitiesDescriptor
388 XMLMetadataImpl* wrapper,
389 time_t validUntil=LONG_MAX,
390 const IEntitiesDescriptor* parent=NULL
392 ~EntitiesDescriptor();
394 const XMLCh* getName() const {return m_name;}
395 bool isValid() const {return time(NULL) < m_validUntil;}
396 const IEntitiesDescriptor* getEntitiesDescriptor() const {return m_parent;}
397 saml::Iterator<const IEntitiesDescriptor*> getEntitiesDescriptors() const {return m_groups;}
398 saml::Iterator<const IEntityDescriptor*> getEntityDescriptors() const {return m_providers;}
399 const DOMElement* getElement() const {return m_root;}
402 const DOMElement* m_root;
403 const IEntitiesDescriptor* m_parent;
405 vector<const IEntitiesDescriptor*> m_groups;
406 vector<const IEntityDescriptor*> m_providers;
410 XMLMetadataImpl(const char* pathname) : ReloadableXMLFileImpl(pathname), m_rootProvider(NULL), m_rootGroup(NULL) { init(); }
411 XMLMetadataImpl(const DOMElement* e) : ReloadableXMLFileImpl(e), m_rootProvider(NULL), m_rootGroup(NULL) { init(); }
415 typedef multimap<string,const EntityDescriptor*> sitemap_t;
418 EntityDescriptor* m_rootProvider;
419 EntitiesDescriptor* m_rootGroup;
422 class XMLMetadata : public IMetadata, public ReloadableXMLFile
425 XMLMetadata(const DOMElement* e) : ReloadableXMLFile(e) {}
428 const IEntityDescriptor* lookup(const XMLCh* providerId) const;
429 const IEntityDescriptor* lookup(const saml::SAMLArtifact* artifact) const;
432 virtual ReloadableXMLFileImpl* newImplementation(const char* pathname, bool first=true) const;
433 virtual ReloadableXMLFileImpl* newImplementation(const DOMElement* e, bool first=true) const;
437 IPlugIn* XMLMetadataFactory(const DOMElement* e)
439 XMLMetadata* m=new XMLMetadata(e);
441 m->getImplementation();
450 ReloadableXMLFileImpl* XMLMetadata::newImplementation(const DOMElement* e, bool first) const
452 return new XMLMetadataImpl(e);
455 ReloadableXMLFileImpl* XMLMetadata::newImplementation(const char* pathname, bool first) const
457 return new XMLMetadataImpl(pathname);
460 XMLMetadataImpl::ContactPerson::ContactPerson(const DOMElement* e) : m_root(e)
462 const XMLCh* type=NULL;
464 // Old metadata or new?
465 if (saml::XML::isElementNamed(e,::XML::SHIB_NS,SHIB_L(Contact))) {
466 type=e->getAttributeNS(NULL,SHIB_L(Type));
467 m_surName=auto_ptr<char>(toUTF8(e->getAttributeNS(NULL,SHIB_L(Name))));
468 if (e->hasAttributeNS(NULL,SHIB_L(Email))) {
469 auto_ptr<char> temp(toUTF8(e->getAttributeNS(NULL,SHIB_L(Email))));
471 m_emails.push_back(temp.get());
474 else if (saml::XML::isElementNamed(e,::XML::SAML2META_NS,SHIB_L(ContactPerson))) {
475 type=e->getAttributeNS(NULL,SHIB_L(contactType));
477 e=saml::XML::getFirstChildElement(e);
479 if (saml::XML::isElementNamed(e,::XML::SAML2META_NS,SHIB_L(Company))) {
480 n=e->getFirstChild();
481 if (n) m_company=auto_ptr<char>(toUTF8(n->getNodeValue()));
483 else if (saml::XML::isElementNamed(e,::XML::SAML2META_NS,SHIB_L(GivenName))) {
484 n=e->getFirstChild();
485 if (n) m_givenName=auto_ptr<char>(toUTF8(n->getNodeValue()));
487 else if (saml::XML::isElementNamed(e,::XML::SAML2META_NS,SHIB_L(SurName))) {
488 n=e->getFirstChild();
489 if (n) m_surName=auto_ptr<char>(toUTF8(n->getNodeValue()));
491 else if (saml::XML::isElementNamed(e,::XML::SAML2META_NS,SHIB_L(EmailAddress))) {
492 n=e->getFirstChild();
494 auto_ptr<char> temp(toUTF8(n->getNodeValue()));
495 if (temp.get()) m_emails.push_back(temp.get());
498 else if (saml::XML::isElementNamed(e,::XML::SAML2META_NS,SHIB_L(TelephoneNumber))) {
499 n=e->getFirstChild();
501 auto_ptr<char> temp(toUTF8(n->getNodeValue()));
502 if (temp.get()) m_phones.push_back(temp.get());
505 e=saml::XML::getNextSiblingElement(e);
509 if (!XMLString::compareString(type,SHIB_L(technical)))
510 m_type=IContactPerson::technical;
511 else if (!XMLString::compareString(type,SHIB_L(support)))
512 m_type=IContactPerson::support;
513 else if (!XMLString::compareString(type,SHIB_L(administrative)))
514 m_type=IContactPerson::administrative;
515 else if (!XMLString::compareString(type,SHIB_L(billing)))
516 m_type=IContactPerson::billing;
517 else if (!XMLString::compareString(type,SHIB_L(other)))
518 m_type=IContactPerson::other;
521 XMLMetadataImpl::Organization::Organization(const DOMElement* e) : m_root(e)
524 e=saml::XML::getFirstChildElement(e);
526 if (saml::XML::isElementNamed(e,::XML::SAML2META_NS,SHIB_L(OrganizationName))) {
527 n=e->getFirstChild();
529 auto_ptr<char> name(toUTF8(n->getNodeValue()));
530 auto_ptr_char lang(e->getAttributeNS(saml::XML::XML_NS,L(lang)));
531 m_names[lang.get()]=name.get();
534 else if (saml::XML::isElementNamed(e,::XML::SAML2META_NS,SHIB_L(OrganizationDisplayName))) {
535 n=e->getFirstChild();
537 auto_ptr<char> display(toUTF8(n->getNodeValue()));
538 auto_ptr_char lang(e->getAttributeNS(saml::XML::XML_NS,L(lang)));
539 m_displays[lang.get()]=display.get();
542 else if (saml::XML::isElementNamed(e,::XML::SAML2META_NS,SHIB_L(OrganizationURL))) {
543 n=e->getFirstChild();
545 auto_ptr<char> url(toUTF8(n->getNodeValue()));
546 auto_ptr_char lang(e->getAttributeNS(saml::XML::XML_NS,L(lang)));
547 m_urls[lang.get()]=url.get();
550 e=saml::XML::getNextSiblingElement(e);
554 XMLMetadataImpl::EncryptionMethod::EncryptionMethod(const DOMElement* e) : m_root(e)
556 m_alg=e->getAttributeNS(NULL,SHIB_L(Algorithm));
557 e=saml::XML::getFirstChildElement(e);
559 if (saml::XML::isElementNamed(e,::XML::XMLENC_NS,SHIB_L(KeySize))) {
560 DOMNode* n=e->getFirstChild();
561 if (n) m_size=XMLString::parseInt(n->getNodeValue());
563 else if (saml::XML::isElementNamed(e,saml::XML::XMLSIG_NS,SHIB_L(DigestMethod))) {
564 DOMNode* n=e->getFirstChild();
565 if (n) m_digest=n->getNodeValue();
567 else if (saml::XML::isElementNamed(e,::XML::XMLENC_NS,SHIB_L(OAEParams))) {
568 DOMNode* n=e->getFirstChild();
569 if (n) m_params=n->getNodeValue();
571 e=saml::XML::getNextSiblingElement(e);
575 XMLMetadataImpl::KeyDescriptor::KeyDescriptor(const DOMElement* e) : m_root(e), m_use(unspecified), m_klist(NULL)
577 if (!XMLString::compareString(e->getAttributeNS(NULL,SHIB_L(use)),SHIB_L(encryption)))
579 else if (!XMLString::compareString(e->getAttributeNS(NULL,SHIB_L(use)),SHIB_L(signing)))
582 // Process ds:KeyInfo
583 e=saml::XML::getFirstChildElement(e);
585 // We let XMLSec hack through anything it can. This should evolve over time, or we can
586 // plug in our own KeyResolver later...
587 DOMElement* child=saml::XML::getFirstChildElement(e);
590 if (!m_klist.addXMLKeyInfo(child)) {
591 Category::getInstance(XMLPROVIDERS_LOGCAT".XMLMetadataImpl.KeyDescriptor").warn(
592 "skipped unsupported ds:KeyInfo child element");
595 catch (XSECCryptoException& xe) {
596 Category::getInstance(XMLPROVIDERS_LOGCAT".XMLMetadataImpl.KeyDescriptor").error(
597 "unable to process ds:KeyInfo child element: %s",xe.getMsg());
599 child=saml::XML::getNextSiblingElement(child);
602 // Check for encryption methods.
603 e=saml::XML::getNextSiblingElement(e);
604 while (e && saml::XML::isElementNamed(e,::XML::SAML2META_NS,SHIB_L(EncryptionMethod)))
605 m_methods.push_back(new EncryptionMethod(e));
608 XMLMetadataImpl::KeyDescriptor::~KeyDescriptor()
610 for (vector<const XENCEncryptionMethod*>::iterator i=m_methods.begin(); i!=m_methods.end(); i++)
611 delete const_cast<XENCEncryptionMethod*>(*i);
614 XMLMetadataImpl::Role::Role(const EntityDescriptor* provider, time_t validUntil, const DOMElement* e)
615 : m_provider(provider), m_errorURL(NULL), m_protocolEnumCopy(NULL), m_org(NULL), m_validUntil(validUntil), m_root(e)
617 // Check the root element namespace. If SAML2, assume it's the std schema.
618 if (e && !XMLString::compareString(e->getNamespaceURI(),::XML::SAML2META_NS)) {
620 if (e->hasAttributeNS(NULL,SHIB_L(validUntil))) {
621 SAMLDateTime exp(e->getAttributeNS(NULL,SHIB_L(validUntil)));
623 m_validUntil=min(m_validUntil,exp.getEpoch());
626 if (e->hasAttributeNS(NULL,SHIB_L(errorURL)))
627 m_errorURL=toUTF8(e->getAttributeNS(NULL,SHIB_L(errorURL)));
629 // Chop the protocol list into pieces...assume any whitespace can appear in between.
630 m_protocolEnumCopy=XMLString::replicate(e->getAttributeNS(NULL,SHIB_L(protocolSupportEnumeration)));
631 XMLCh* temp=m_protocolEnumCopy;
632 while (temp && *temp) {
634 while (*temp && !XMLChar1_1::isWhitespace(*temp)) temp++;
636 m_protocolEnum.push_back(start);
638 while (*temp && XMLChar1_1::isWhitespace(*temp)) temp++;
641 e=saml::XML::getFirstChildElement(m_root,::XML::SAML2META_NS,SHIB_L(KeyDescriptor));
643 m_keys.push_back(new KeyDescriptor(e));
644 e=saml::XML::getNextSiblingElement(e,::XML::SAML2META_NS,SHIB_L(KeyDescriptor));
647 e=saml::XML::getFirstChildElement(m_root,::XML::SAML2META_NS,SHIB_L(Organization));
649 m_org=new Organization(e);
651 e=saml::XML::getFirstChildElement(m_root,::XML::SAML2META_NS,SHIB_L(ContactPerson));
653 m_contacts.push_back(new ContactPerson(e));
654 e=saml::XML::getNextSiblingElement(e,::XML::SAML2META_NS,SHIB_L(ContactPerson));
659 XMLMetadataImpl::Role::~Role()
663 if (m_protocolEnumCopy) XMLString::release(&m_protocolEnumCopy);
664 for (vector<const IKeyDescriptor*>::iterator i=m_keys.begin(); i!=m_keys.end(); i++)
665 delete const_cast<IKeyDescriptor*>(*i);
666 for (vector<const IContactPerson*>::iterator j=m_contacts.begin(); j!=m_contacts.end(); j++)
667 delete const_cast<IContactPerson*>(*j);
670 bool XMLMetadataImpl::Role::hasSupport(const XMLCh* protocol) const
672 Iterator<const XMLCh*> i(m_protocolEnum);
673 while (i.hasNext()) {
674 if (!XMLString::compareString(protocol,i.next()))
680 XMLMetadataImpl::SSORole::SSORole(const EntityDescriptor* provider, time_t validUntil, const DOMElement* e)
681 : Role(provider,validUntil,e)
683 // Check the root element namespace. If SAML2, assume it's the std schema.
684 if (!XMLString::compareString(e->getNamespaceURI(),::XML::SAML2META_NS)) {
686 DOMNodeList* nlist=e->getElementsByTagNameNS(::XML::SAML2META_NS,SHIB_L(ArtifactResolutionService));
687 for (i=0; nlist && i<nlist->getLength(); i++)
688 m_artifact.add(new IndexedEndpoint(static_cast<DOMElement*>(nlist->item(i))));
690 nlist=e->getElementsByTagNameNS(::XML::SAML2META_NS,SHIB_L(SingleLogoutService));
691 for (i=0; nlist && i<nlist->getLength(); i++)
692 m_logout.add(new Endpoint(static_cast<DOMElement*>(nlist->item(i))));
694 nlist=e->getElementsByTagNameNS(::XML::SAML2META_NS,SHIB_L(ManageNameIDService));
695 for (i=0; nlist && i<nlist->getLength(); i++)
696 m_nameid.add(new Endpoint(static_cast<DOMElement*>(nlist->item(i))));
698 nlist=e->getElementsByTagNameNS(::XML::SAML2META_NS,SHIB_L(NameIDFormat));
699 for (i=0; nlist && i<nlist->getLength(); i++) {
700 DOMNode* n=nlist->item(i)->getFirstChild();
701 if (n) m_formats.push_back(n->getNodeValue());
705 // For old style, we just do SAML 1.1 compatibility with Shib handles.
706 m_protocolEnum.push_back(saml::XML::SAML11_PROTOCOL_ENUM);
707 m_formats.push_back(shibboleth::Constants::SHIB_NAMEID_FORMAT_URI);
711 XMLMetadataImpl::ScopedRole::ScopedRole(const DOMElement* e)
713 // Check the root element namespace. If SAML2, assume it's the std schema.
714 DOMNodeList* nlist=NULL;
715 if (!XMLString::compareString(e->getNamespaceURI(),::XML::SAML2META_NS)) {
716 e=saml::XML::getFirstChildElement(e,::XML::SAML2META_NS,SHIB_L(Extensions));
717 nlist=e->getElementsByTagNameNS(::XML::SHIBMETA_NS,SHIB_L(Domain));
720 nlist=e->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(Domain));
723 for (int i=0; nlist && i < nlist->getLength(); i++) {
724 const XMLCh* dom=(nlist->item(i)->hasChildNodes()) ? nlist->item(i)->getFirstChild()->getNodeValue() : NULL;
726 const XMLCh* regexp=static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIB_L(regexp));
728 pair<const XMLCh*,bool>(dom,(regexp && (*regexp==chLatin_t || *regexp==chDigit_1)))
734 XMLMetadataImpl::IDPRole::IDPRole(const EntityDescriptor* provider, time_t validUntil, const DOMElement* e)
735 : SSORole(provider,validUntil,e), ScopedRole(e), m_wantAuthnRequestsSigned(false), m_sourceId(NULL)
737 // Check the root element namespace. If SAML2, assume it's the std schema.
738 if (!XMLString::compareString(e->getNamespaceURI(),::XML::SAML2META_NS)) {
739 const XMLCh* flag=e->getAttributeNS(NULL,SHIB_L(WantAuthnRequestsSigned));
740 m_wantAuthnRequestsSigned=(flag && (*flag==chDigit_1 || *flag==chLatin_t));
742 // Check for SourceID extension.
743 DOMElement* ext=saml::XML::getFirstChildElement(e,::XML::SAML2META_NS,SHIB_L(Extensions));
745 ext=saml::XML::getFirstChildElement(e,saml::XML::SAML_ARTIFACT_SOURCEID,SHIB_L(SourceID));
746 if (ext && ext->hasChildNodes())
747 m_sourceId=ext->getFirstChild()->getNodeValue();
751 DOMNodeList* nlist=e->getElementsByTagNameNS(::XML::SAML2META_NS,SHIB_L(SingleSignOnService));
752 for (i=0; nlist && i<nlist->getLength(); i++)
753 m_sso.add(new Endpoint(static_cast<DOMElement*>(nlist->item(i))));
755 nlist=e->getElementsByTagNameNS(::XML::SAML2META_NS,SHIB_L(NameIDMappingService));
756 for (i=0; nlist && i<nlist->getLength(); i++)
757 m_mapping.add(new Endpoint(static_cast<DOMElement*>(nlist->item(i))));
759 nlist=e->getElementsByTagNameNS(::XML::SAML2META_NS,SHIB_L(AssertionIDRequestService));
760 for (i=0; nlist && i<nlist->getLength(); i++)
761 m_idreq.add(new Endpoint(static_cast<DOMElement*>(nlist->item(i))));
763 nlist=e->getElementsByTagNameNS(::XML::SAML2META_NS,SHIB_L(AttributeProfile));
764 for (i=0; nlist && i<nlist->getLength(); i++) {
765 DOMNode* n=nlist->item(i)->getFirstChild();
766 if (n) m_attrprofs.push_back(n->getNodeValue());
769 nlist=e->getElementsByTagNameNS(::XML::SAML2ASSERT_NS,L(Attribute));
770 for (i=0; nlist && i<nlist->getLength(); i++) {
771 // For now, we need to convert these to plain SAML 1.1 attributes.
772 DOMElement* src=static_cast<DOMElement*>(nlist->item(i));
773 DOMElement* copy=e->getOwnerDocument()->createElementNS(saml::XML::SAML_NS,L(Attribute));
774 copy->setAttributeNS(NULL,L(AttributeName),src->getAttributeNS(NULL,SHIB_L(Name)));
775 copy->setAttributeNS(NULL,L(AttributeNamespace),src->getAttributeNS(NULL,SHIB_L(NameFormat)));
776 src=saml::XML::getFirstChildElement(src,::XML::SAML2ASSERT_NS,L(AttributeValue));
778 src=saml::XML::getNextSiblingElement(src,::XML::SAML2ASSERT_NS,L(AttributeValue));
779 DOMElement* val=e->getOwnerDocument()->createElementNS(saml::XML::SAML_NS,L(AttributeValue));
780 DOMNamedNodeMap* attrs = src->getAttributes();
781 for (int j=0; j<attrs->getLength(); j++)
782 val->setAttributeNodeNS(static_cast<DOMAttr*>(e->getOwnerDocument()->importNode(attrs->item(j),true)));
783 while (src->hasChildNodes())
784 val->appendChild(src->getFirstChild());
785 copy->appendChild(val);
787 m_attrs.push_back(SAMLAttribute::getInstance(copy));
791 m_attrprofs.push_back(Constants::SHIB_ATTRIBUTE_NAMESPACE_URI);
793 DOMNodeList* nlist=e->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(HandleService));
794 for (i=0; nlist && i<nlist->getLength(); i++) {
795 // Manufacture an endpoint for the "Shib" binding.
797 new Endpoint(Constants::SHIB_AUTHNREQUEST_PROFILE_URI,static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIB_L(Location)))
800 // We're going to "mock up" a KeyDescriptor that contains the specified Name as a ds:KeyName.
801 DOMElement* kd=e->getOwnerDocument()->createElementNS(::XML::SAML2META_NS,SHIB_L(KeyDescriptor));
802 DOMElement* ki=e->getOwnerDocument()->createElementNS(saml::XML::XMLSIG_NS,L(KeyInfo));
803 DOMElement* kn=e->getOwnerDocument()->createElementNS(saml::XML::XMLSIG_NS,SHIB_L(KeyName));
805 e->getOwnerDocument()->createTextNode(
806 static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIB_L(Name))
811 kd->setAttributeNS(NULL,SHIB_L(use),SHIB_L(signing));
812 m_keys.push_back(new KeyDescriptor(kd));
817 XMLMetadataImpl::IDPRole::~IDPRole()
819 for (vector<const SAMLAttribute*>::iterator i=m_attrs.begin(); i!=m_attrs.end(); i++)
820 delete const_cast<SAMLAttribute*>(*i);
823 XMLMetadataImpl::AARole::AARole(const EntityDescriptor* provider, time_t validUntil, const DOMElement* e)
824 : Role(provider,validUntil,e), ScopedRole(e)
826 // Check the root element namespace. If SAML2, assume it's the std schema.
827 if (!XMLString::compareString(e->getNamespaceURI(),::XML::SAML2META_NS)) {
829 DOMNodeList* nlist=e->getElementsByTagNameNS(::XML::SAML2META_NS,SHIB_L(AttributeService));
830 for (i=0; nlist && i<nlist->getLength(); i++)
831 m_query.add(new Endpoint(static_cast<DOMElement*>(nlist->item(i))));
833 nlist=e->getElementsByTagNameNS(::XML::SAML2META_NS,SHIB_L(AssertionIDRequestService));
834 for (i=0; nlist && i<nlist->getLength(); i++)
835 m_idreq.add(new Endpoint(static_cast<DOMElement*>(nlist->item(i))));
837 nlist=e->getElementsByTagNameNS(::XML::SAML2META_NS,SHIB_L(NameIDFormat));
838 for (i=0; nlist && i<nlist->getLength(); i++) {
839 DOMNode* n=nlist->item(i)->getFirstChild();
840 if (n) m_formats.push_back(n->getNodeValue());
843 nlist=e->getElementsByTagNameNS(::XML::SAML2META_NS,SHIB_L(AttributeProfile));
844 for (i=0; nlist && i<nlist->getLength(); i++) {
845 DOMNode* n=nlist->item(i)->getFirstChild();
846 if (n) m_attrprofs.push_back(n->getNodeValue());
849 nlist=e->getElementsByTagNameNS(::XML::SAML2ASSERT_NS,L(Attribute));
850 for (i=0; nlist && i<nlist->getLength(); i++) {
851 // For now, we need to convert these to plain SAML 1.1 attributes.
852 DOMElement* src=static_cast<DOMElement*>(nlist->item(i));
853 DOMElement* copy=e->getOwnerDocument()->createElementNS(saml::XML::SAML_NS,L(Attribute));
854 copy->setAttributeNS(NULL,L(AttributeName),src->getAttributeNS(NULL,SHIB_L(Name)));
855 copy->setAttributeNS(NULL,L(AttributeNamespace),src->getAttributeNS(NULL,SHIB_L(NameFormat)));
856 src=saml::XML::getFirstChildElement(src,::XML::SAML2ASSERT_NS,L(AttributeValue));
858 src=saml::XML::getNextSiblingElement(src,::XML::SAML2ASSERT_NS,L(AttributeValue));
859 DOMElement* val=e->getOwnerDocument()->createElementNS(saml::XML::SAML_NS,L(AttributeValue));
860 DOMNamedNodeMap* attrs = src->getAttributes();
861 for (int j=0; j<attrs->getLength(); j++)
862 val->setAttributeNodeNS(static_cast<DOMAttr*>(e->getOwnerDocument()->importNode(attrs->item(j),true)));
863 while (src->hasChildNodes())
864 val->appendChild(src->getFirstChild());
865 copy->appendChild(val);
867 m_attrs.push_back(SAMLAttribute::getInstance(copy));
871 // For old style, we just do SAML 1.1 compatibility with Shib handles.
872 m_protocolEnum.push_back(saml::XML::SAML11_PROTOCOL_ENUM);
873 m_formats.push_back(Constants::SHIB_NAMEID_FORMAT_URI);
874 m_attrprofs.push_back(Constants::SHIB_ATTRIBUTE_NAMESPACE_URI);
876 DOMNodeList* nlist=e->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(AttributeAuthority));
877 for (i=0; nlist && i<nlist->getLength(); i++) {
878 // Manufacture an endpoint for the SOAP binding.
882 static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIB_L(Location))
886 // We're going to "mock up" a KeyDescriptor that contains the specified Name as a ds:KeyName.
887 DOMElement* kd=e->getOwnerDocument()->createElementNS(::XML::SAML2META_NS,SHIB_L(KeyDescriptor));
888 DOMElement* ki=e->getOwnerDocument()->createElementNS(saml::XML::XMLSIG_NS,L(KeyInfo));
889 DOMElement* kn=e->getOwnerDocument()->createElementNS(saml::XML::XMLSIG_NS,SHIB_L(KeyName));
891 e->getOwnerDocument()->createTextNode(
892 static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,SHIB_L(Name))
897 m_keys.push_back(new KeyDescriptor(kd));
902 XMLMetadataImpl::AARole::~AARole()
904 for (vector<const SAMLAttribute*>::iterator i=m_attrs.begin(); i!=m_attrs.end(); i++)
905 delete const_cast<SAMLAttribute*>(*i);
908 XMLMetadataImpl::EntityDescriptor::EntityDescriptor(
909 const DOMElement* e, XMLMetadataImpl* wrapper, time_t validUntil, const IEntitiesDescriptor* parent
910 ) : m_root(e), m_parent(parent), m_org(NULL), m_validUntil(validUntil)
912 // Check the root element namespace. If SAML2, assume it's the std schema.
913 if (!XMLString::compareString(e->getNamespaceURI(),::XML::SAML2META_NS)) {
914 m_id=e->getAttributeNS(NULL,SHIB_L(entityID));
916 if (e->hasAttributeNS(NULL,SHIB_L(validUntil))) {
917 SAMLDateTime exp(e->getAttributeNS(NULL,SHIB_L(validUntil)));
919 m_validUntil=min(validUntil,exp.getEpoch());
922 DOMElement* child=saml::XML::getFirstChildElement(e);
924 // Process the various kinds of children that we care about...
925 if (saml::XML::isElementNamed(child,::XML::SAML2META_NS,SHIB_L(ContactPerson))) {
926 m_contacts.push_back(new ContactPerson(child));
928 else if (saml::XML::isElementNamed(child,::XML::SAML2META_NS,SHIB_L(Organization))) {
929 m_org=new Organization(child);
931 else if (saml::XML::isElementNamed(child,::XML::SAML2META_NS,SHIB_L(AdditionalMetadataLocation))) {
932 DOMNode* loc=child->getFirstChild();
935 pair<const XMLCh*,const XMLCh*>(child->getAttributeNS(NULL,::XML::Literals::_namespace),loc->getNodeValue())
938 else if (saml::XML::isElementNamed(child,::XML::SAML2META_NS,SHIB_L(IDPSSODescriptor))) {
939 m_roles.push_back(new IDPRole(this,m_validUntil,child));
941 else if (saml::XML::isElementNamed(child,::XML::SAML2META_NS,SHIB_L(AttributeAuthorityDescriptor))) {
942 m_roles.push_back(new AARole(this,m_validUntil,child));
944 child = saml::XML::getNextSiblingElement(child);
948 m_id=e->getAttributeNS(NULL,SHIB_L(Name));
949 m_errorURL=auto_ptr<char>(toUTF8(e->getAttributeNS(NULL,SHIB_L(ErrorURL))));
951 bool idp=false,aa=false; // only want to build a role once
952 DOMElement* child=saml::XML::getFirstChildElement(e);
954 // Process the various kinds of OriginSite children that we care about...
955 if (saml::XML::isElementNamed(child,::XML::SHIB_NS,SHIB_L(Contact))) {
956 m_contacts.push_back(new ContactPerson(child));
958 else if (saml::XML::isElementNamed(child,::XML::SHIB_NS,SHIB_L(HandleService)) && !idp) {
959 // Create the IDP role if needed.
960 m_roles.push_back(new IDPRole(this, m_validUntil, e));
963 else if (saml::XML::isElementNamed(child,::XML::SHIB_NS,SHIB_L(AttributeAuthority)) && !aa) {
964 // Create the AA role if needed.
965 m_roles.push_back(new AARole(this, m_validUntil, e));
968 child = saml::XML::getNextSiblingElement(child);
972 auto_ptr_char id(m_id);
973 wrapper->m_sites.insert(pair<string,const EntityDescriptor*>(id.get(),this));
975 // Look for an IdP role, and register the artifact source ID and endpoints.
976 const IDPRole* idp=NULL;
977 for (vector<const IRoleDescriptor*>::const_iterator r=m_roles.begin(); r!=m_roles.end(); r++) {
978 if (idp=dynamic_cast<const IDPRole*>(*r)) {
979 if (idp->m_sourceId) {
980 auto_ptr_char sourceid(idp->m_sourceId);
981 wrapper->m_sources.insert(pair<string,const EntityDescriptor*>(sourceid.get(),this));
984 string sourceid=SAMLArtifact::toHex(SAMLArtifactType0001::generateSourceId(id.get()));
985 wrapper->m_sources.insert(pair<string,const EntityDescriptor*>(sourceid,this));
987 Iterator<const IEndpoint*> locs=idp->getArtifactResolutionServiceManager()->getEndpoints();
988 while (locs.hasNext()) {
989 auto_ptr_char loc(locs.next()->getLocation());
990 wrapper->m_sources.insert(pair<string,const EntityDescriptor*>(loc.get(),this));
996 const IIDPSSODescriptor* XMLMetadataImpl::EntityDescriptor::getIDPSSODescriptor(const XMLCh* protocol) const
998 const IIDPSSODescriptor* ret=NULL;
999 for (vector<const IRoleDescriptor*>::const_iterator i=m_roles.begin(); i!=m_roles.end(); i++) {
1000 if ((*i)->hasSupport(protocol) && (*i)->isValid() && (ret=dynamic_cast<const IIDPSSODescriptor*>(*i)))
1006 const IAttributeAuthorityDescriptor* XMLMetadataImpl::EntityDescriptor::getAttributeAuthorityDescriptor(const XMLCh* protocol) const
1008 const IAttributeAuthorityDescriptor* ret=NULL;
1009 for (vector<const IRoleDescriptor*>::const_iterator i=m_roles.begin(); i!=m_roles.end(); i++) {
1010 if ((*i)->hasSupport(protocol) && (*i)->isValid() && (ret=dynamic_cast<const IAttributeAuthorityDescriptor*>(*i)))
1016 XMLMetadataImpl::EntityDescriptor::~EntityDescriptor()
1019 for (vector<const IContactPerson*>::iterator i=m_contacts.begin(); i!=m_contacts.end(); i++)
1020 delete const_cast<IContactPerson*>(*i);
1021 for (vector<const IRoleDescriptor*>::iterator j=m_roles.begin(); j!=m_roles.end(); j++)
1022 delete const_cast<IRoleDescriptor*>(*j);
1025 XMLMetadataImpl::EntitiesDescriptor::EntitiesDescriptor(
1026 const DOMElement* e, XMLMetadataImpl* wrapper, time_t validUntil, const IEntitiesDescriptor* parent
1027 ) : m_root(e), m_name(e->getAttributeNS(NULL,SHIB_L(Name))), m_parent(parent), m_validUntil(validUntil)
1029 // Check the root element namespace. If SAML2, assume it's the std schema.
1030 if (!XMLString::compareString(e->getNamespaceURI(),::XML::SAML2META_NS)) {
1032 if (e->hasAttributeNS(NULL,SHIB_L(validUntil))) {
1033 SAMLDateTime exp(e->getAttributeNS(NULL,SHIB_L(validUntil)));
1034 exp.parseDateTime();
1035 m_validUntil=min(validUntil,exp.getEpoch());
1038 e=saml::XML::getFirstChildElement(e);
1040 if (saml::XML::isElementNamed(e,::XML::SAML2META_NS,SHIB_L(EntitiesDescriptor)))
1041 m_groups.push_back(new EntitiesDescriptor(e,wrapper,m_validUntil,this));
1042 else if (saml::XML::isElementNamed(e,::XML::SAML2META_NS,SHIB_L(EntityDescriptor)))
1043 m_providers.push_back(new EntityDescriptor(e,wrapper,m_validUntil,this));
1044 e=saml::XML::getNextSiblingElement(e);
1048 e=saml::XML::getFirstChildElement(e);
1050 if (saml::XML::isElementNamed(e,::XML::SHIB_NS,SHIB_L(SiteGroup)))
1051 m_groups.push_back(new EntitiesDescriptor(e,wrapper,m_validUntil,this));
1052 else if (saml::XML::isElementNamed(e,::XML::SHIB_NS,SHIB_L(OriginSite)))
1053 m_providers.push_back(new EntityDescriptor(e,wrapper,m_validUntil,this));
1054 e=saml::XML::getNextSiblingElement(e);
1059 XMLMetadataImpl::EntitiesDescriptor::~EntitiesDescriptor()
1061 for (vector<const IEntityDescriptor*>::iterator i=m_providers.begin(); i!=m_providers.end(); i++)
1062 delete const_cast<IEntityDescriptor*>(*i);
1063 for (vector<const IEntitiesDescriptor*>::iterator j=m_groups.begin(); j!=m_groups.end(); j++)
1064 delete const_cast<IEntitiesDescriptor*>(*j);
1067 void XMLMetadataImpl::init()
1069 NDC ndc("XMLMetadataImpl");
1070 Category& log=Category::getInstance(XMLPROVIDERS_LOGCAT".XMLMetadataImpl");
1074 if (saml::XML::isElementNamed(m_root,::XML::SAML2META_NS,SHIB_L(EntitiesDescriptor)))
1075 m_rootGroup=new EntitiesDescriptor(m_root,this);
1076 else if (saml::XML::isElementNamed(m_root,::XML::SAML2META_NS,SHIB_L(EntityDescriptor)))
1077 m_rootProvider=new EntityDescriptor(m_root,this);
1078 else if (saml::XML::isElementNamed(m_root,::XML::SHIB_NS,SHIB_L(SiteGroup)))
1079 m_rootGroup=new EntitiesDescriptor(m_root,this);
1080 else if (saml::XML::isElementNamed(m_root,::XML::SHIB_NS,SHIB_L(OriginSite)))
1081 m_rootProvider=new EntityDescriptor(m_root,this);
1083 log.error("Construction requires a valid SAML metadata file");
1084 throw MetadataException("Construction requires a valid SAML metadata file");
1087 catch (SAMLException& e)
1089 log.errorStream() << "Error while parsing SAML metadata: " << e.what() << CategoryStream::ENDLINE;
1090 this->~XMLMetadataImpl();
1095 log.error("Unexpected error while parsing SAML metadata");
1096 this->~XMLMetadataImpl();
1101 XMLMetadataImpl::~XMLMetadataImpl()
1104 delete m_rootProvider;
1107 const IEntityDescriptor* XMLMetadata::lookup(const XMLCh* providerId) const
1109 XMLMetadataImpl* impl=dynamic_cast<XMLMetadataImpl*>(getImplementation());
1110 auto_ptr_char temp(providerId);
1111 pair<XMLMetadataImpl::sitemap_t::const_iterator,XMLMetadataImpl::sitemap_t::const_iterator> range=
1112 impl->m_sites.equal_range(temp.get());
1114 time_t now=time(NULL);
1115 for (XMLMetadataImpl::sitemap_t::const_iterator i=range.first; i!=range.second; i++)
1116 if (now < i->second->getValidUntil())
1121 const IEntityDescriptor* XMLMetadata::lookup(const SAMLArtifact* artifact) const
1123 time_t now=time(NULL);
1124 XMLMetadataImpl* impl=dynamic_cast<XMLMetadataImpl*>(getImplementation());
1125 pair<XMLMetadataImpl::sitemap_t::const_iterator,XMLMetadataImpl::sitemap_t::const_iterator> range;
1127 // Depends on type of artifact.
1128 const SAMLArtifactType0001* type1=dynamic_cast<const SAMLArtifactType0001*>(artifact);
1130 range=impl->m_sources.equal_range(type1->getSourceID());
1133 const SAMLArtifactType0002* type2=dynamic_cast<const SAMLArtifactType0002*>(artifact);
1135 range=impl->m_sources.equal_range(type2->getSourceLocation());
1140 for (XMLMetadataImpl::sitemap_t::const_iterator i=range.first; i!=range.second; i++)
1141 if (now < i->second->getValidUntil())