Imported Upstream version 2.2.1+dfsg
[shibboleth/sp.git] / shibsp / attribute / resolver / impl / SimpleAggregationAttributeResolver.cpp
1 /*
2  *  Copyright 2009 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  * SimpleAggregationAttributeResolver.cpp
19  *
20  * AttributeResolver based on SAML queries to third-party AA sources.
21  */
22
23 #include "internal.h"
24 #include "Application.h"
25 #include "ServiceProvider.h"
26 #include "SessionCache.h"
27 #include "attribute/NameIDAttribute.h"
28 #include "attribute/filtering/AttributeFilter.h"
29 #include "attribute/filtering/BasicFilteringContext.h"
30 #include "attribute/resolver/AttributeExtractor.h"
31 #include "attribute/resolver/AttributeResolver.h"
32 #include "attribute/resolver/ResolutionContext.h"
33 #include "binding/SOAPClient.h"
34 #include "metadata/MetadataProviderCriteria.h"
35 #include "util/SPConstants.h"
36
37 #include <saml/exceptions.h>
38 #include <saml/SAMLConfig.h>
39 #include <saml/binding/SecurityPolicy.h>
40 #include <saml/saml2/binding/SAML2SOAPClient.h>
41 #include <saml/saml2/core/Protocols.h>
42 #include <saml/saml2/metadata/MetadataProvider.h>
43 #include <xmltooling/util/NDC.h>
44 #include <xmltooling/util/XMLHelper.h>
45 #include <xercesc/util/XMLUniDefs.hpp>
46
47 using namespace shibsp;
48 using namespace opensaml::saml2;
49 using namespace opensaml::saml2p;
50 using namespace opensaml::saml2md;
51 using namespace opensaml;
52 using namespace xmltooling;
53 using namespace std;
54
55 namespace shibsp {
56
57     class SHIBSP_DLLLOCAL SimpleAggregationContext : public ResolutionContext
58     {
59     public:
60         SimpleAggregationContext(const Application& application, const Session& session)
61             : m_app(application),
62               m_session(&session),
63               m_nameid(NULL),
64               m_class(XMLString::transcode(session.getAuthnContextClassRef())),
65               m_decl(XMLString::transcode(session.getAuthnContextDeclRef())),
66               m_inputTokens(NULL),
67               m_inputAttributes(NULL) {
68         }
69
70         SimpleAggregationContext(
71             const Application& application,
72             const NameID* nameid=NULL,
73             const XMLCh* authncontext_class=NULL,
74             const XMLCh* authncontext_decl=NULL,
75             const vector<const opensaml::Assertion*>* tokens=NULL,
76             const vector<shibsp::Attribute*>* attributes=NULL
77             ) : m_app(application),
78                 m_session(NULL),
79                 m_nameid(nameid),
80                 m_class(const_cast<XMLCh*>(authncontext_class)),
81                 m_decl(const_cast<XMLCh*>(authncontext_decl)),
82                 m_inputTokens(tokens),
83                 m_inputAttributes(attributes) {
84         }
85
86         ~SimpleAggregationContext() {
87             for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<shibsp::Attribute>());
88             for_each(m_assertions.begin(), m_assertions.end(), xmltooling::cleanup<opensaml::Assertion>());
89             if (m_session) {
90                 XMLString::release(&m_class);
91                 XMLString::release(&m_decl);
92             }
93         }
94
95         const Application& getApplication() const {
96             return m_app;
97         }
98         const NameID* getNameID() const {
99             return m_session ? m_session->getNameID() : m_nameid;
100         }
101         const XMLCh* getClassRef() const {
102             return m_class;
103         }
104         const XMLCh* getDeclRef() const {
105             return m_decl;
106         }
107         const Session* getSession() const {
108             return m_session;
109         }
110         const vector<shibsp::Attribute*>* getInputAttributes() const {
111             return m_inputAttributes;
112         }
113         const vector<const opensaml::Assertion*>* getInputTokens() const {
114             return m_inputTokens;
115         }
116         vector<shibsp::Attribute*>& getResolvedAttributes() {
117             return m_attributes;
118         }
119         vector<opensaml::Assertion*>& getResolvedAssertions() {
120             return m_assertions;
121         }
122
123     private:
124         const Application& m_app;
125         const Session* m_session;
126         const NameID* m_nameid;
127         XMLCh* m_class;
128         XMLCh* m_decl;
129         const vector<const opensaml::Assertion*>* m_inputTokens;
130         const vector<shibsp::Attribute*>* m_inputAttributes;
131         vector<shibsp::Attribute*> m_attributes;
132         vector<opensaml::Assertion*> m_assertions;
133     };
134
135     class SHIBSP_DLLLOCAL SimpleAggregationResolver : public AttributeResolver
136     {
137     public:
138         SimpleAggregationResolver(const DOMElement* e);
139         ~SimpleAggregationResolver() {
140             delete m_trust;
141             delete m_metadata;
142             for_each(m_designators.begin(), m_designators.end(), xmltooling::cleanup<saml2::Attribute>());
143         }
144
145         Lockable* lock() {return this;}
146         void unlock() {}
147
148         ResolutionContext* createResolutionContext(
149             const Application& application,
150             const EntityDescriptor* issuer,
151             const XMLCh* protocol,
152             const NameID* nameid=NULL,
153             const XMLCh* authncontext_class=NULL,
154             const XMLCh* authncontext_decl=NULL,
155             const vector<const opensaml::Assertion*>* tokens=NULL,
156             const vector<shibsp::Attribute*>* attributes=NULL
157             ) const {
158             return new SimpleAggregationContext(application,nameid,authncontext_class,authncontext_decl,tokens,attributes);
159         }
160
161         ResolutionContext* createResolutionContext(const Application& application, const Session& session) const {
162             return new SimpleAggregationContext(application,session);
163         }
164
165         void resolveAttributes(ResolutionContext& ctx) const;
166
167         void getAttributeIds(vector<string>& attributes) const {
168             // Nothing to do, only the extractor would actually generate them.
169         }
170
171     private:
172         bool doQuery(SimpleAggregationContext& ctx, const char* entityID, const NameID* name) const;
173
174         Category& m_log;
175         string m_policyId;
176         vector<string> m_attributeIds;
177         xstring m_format;
178         MetadataProvider* m_metadata;
179         TrustEngine* m_trust;
180         vector<saml2::Attribute*> m_designators;
181         vector< pair<string,bool> > m_sources;
182     };
183
184     AttributeResolver* SHIBSP_DLLLOCAL SimpleAggregationResolverFactory(const DOMElement* const & e)
185     {
186         return new SimpleAggregationResolver(e);
187     }
188
189     static const XMLCh attributeId[] =          UNICODE_LITERAL_11(a,t,t,r,i,b,u,t,e,I,d);
190     static const XMLCh Entity[] =               UNICODE_LITERAL_6(E,n,t,i,t,y);
191     static const XMLCh EntityReference[] =      UNICODE_LITERAL_15(E,n,t,i,t,y,R,e,f,e,r,e,n,c,e);
192     static const XMLCh format[] =               UNICODE_LITERAL_6(f,o,r,m,a,t);
193     static const XMLCh _MetadataProvider[] =    UNICODE_LITERAL_16(M,e,t,a,d,a,t,a,P,r,o,v,i,d,e,r);
194     static const XMLCh policyId[] =             UNICODE_LITERAL_8(p,o,l,i,c,y,I,d);
195     static const XMLCh _TrustEngine[] =         UNICODE_LITERAL_11(T,r,u,s,t,E,n,g,i,n,e);
196     static const XMLCh _type[] =                UNICODE_LITERAL_4(t,y,p,e);
197 };
198
199 SimpleAggregationResolver::SimpleAggregationResolver(const DOMElement* e)
200     : m_log(Category::getInstance(SHIBSP_LOGCAT".AttributeResolver.SimpleAggregation")), m_metadata(NULL), m_trust(NULL)
201 {
202 #ifdef _DEBUG
203     xmltooling::NDC ndc("SimpleAggregationResolver");
204 #endif
205
206     const XMLCh* pid = e ? e->getAttributeNS(NULL, policyId) : NULL;
207     if (pid && *pid) {
208         auto_ptr_char temp(pid);
209         m_policyId = temp.get();
210     }
211
212     pid = e ? e->getAttributeNS(NULL, attributeId) : NULL;
213     if (pid && *pid) {
214         char* dup = XMLString::transcode(pid);
215         char* pos;
216         char* start = dup;
217         while (start && *start) {
218             while (*start && isspace(*start))
219                 start++;
220             if (!*start)
221                 break;
222             pos = strchr(start,' ');
223             if (pos)
224                 *pos=0;
225             m_attributeIds.push_back(start);
226             start = pos ? pos+1 : NULL;
227         }
228         XMLString::release(&dup);
229
230         pid = e->getAttributeNS(NULL, format);
231         if (pid && *pid)
232             m_format = pid;
233
234     }
235
236     DOMElement* child = XMLHelper::getFirstChildElement(e, _MetadataProvider);
237     if (child) {
238         auto_ptr_char type(child->getAttributeNS(NULL, _type));
239         if (!type.get() || !*type.get())
240             throw ConfigurationException("MetadataProvider element missing type attribute.");
241         m_log.info("building MetadataProvider of type %s...", type.get());
242         auto_ptr<MetadataProvider> mp(SAMLConfig::getConfig().MetadataProviderManager.newPlugin(type.get(), child));
243         mp->init();
244         m_metadata = mp.release();
245     }
246
247     child = XMLHelper::getFirstChildElement(e,  _TrustEngine);
248     if (child) {
249         try {
250             auto_ptr_char type(child->getAttributeNS(NULL, _type));
251             if (!type.get() || !*type.get())
252                 throw ConfigurationException("TrustEngine element missing type attribute.");
253             m_log.info("building TrustEngine of type %s...", type.get());
254             m_trust = XMLToolingConfig::getConfig().TrustEngineManager.newPlugin(type.get(), child);
255         }
256         catch (exception&) {
257             delete m_metadata;
258             throw;
259         }
260     }
261
262     child = XMLHelper::getFirstChildElement(e);
263     while (child) {
264         if (child->hasChildNodes() && XMLString::equals(child->getLocalName(), Entity)) {
265             pid = child->getFirstChild()->getNodeValue();
266             if (pid && *pid) {
267                 auto_ptr_char tpid(pid);
268                 m_sources.push_back(pair<string,bool>(tpid.get(),true));
269             }
270         }
271         else if (child->hasChildNodes() && XMLString::equals(child->getLocalName(), EntityReference)) {
272             pid = child->getFirstChild()->getNodeValue();
273             if (pid && *pid) {
274                 auto_ptr_char tpid(pid);
275                 m_sources.push_back(pair<string,bool>(tpid.get(),false));
276             }
277         }
278         else if (XMLHelper::isNodeNamed(child, samlconstants::SAML20_NS, saml2::Attribute::LOCAL_NAME)) {
279             try {
280                 auto_ptr<XMLObject> obj(saml2::AttributeBuilder::buildOneFromElement(child));
281                 saml2::Attribute* down = dynamic_cast<saml2::Attribute*>(obj.get());
282                 if (down) {
283                     m_designators.push_back(down);
284                     obj.release();
285                 }
286             }
287             catch (exception& ex) {
288                 m_log.error("exception loading attribute designator: %s", ex.what());
289             }
290         }
291         child = XMLHelper::getNextSiblingElement(child);
292     }
293
294 }
295
296 bool SimpleAggregationResolver::doQuery(SimpleAggregationContext& ctx, const char* entityID, const NameID* name) const
297 {
298 #ifdef _DEBUG
299     xmltooling::NDC ndc("doQuery");
300 #endif
301     const Application& application = ctx.getApplication();
302     MetadataProviderCriteria mc(application, entityID, &AttributeAuthorityDescriptor::ELEMENT_QNAME, samlconstants::SAML20P_NS);
303     Locker mlocker(m_metadata);
304     const AttributeAuthorityDescriptor* AA=NULL;
305     pair<const EntityDescriptor*,const RoleDescriptor*> mdresult =
306         (m_metadata ? m_metadata : application.getMetadataProvider())->getEntityDescriptor(mc);
307     if (!mdresult.first) {
308         m_log.warn("unable to locate metadata for provider (%s)", entityID);
309         return false;
310     }
311     else if (!(AA=dynamic_cast<const AttributeAuthorityDescriptor*>(mdresult.second))) {
312         m_log.warn("no SAML 2 AttributeAuthority role found in metadata for (%s)", entityID);
313         return false;
314     }
315
316     const PropertySet* relyingParty = application.getRelyingParty(mdresult.first);
317
318     // Locate policy key.
319     const char* policyId = m_policyId.empty() ? application.getString("policyId").second : m_policyId.c_str();
320
321     // Access policy properties.
322     const PropertySet* settings = application.getServiceProvider().getPolicySettings(policyId);
323     pair<bool,bool> validate = settings->getBool("validate");
324
325     pair<bool,bool> signedAssertions = relyingParty->getBool("requireSignedAssertions");
326     pair<bool,const char*> encryption = relyingParty->getString("encryption");
327
328     shibsp::SecurityPolicy policy(application, NULL, validate.first && validate.second, policyId);
329     if (m_metadata)
330         policy.setMetadataProvider(m_metadata);
331     if (m_trust)
332         policy.setTrustEngine(m_trust);
333     policy.getAudiences().push_back(relyingParty->getXMLString("entityID").second);
334
335     MetadataCredentialCriteria mcc(*AA);
336     shibsp::SOAPClient soaper(policy);
337
338     auto_ptr_XMLCh binding(samlconstants::SAML20_BINDING_SOAP);
339     saml2p::StatusResponseType* srt=NULL;
340     const vector<AttributeService*>& endpoints=AA->getAttributeServices();
341     for (vector<AttributeService*>::const_iterator ep=endpoints.begin(); !srt && ep!=endpoints.end(); ++ep) {
342         if (!XMLString::equals((*ep)->getBinding(),binding.get())  || !(*ep)->getLocation())
343             continue;
344         auto_ptr_char loc((*ep)->getLocation());
345         try {
346             auto_ptr<saml2::Subject> subject(saml2::SubjectBuilder::buildSubject());
347
348             // Encrypt the NameID?
349             if (encryption.first && (!strcmp(encryption.second, "true") || !strcmp(encryption.second, "back"))) {
350                 auto_ptr<EncryptedID> encrypted(EncryptedIDBuilder::buildEncryptedID());
351                 MetadataCredentialCriteria mcc(*AA);
352                 encrypted->encrypt(
353                     *name,
354                     *(policy.getMetadataProvider()),
355                     mcc,
356                     false,
357                     relyingParty->getXMLString("encryptionAlg").second
358                     );
359                 subject->setEncryptedID(encrypted.release());
360             }
361             else {
362                 subject->setNameID(name->cloneNameID());
363             }
364
365             saml2p::AttributeQuery* query = saml2p::AttributeQueryBuilder::buildAttributeQuery();
366             query->setSubject(subject.release());
367             Issuer* iss = IssuerBuilder::buildIssuer();
368             iss->setName(relyingParty->getXMLString("entityID").second);
369             query->setIssuer(iss);
370             for (vector<saml2::Attribute*>::const_iterator ad = m_designators.begin(); ad!=m_designators.end(); ++ad)
371                 query->getAttributes().push_back((*ad)->cloneAttribute());
372
373             SAML2SOAPClient client(soaper, false);
374             client.sendSAML(query, application.getId(), mcc, loc.get());
375             srt = client.receiveSAML();
376         }
377         catch (exception& ex) {
378             m_log.error("exception during SAML query to %s: %s", loc.get(), ex.what());
379             soaper.reset();
380         }
381     }
382
383     if (!srt) {
384         m_log.error("unable to obtain a SAML response from attribute authority (%s)", entityID);
385         return false;
386     }
387     saml2p::Response* response = dynamic_cast<saml2p::Response*>(srt);
388     if (!response) {
389         delete srt;
390         m_log.error("message was not a samlp:Response");
391         return true;
392     }
393     else if (!response->getStatus() || !response->getStatus()->getStatusCode() ||
394             !XMLString::equals(response->getStatus()->getStatusCode()->getValue(), saml2p::StatusCode::SUCCESS)) {
395         delete srt;
396         m_log.error("attribute authority (%s) returned a SAML error", entityID);
397         return true;
398     }
399
400     const vector<saml2::Assertion*>& assertions = const_cast<const saml2p::Response*>(response)->getAssertions();
401     if (assertions.empty()) {
402         delete srt;
403         m_log.warn("response from attribute authority (%s) was empty", entityID);
404         return true;
405     }
406     else if (assertions.size()>1)
407         m_log.warn("resolver only supports one assertion in the query response");
408
409     auto_ptr<saml2p::StatusResponseType> wrapper(srt);
410     saml2::Assertion* newtoken = assertions.front();
411
412     if (!newtoken->getSignature() && signedAssertions.first && signedAssertions.second) {
413         m_log.error("assertion unsigned, rejecting it based on signedAssertions policy");
414         return true;
415     }
416
417     try {
418         // We're going to insist that the assertion issuer is the same as the peer.
419         // Reset the policy's message bits and extract them from the assertion.
420         policy.reset(true);
421         policy.setMessageID(newtoken->getID());
422         policy.setIssueInstant(newtoken->getIssueInstantEpoch());
423         policy.setIssuer(newtoken->getIssuer());
424         policy.evaluate(*newtoken);
425
426         // Now we can check the security status of the policy.
427         if (!policy.isAuthenticated())
428             throw SecurityPolicyException("Security of SAML 2.0 query result not established.");
429     }
430     catch (exception& ex) {
431         m_log.error("assertion failed policy validation: %s", ex.what());
432         return true;
433     }
434
435     newtoken->detach();
436     wrapper.release();
437     ctx.getResolvedAssertions().push_back(newtoken);
438
439     // Finally, extract and filter the result.
440     try {
441         AttributeExtractor* extractor = application.getAttributeExtractor();
442         if (extractor) {
443             Locker extlocker(extractor);
444             extractor->extractAttributes(application, AA, *newtoken, ctx.getResolvedAttributes());
445         }
446
447         AttributeFilter* filter = application.getAttributeFilter();
448         if (filter) {
449             BasicFilteringContext fc(application, ctx.getResolvedAttributes(), AA, ctx.getClassRef(), ctx.getDeclRef());
450             Locker filtlocker(filter);
451             filter->filterAttributes(fc, ctx.getResolvedAttributes());
452         }
453     }
454     catch (exception& ex) {
455         m_log.error("caught exception extracting/filtering attributes from query result: %s", ex.what());
456         for_each(ctx.getResolvedAttributes().begin(), ctx.getResolvedAttributes().end(), xmltooling::cleanup<shibsp::Attribute>());
457         ctx.getResolvedAttributes().clear();
458     }
459
460     return true;
461 }
462
463 void SimpleAggregationResolver::resolveAttributes(ResolutionContext& ctx) const
464 {
465 #ifdef _DEBUG
466     xmltooling::NDC ndc("resolveAttributes");
467 #endif
468
469     SimpleAggregationContext& qctx = dynamic_cast<SimpleAggregationContext&>(ctx);
470
471     // First we manufacture the appropriate NameID to use.
472     NameID* n=NULL;
473     for (vector<string>::const_iterator a = m_attributeIds.begin(); !n && a != m_attributeIds.end(); ++a) {
474         const Attribute* attr=NULL;
475         if (qctx.getSession()) {
476             // Input attributes should be available via multimap.
477             pair<multimap<string,const Attribute*>::const_iterator, multimap<string,const Attribute*>::const_iterator> range =
478                 qctx.getSession()->getIndexedAttributes().equal_range(*a);
479             for (; !attr && range.first != range.second; ++range.first) {
480                 if (range.first->second->valueCount() > 0)
481                     attr = range.first->second;
482             }
483         }
484         else if (qctx.getInputAttributes()) {
485             // Have to loop over unindexed set.
486             const vector<Attribute*>* matches = qctx.getInputAttributes();
487             for (vector<Attribute*>::const_iterator match = matches->begin(); !attr && match != matches->end(); ++match) {
488                 if (*a == (*match)->getId() && (*match)->valueCount() > 0)
489                     attr = *match;
490             }
491         }
492
493         if (attr) {
494             m_log.debug("using input attribute (%s) as identifier for queries", attr->getId());
495             n = NameIDBuilder::buildNameID();
496             const NameIDAttribute* down = dynamic_cast<const NameIDAttribute*>(attr);
497             if (down) {
498                 // We can create a NameID directly from the source material.
499                 const NameIDAttribute::Value& v = down->getValues().front();
500                 XMLCh* val = fromUTF8(v.m_Name.c_str());
501                 n->setName(val);
502                 delete[] val;
503                 if (!v.m_Format.empty()) {
504                     val = fromUTF8(v.m_Format.c_str());
505                     n->setFormat(val);
506                     delete[] val;
507                 }
508                 if (!v.m_NameQualifier.empty()) {
509                     val = fromUTF8(v.m_NameQualifier.c_str());
510                     n->setNameQualifier(val);
511                     delete[] val;
512                 }
513                 if (!v.m_SPNameQualifier.empty()) {
514                     val = fromUTF8(v.m_SPNameQualifier.c_str());
515                     n->setSPNameQualifier(val);
516                     delete[] val;
517                 }
518                 if (!v.m_SPProvidedID.empty()) {
519                     val = fromUTF8(v.m_SPProvidedID.c_str());
520                     n->setSPProvidedID(val);
521                     delete[] val;
522                 }
523             }
524             else {
525                 // We have to mock up the NameID.
526                 XMLCh* val = fromUTF8(attr->getSerializedValues().front().c_str());
527                 n->setName(val);
528                 delete[] val;
529                 if (!m_format.empty())
530                     n->setFormat(m_format.c_str());
531             }
532         }
533     }
534
535     if (!n) {
536         if (qctx.getNameID() && m_attributeIds.empty()) {
537             m_log.debug("using authenticated NameID as identifier for queries");
538         }
539         else {
540             m_log.warn("unable to resolve attributes, no suitable query identifier found");
541             return;
542         }
543     }
544
545     auto_ptr<NameID> wrapper(n);
546
547     set<string> history;
548
549     // We have a master loop over all the possible sources of material.
550     for (vector< pair<string,bool> >::const_iterator source = m_sources.begin(); source != m_sources.end(); ++source) {
551         if (source->second) {
552             // A literal entityID to query.
553             if (history.count(source->first) == 0) {
554                 m_log.debug("issuing SAML query to (%s)", source->first.c_str());
555                 doQuery(qctx, source->first.c_str(), n ? n : qctx.getNameID());
556                 history.insert(source->first);
557             }
558             else {
559                 m_log.debug("skipping previously queried attribute source (%s)", source->first.c_str());
560             }
561         }
562         else {
563             m_log.debug("using attribute sources referenced in attribute (%s)", source->first.c_str());
564             if (qctx.getSession()) {
565                 // Input attributes should be available via multimap.
566                 pair<multimap<string,const Attribute*>::const_iterator, multimap<string,const Attribute*>::const_iterator> range =
567                     qctx.getSession()->getIndexedAttributes().equal_range(source->first);
568                 for (; range.first != range.second; ++range.first) {
569                     const vector<string>& links = range.first->second->getSerializedValues();
570                     for (vector<string>::const_iterator link = links.begin(); link != links.end(); ++link) {
571                         if (history.count(*link) == 0) {
572                             m_log.debug("issuing SAML query to (%s)", link->c_str());
573                             doQuery(qctx, link->c_str(), n ? n : qctx.getNameID());
574                             history.insert(*link);
575                         }
576                         else {
577                             m_log.debug("skipping previously queried attribute source (%s)", link->c_str());
578                         }
579                     }
580                 }
581             }
582             else if (qctx.getInputAttributes()) {
583                 // Have to loop over unindexed set.
584                 const vector<Attribute*>* matches = qctx.getInputAttributes();
585                 for (vector<Attribute*>::const_iterator match = matches->begin(); match != matches->end(); ++match) {
586                     if (source->first == (*match)->getId()) {
587                         const vector<string>& links = (*match)->getSerializedValues();
588                         for (vector<string>::const_iterator link = links.begin(); link != links.end(); ++link) {
589                             if (history.count(*link) == 0) {
590                                 m_log.debug("issuing SAML query to (%s)", link->c_str());
591                                 doQuery(qctx, link->c_str(), n ? n : qctx.getNameID());
592                                 history.insert(*link);
593                             }
594                             else {
595                                 m_log.debug("skipping previously queried attribute source (%s)", link->c_str());
596                             }
597                         }
598                     }
599                 }
600             }
601         }
602     }
603 }