972a41f5cf3181da2fcb646fecd8ad0c94fd2d25
[shibboleth/sp.git] / shibsp / attribute / resolver / impl / XMLAttributeExtractor.cpp
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * XMLAttributeExtractor.cpp
19  * 
20  * AttributeExtractor based on an XML mapping file.
21  */
22
23 #include "internal.h"
24 #include "Application.h"
25 #include "ServiceProvider.h"
26 #include "attribute/AttributeDecoder.h"
27 #include "attribute/resolver/AttributeExtractor.h"
28 #include "util/SPConstants.h"
29
30 #include <saml/saml1/core/Assertions.h>
31 #include <saml/saml2/core/Assertions.h>
32 #include <saml/saml2/metadata/MetadataCredentialCriteria.h>
33 #include <xmltooling/util/NDC.h>
34 #include <xmltooling/util/ReloadableXMLFile.h>
35 #include <xmltooling/util/XMLHelper.h>
36 #include <xercesc/util/XMLUniDefs.hpp>
37
38 using namespace shibsp;
39 using namespace opensaml::saml2md;
40 using namespace opensaml;
41 using namespace xmltooling;
42 using namespace std;
43 using saml1::NameIdentifier;
44 using saml2::NameID;
45 using saml2::EncryptedAttribute;
46
47 namespace shibsp {
48
49 #if defined (_MSC_VER)
50     #pragma warning( push )
51     #pragma warning( disable : 4250 )
52 #endif
53
54     class XMLExtractorImpl
55     {
56     public:
57         XMLExtractorImpl(const DOMElement* e, Category& log);
58         ~XMLExtractorImpl() {
59             for (attrmap_t::iterator i = m_attrMap.begin(); i!=m_attrMap.end(); ++i)
60                 delete i->second.first;
61             if (m_document)
62                 m_document->release();
63         }
64
65         void setDocument(DOMDocument* doc) {
66             m_document = doc;
67         }
68
69         void extractAttributes(
70             const Application& application, const char* assertingParty, const NameIdentifier& nameid, vector<Attribute*>& attributes
71             ) const;
72         void extractAttributes(
73             const Application& application, const char* assertingParty, const NameID& nameid, vector<Attribute*>& attributes
74             ) const;
75         void extractAttributes(
76             const Application& application, const char* assertingParty, const saml1::Attribute& attr, vector<Attribute*>& attributes
77             ) const;
78         void extractAttributes(
79             const Application& application, const char* assertingParty, const saml2::Attribute& attr, vector<Attribute*>& attributes
80             ) const;
81         void extractAttributes(
82             const Application& application, const char* assertingParty, const Extensions& ext, vector<Attribute*>& attributes
83             ) const;
84
85         void getAttributeIds(vector<string>& attributes) const {
86             attributes.insert(attributes.end(), m_attributeIds.begin(), m_attributeIds.end());
87         }
88
89     private:
90         Category& m_log;
91         DOMDocument* m_document;
92 #ifdef HAVE_GOOD_STL
93         typedef map< pair<xstring,xstring>,pair< AttributeDecoder*,vector<string> > > attrmap_t;
94 #else
95         typedef map< pair<string,string>,pair< AttributeDecoder*,vector<string> > > attrmap_t;
96 #endif
97         attrmap_t m_attrMap;
98         vector<string> m_attributeIds;
99     };
100     
101     class XMLExtractor : public AttributeExtractor, public ReloadableXMLFile
102     {
103     public:
104         XMLExtractor(const DOMElement* e) : ReloadableXMLFile(e, Category::getInstance(SHIBSP_LOGCAT".AttributeExtractor")), m_impl(NULL) {
105             load();
106         }
107         ~XMLExtractor() {
108             delete m_impl;
109         }
110         
111         void extractAttributes(
112             const Application& application, const RoleDescriptor* issuer, const XMLObject& xmlObject, vector<Attribute*>& attributes
113             ) const;
114
115         void getAttributeIds(std::vector<std::string>& attributes) const {
116             if (m_impl)
117                 m_impl->getAttributeIds(attributes);
118         }
119
120     protected:
121         pair<bool,DOMElement*> load();
122
123     private:
124         XMLExtractorImpl* m_impl;
125     };
126
127 #if defined (_MSC_VER)
128     #pragma warning( pop )
129 #endif
130
131     AttributeExtractor* SHIBSP_DLLLOCAL XMLAttributeExtractorFactory(const DOMElement* const & e)
132     {
133         return new XMLExtractor(e);
134     }
135     
136     static const XMLCh _AttributeDecoder[] =    UNICODE_LITERAL_16(A,t,t,r,i,b,u,t,e,D,e,c,o,d,e,r);
137     static const XMLCh Attributes[] =           UNICODE_LITERAL_10(A,t,t,r,i,b,u,t,e,s);
138     static const XMLCh _id[] =                  UNICODE_LITERAL_2(i,d);
139     static const XMLCh _aliases[] =             UNICODE_LITERAL_7(a,l,i,a,s,e,s);
140     static const XMLCh _name[] =                UNICODE_LITERAL_4(n,a,m,e);
141     static const XMLCh nameFormat[] =           UNICODE_LITERAL_10(n,a,m,e,F,o,r,m,a,t);
142 };
143
144 void SHIBSP_API shibsp::registerAttributeExtractors()
145 {
146     SPConfig::getConfig().AttributeExtractorManager.registerFactory(XML_ATTRIBUTE_EXTRACTOR, XMLAttributeExtractorFactory);
147 }
148
149 XMLExtractorImpl::XMLExtractorImpl(const DOMElement* e, Category& log) : m_log(log), m_document(NULL)
150 {
151 #ifdef _DEBUG
152     xmltooling::NDC ndc("XMLExtractorImpl");
153 #endif
154     
155     if (!XMLHelper::isNodeNamed(e, shibspconstants::SHIB2ATTRIBUTEMAP_NS, Attributes))
156         throw ConfigurationException("XML AttributeExtractor requires am:Attributes at root of configuration.");
157
158     DOMElement* child = XMLHelper::getFirstChildElement(e, shibspconstants::SHIB2ATTRIBUTEMAP_NS, saml1::Attribute::LOCAL_NAME);
159     while (child) {
160         // Check for missing name or id.
161         const XMLCh* name = child->getAttributeNS(NULL, _name);
162         if (!name || !*name) {
163             m_log.warn("skipping Attribute with no name");
164             child = XMLHelper::getNextSiblingElement(child, shibspconstants::SHIB2ATTRIBUTEMAP_NS, saml1::Attribute::LOCAL_NAME);
165             continue;
166         }
167
168         auto_ptr_char id(child->getAttributeNS(NULL, _id));
169         if (!id.get() || !*id.get()) {
170             m_log.warn("skipping Attribute with no id");
171             child = XMLHelper::getNextSiblingElement(child, shibspconstants::SHIB2ATTRIBUTEMAP_NS, saml1::Attribute::LOCAL_NAME);
172             continue;
173         }
174         else if (!strcmp(id.get(), "REMOTE_USER")) {
175             m_log.warn("skipping Attribute, id of REMOTE_USER is a reserved name");
176             child = XMLHelper::getNextSiblingElement(child, shibspconstants::SHIB2ATTRIBUTEMAP_NS, saml1::Attribute::LOCAL_NAME);
177             continue;
178         }
179
180         AttributeDecoder* decoder=NULL;
181         try {
182             DOMElement* dchild = XMLHelper::getFirstChildElement(child, shibspconstants::SHIB2ATTRIBUTEMAP_NS, _AttributeDecoder);
183             if (dchild) {
184                 auto_ptr<QName> q(XMLHelper::getXSIType(dchild));
185                 if (q.get())
186                     decoder = SPConfig::getConfig().AttributeDecoderManager.newPlugin(*q.get(), dchild);
187             }
188             if (!decoder)
189                 decoder = SPConfig::getConfig().AttributeDecoderManager.newPlugin(StringAttributeDecoderType, NULL);
190         }
191         catch (exception& ex) {
192             m_log.error("skipping Attribute (%s), error building AttributeDecoder: %s", id.get(), ex.what());
193         }
194
195         if (!decoder) {
196             child = XMLHelper::getNextSiblingElement(child, shibspconstants::SHIB2ATTRIBUTEMAP_NS, saml1::Attribute::LOCAL_NAME);
197             continue;
198         }
199
200         // Empty NameFormat implies the usual Shib URI naming defaults.
201         const XMLCh* format = child->getAttributeNS(NULL, nameFormat);
202         if (!format || XMLString::equals(format, shibspconstants::SHIB1_ATTRIBUTE_NAMESPACE_URI) ||
203                 XMLString::equals(format, saml2::Attribute::URI_REFERENCE))
204             format = &chNull;  // ignore default Format/Namespace values
205
206         // Fetch/create the map entry and see if it's a duplicate rule.
207 #ifdef HAVE_GOOD_STL
208         pair< AttributeDecoder*,vector<string> >& decl = m_attrMap[pair<xstring,xstring>(name,format)];
209 #else
210         auto_ptr_char n(name);
211         auto_ptr_char f(format);
212         pair< AttributeDecoder*,vector<string> >& decl = m_attrMap[pair<string,string>(n.get(),f.get())];
213 #endif
214         if (decl.first) {
215             m_log.warn("skipping duplicate Attribute mapping (same name and nameFormat)");
216             delete decoder;
217             child = XMLHelper::getNextSiblingElement(child, shibspconstants::SHIB2ATTRIBUTEMAP_NS, saml1::Attribute::LOCAL_NAME);
218             continue;
219         }
220
221         if (m_log.isInfoEnabled()) {
222 #ifdef HAVE_GOOD_STL
223             auto_ptr_char n(name);
224             auto_ptr_char f(format);
225 #endif
226             m_log.info("creating mapping for Attribute %s%s%s", n.get(), *f.get() ? ", Format/Namespace:" : "", f.get());
227         }
228         
229         decl.first = decoder;
230         decl.second.push_back(id.get());
231         m_attributeIds.push_back(id.get());
232
233         name = child->getAttributeNS(NULL, _aliases);
234         if (name && *name) {
235             auto_ptr_char aliases(name);
236             char* pos;
237             char* start = const_cast<char*>(aliases.get());
238             while (start && *start) {
239                 while (*start && isspace(*start))
240                     start++;
241                 if (!*start)
242                     break;
243                 pos = strchr(start,' ');
244                 if (pos)
245                     *pos=0;
246                 if (strcmp(start, "REMOTE_USER")) {
247                     decl.second.push_back(start);
248                     m_attributeIds.push_back(start);
249                 }
250                 else {
251                     m_log.warn("skipping alias, REMOTE_USER is a reserved name");
252                 }
253                 start = pos ? pos+1 : NULL;
254             }
255         }
256         
257         child = XMLHelper::getNextSiblingElement(child, shibspconstants::SHIB2ATTRIBUTEMAP_NS, saml1::Attribute::LOCAL_NAME);
258     }
259 }
260
261 void XMLExtractorImpl::extractAttributes(
262     const Application& application, const char* assertingParty, const NameIdentifier& nameid, vector<Attribute*>& attributes
263     ) const
264 {
265 #ifdef HAVE_GOOD_STL
266     map< pair<xstring,xstring>,pair< AttributeDecoder*,vector<string> > >::const_iterator rule;
267 #else
268     map< pair<string,string>,pair< AttributeDecoder*,vector<string> > >::const_iterator rule;
269 #endif
270
271     const XMLCh* format = nameid.getFormat();
272     if (!format || !*format)
273         format = NameIdentifier::UNSPECIFIED;
274 #ifdef HAVE_GOOD_STL
275     if ((rule=m_attrMap.find(pair<xstring,xstring>(format,xstring()))) != m_attrMap.end()) {
276 #else
277     auto_ptr_char temp(format);
278     if ((rule=m_attrMap.find(pair<string,string>(temp.get(),string()))) != m_attrMap.end()) {
279 #endif
280         Attribute* a = rule->second.first->decode(rule->second.second, &nameid, assertingParty, application.getString("entityID").second);
281         if (a)
282             attributes.push_back(a);
283     }
284     else if (m_log.isDebugEnabled()) {
285 #ifdef HAVE_GOOD_STL
286         auto_ptr_char temp(format);
287 #endif
288         m_log.debug("skipping unmapped NameIdentifier with format (%s)", temp.get());
289     }
290 }
291
292 void XMLExtractorImpl::extractAttributes(
293     const Application& application, const char* assertingParty, const NameID& nameid, vector<Attribute*>& attributes
294     ) const
295 {
296 #ifdef HAVE_GOOD_STL
297     map< pair<xstring,xstring>,pair< AttributeDecoder*,vector<string> > >::const_iterator rule;
298 #else
299     map< pair<string,string>,pair< AttributeDecoder*,vector<string> > >::const_iterator rule;
300 #endif
301
302     const XMLCh* format = nameid.getFormat();
303     if (!format || !*format)
304         format = NameID::UNSPECIFIED;
305 #ifdef HAVE_GOOD_STL
306     if ((rule=m_attrMap.find(pair<xstring,xstring>(format,xstring()))) != m_attrMap.end()) {
307 #else
308     auto_ptr_char temp(format);
309     if ((rule=m_attrMap.find(pair<string,string>(temp.get(),string()))) != m_attrMap.end()) {
310 #endif
311         Attribute* a = rule->second.first->decode(rule->second.second, &nameid, assertingParty, application.getString("entityID").second);
312         if (a)
313             attributes.push_back(a);
314     }
315     else if (m_log.isDebugEnabled()) {
316 #ifdef HAVE_GOOD_STL
317         auto_ptr_char temp(format);
318 #endif
319         m_log.debug("skipping unmapped NameID with format (%s)", temp.get());
320     }
321 }
322
323 void XMLExtractorImpl::extractAttributes(
324     const Application& application, const char* assertingParty, const saml1::Attribute& attr, vector<Attribute*>& attributes
325     ) const
326 {
327 #ifdef HAVE_GOOD_STL
328     map< pair<xstring,xstring>,pair< AttributeDecoder*,vector<string> > >::const_iterator rule;
329 #else
330     map< pair<string,string>,pair< AttributeDecoder*,vector<string> > >::const_iterator rule;
331 #endif
332
333     const XMLCh* name = attr.getAttributeName();
334     const XMLCh* format = attr.getAttributeNamespace();
335     if (!name || !*name)
336         return;
337     if (!format || XMLString::equals(format, shibspconstants::SHIB1_ATTRIBUTE_NAMESPACE_URI))
338         format = &chNull;
339 #ifdef HAVE_GOOD_STL
340     if ((rule=m_attrMap.find(pair<xstring,xstring>(name,format))) != m_attrMap.end()) {
341 #else
342     auto_ptr_char temp1(name);
343     auto_ptr_char temp2(format);
344     if ((rule=m_attrMap.find(pair<string,string>(temp1.get(),temp2.get()))) != m_attrMap.end()) {
345 #endif
346         Attribute* a = rule->second.first->decode(rule->second.second, &attr, assertingParty, application.getString("entityID").second);
347         if (a)
348             attributes.push_back(a);
349     }
350     else if (m_log.isInfoEnabled()) {
351 #ifdef HAVE_GOOD_STL
352         auto_ptr_char temp1(name);
353         auto_ptr_char temp2(format);
354 #endif
355         m_log.info("skipping unmapped SAML 1.x Attribute with Name: %s%s%s", temp1.get(), *temp2.get() ? ", Namespace:" : "", temp2.get());
356     }
357 }
358
359 void XMLExtractorImpl::extractAttributes(
360     const Application& application, const char* assertingParty, const saml2::Attribute& attr, vector<Attribute*>& attributes
361     ) const
362 {
363 #ifdef HAVE_GOOD_STL
364     map< pair<xstring,xstring>,pair< AttributeDecoder*,vector<string> > >::const_iterator rule;
365 #else
366     map< pair<string,string>,pair< AttributeDecoder*,vector<string> > >::const_iterator rule;
367 #endif
368
369     const XMLCh* name = attr.getName();
370     const XMLCh* format = attr.getNameFormat();
371     if (!name || !*name)
372         return;
373     if (!format || !*format)
374         format = saml2::Attribute::UNSPECIFIED;
375     else if (XMLString::equals(format, saml2::Attribute::URI_REFERENCE))
376         format = &chNull;
377 #ifdef HAVE_GOOD_STL
378     if ((rule=m_attrMap.find(pair<xstring,xstring>(name,format))) != m_attrMap.end()) {
379 #else
380     auto_ptr_char temp1(name);
381     auto_ptr_char temp2(format);
382     if ((rule=m_attrMap.find(pair<string,string>(temp1.get(),temp2.get()))) != m_attrMap.end()) {
383 #endif
384         Attribute* a = rule->second.first->decode(rule->second.second, &attr, assertingParty, application.getString("entityID").second);
385         if (a)
386             attributes.push_back(a);
387     }
388     else if (m_log.isInfoEnabled()) {
389 #ifdef HAVE_GOOD_STL
390         auto_ptr_char temp1(name);
391         auto_ptr_char temp2(format);
392 #endif
393         m_log.info("skipping unmapped SAML 2.0 Attribute with Name: %s%s%s", temp1.get(), *temp2.get() ? ", Format:" : "", temp2.get());
394     }
395 }
396
397 void XMLExtractorImpl::extractAttributes(
398     const Application& application, const char* assertingParty, const Extensions& ext, vector<Attribute*>& attributes
399     ) const
400 {
401     const vector<XMLObject*> exts = ext.getUnknownXMLObjects();
402     for (vector<XMLObject*>::const_iterator i = exts.begin(); i!=exts.end(); ++i) {
403         const saml2::Attribute* attr = dynamic_cast<const saml2::Attribute*>(*i);
404         if (attr)
405             extractAttributes(application, assertingParty, *attr, attributes);
406     }
407 }
408
409 void XMLExtractor::extractAttributes(
410     const Application& application, const RoleDescriptor* issuer, const XMLObject& xmlObject, vector<Attribute*>& attributes
411     ) const
412 {
413     if (!m_impl)
414         return;
415
416     // Check for assertions.
417     if (XMLString::equals(xmlObject.getElementQName().getLocalPart(), saml1::Assertion::LOCAL_NAME)) {
418         const saml2::Assertion* token2 = dynamic_cast<const saml2::Assertion*>(&xmlObject);
419         if (token2) {
420             auto_ptr_char assertingParty(issuer ? dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID() : NULL);
421             const vector<saml2::AttributeStatement*>& statements = token2->getAttributeStatements();
422             for (vector<saml2::AttributeStatement*>::const_iterator s = statements.begin(); s!=statements.end(); ++s) {
423                 const vector<saml2::Attribute*>& attrs = const_cast<const saml2::AttributeStatement*>(*s)->getAttributes();
424                 for (vector<saml2::Attribute*>::const_iterator a = attrs.begin(); a!=attrs.end(); ++a)
425                     m_impl->extractAttributes(application, assertingParty.get(), *(*a), attributes);
426
427                 const vector<saml2::EncryptedAttribute*>& encattrs = const_cast<const saml2::AttributeStatement*>(*s)->getEncryptedAttributes();
428                 for (vector<saml2::EncryptedAttribute*>::const_iterator ea = encattrs.begin(); ea!=encattrs.end(); ++ea)
429                     extractAttributes(application, issuer, *(*ea), attributes);
430             }
431             return;
432         }
433
434         const saml1::Assertion* token1 = dynamic_cast<const saml1::Assertion*>(&xmlObject);
435         if (token1) {
436             auto_ptr_char assertingParty(issuer ? dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID() : NULL);
437             const vector<saml1::AttributeStatement*>& statements = token1->getAttributeStatements();
438             for (vector<saml1::AttributeStatement*>::const_iterator s = statements.begin(); s!=statements.end(); ++s) {
439                 const vector<saml1::Attribute*>& attrs = const_cast<const saml1::AttributeStatement*>(*s)->getAttributes();
440                 for (vector<saml1::Attribute*>::const_iterator a = attrs.begin(); a!=attrs.end(); ++a)
441                     m_impl->extractAttributes(application, assertingParty.get(), *(*a), attributes);
442             }
443             return;
444         }
445
446         throw AttributeExtractionException("Unable to extract attributes, unknown object type.");
447     }
448
449     // Check for metadata.
450     if (XMLString::equals(xmlObject.getElementQName().getNamespaceURI(), samlconstants::SAML20MD_NS)) {
451         const EntityDescriptor* entity = dynamic_cast<const EntityDescriptor*>(&xmlObject);
452         if (!entity)
453             throw AttributeExtractionException("Unable to extract attributes, unknown metadata object type.");
454         auto_ptr_char assertingParty(issuer ? dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID() : NULL);
455         const Extensions* ext = entity->getExtensions();
456         if (ext)
457             m_impl->extractAttributes(application, assertingParty.get(), *ext, attributes);
458         const EntitiesDescriptor* group = dynamic_cast<const EntitiesDescriptor*>(entity->getParent());
459         while (group) {
460             ext = group->getExtensions();
461             if (ext)
462                 m_impl->extractAttributes(application, assertingParty.get(), *ext, attributes);
463             group = dynamic_cast<const EntitiesDescriptor*>(group->getParent());
464         }
465         return;
466     }
467
468     // Check for attributes.
469     if (XMLString::equals(xmlObject.getElementQName().getLocalPart(), saml1::Attribute::LOCAL_NAME)) {
470         auto_ptr_char assertingParty(issuer ? dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID() : NULL);
471
472         const saml2::Attribute* attr2 = dynamic_cast<const saml2::Attribute*>(&xmlObject);
473         if (attr2)
474             return m_impl->extractAttributes(application, assertingParty.get(), *attr2, attributes);
475
476         const saml1::Attribute* attr1 = dynamic_cast<const saml1::Attribute*>(&xmlObject);
477         if (attr1)
478             return m_impl->extractAttributes(application, assertingParty.get(), *attr1, attributes);
479
480         throw AttributeExtractionException("Unable to extract attributes, unknown object type.");
481     }
482
483     if (XMLString::equals(xmlObject.getElementQName().getLocalPart(), EncryptedAttribute::LOCAL_NAME)) {
484         const EncryptedAttribute* encattr = dynamic_cast<const EncryptedAttribute*>(&xmlObject);
485         if (encattr) {
486             const XMLCh* recipient = application.getXMLString("entityID").second;
487             CredentialResolver* cr = application.getCredentialResolver();
488             if (!cr) {
489                 m_log.warn("found encrypted attribute, but no CredentialResolver was available");
490                 return;
491             }
492
493             try {
494                 Locker credlocker(cr);
495                 if (issuer) {
496                     MetadataCredentialCriteria mcc(*issuer);
497                     auto_ptr<XMLObject> decrypted(encattr->decrypt(*cr, recipient, &mcc));
498                     if (m_log.isDebugEnabled())
499                         m_log.debugStream() << "decrypted Attribute:" << logging::eol << *(decrypted.get()) << logging::eol;
500                     return extractAttributes(application, issuer, *(decrypted.get()), attributes);
501                 }
502                 else {
503                     auto_ptr<XMLObject> decrypted(encattr->decrypt(*cr, recipient));
504                     if (m_log.isDebugEnabled())
505                         m_log.debugStream() << "decrypted Attribute:" << logging::eol << *(decrypted.get()) << logging::eol;
506                     return extractAttributes(application, issuer, *(decrypted.get()), attributes);
507                 }
508             }
509             catch (exception& ex) {
510                 m_log.error("caught exception decrypting Attribute: %s", ex.what());
511                 return;
512             }
513         }
514     }
515
516     // Check for NameIDs.
517     const NameID* name2 = dynamic_cast<const NameID*>(&xmlObject);
518     if (name2) {
519         auto_ptr_char assertingParty(issuer ? dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID() : NULL);
520         return m_impl->extractAttributes(application, assertingParty.get(), *name2, attributes);
521     }
522
523     const NameIdentifier* name1 = dynamic_cast<const NameIdentifier*>(&xmlObject);
524     if (name1) {
525         auto_ptr_char assertingParty(issuer ? dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID() : NULL);
526         return m_impl->extractAttributes(application, assertingParty.get(), *name1, attributes);
527     }
528
529     throw AttributeExtractionException("Unable to extract attributes, unknown object type.");
530 }
531
532 pair<bool,DOMElement*> XMLExtractor::load()
533 {
534     // Load from source using base class.
535     pair<bool,DOMElement*> raw = ReloadableXMLFile::load();
536     
537     // If we own it, wrap it.
538     XercesJanitor<DOMDocument> docjanitor(raw.first ? raw.second->getOwnerDocument() : NULL);
539
540     XMLExtractorImpl* impl = new XMLExtractorImpl(raw.second, m_log);
541     
542     // If we held the document, transfer it to the impl. If we didn't, it's a no-op.
543     impl->setDocument(docjanitor.release());
544
545     delete m_impl;
546     m_impl = impl;
547
548     return make_pair(false,(DOMElement*)NULL);
549 }