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