Signing/encryption support.
[shibboleth/cpp-sp.git] / shibsp / attribute / resolver / impl / QueryAttributeResolver.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  * QueryAttributeResolver.cpp
19  * 
20  * AttributeResolver based on SAML queries.
21  */
22
23 #include "internal.h"
24 #include "Application.h"
25 #include "ServiceProvider.h"
26 #include "SessionCache.h"
27 #include "attribute/Attribute.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 "util/SPConstants.h"
35
36 #include <saml/exceptions.h>
37 #include <saml/binding/SecurityPolicy.h>
38 #include <saml/saml1/binding/SAML1SOAPClient.h>
39 #include <saml/saml1/core/Assertions.h>
40 #include <saml/saml1/core/Protocols.h>
41 #include <saml/saml1/profile/AssertionValidator.h>
42 #include <saml/saml2/binding/SAML2SOAPClient.h>
43 #include <saml/saml2/core/Protocols.h>
44 #include <saml/saml2/metadata/Metadata.h>
45 #include <saml/saml2/metadata/MetadataProvider.h>
46 #include <saml/saml2/profile/AssertionValidator.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::saml1;
53 using namespace opensaml::saml1p;
54 using namespace opensaml::saml2;
55 using namespace opensaml::saml2p;
56 using namespace opensaml::saml2md;
57 using namespace opensaml;
58 using namespace xmltooling;
59 using namespace std;
60
61 namespace shibsp {
62
63     class SHIBSP_DLLLOCAL QueryContext : public ResolutionContext
64     {
65     public:
66         QueryContext(const Application& application, const Session& session)
67                 : m_query(true), m_app(application), m_session(&session), m_metadata(NULL), m_entity(NULL), m_nameid(NULL) {
68             m_protocol = XMLString::transcode(session.getProtocol());
69             m_class = XMLString::transcode(session.getAuthnContextClassRef());
70             m_decl = XMLString::transcode(session.getAuthnContextDeclRef());
71         }
72         
73         QueryContext(
74             const Application& application,
75             const EntityDescriptor* issuer,
76             const XMLCh* protocol,
77             const NameID* nameid,
78             const XMLCh* authncontext_class=NULL,
79             const XMLCh* authncontext_decl=NULL,
80             const vector<const opensaml::Assertion*>* tokens=NULL,
81             const vector<Attribute*>* attributes=NULL
82             ) : m_query(true), m_app(application), m_session(NULL), m_metadata(NULL), m_entity(issuer),
83                 m_protocol(protocol), m_nameid(nameid), m_class(authncontext_class), m_decl(authncontext_decl) {
84
85             if (tokens) {
86                 for (vector<const opensaml::Assertion*>::const_iterator t = tokens->begin(); t!=tokens->end(); ++t) {
87                     const saml2::Assertion* token2 = dynamic_cast<const saml2::Assertion*>(*t);
88                     if (token2 && !token2->getAttributeStatements().empty()) {
89                         m_query = false;
90                     }
91                     else {
92                         const saml1::Assertion* token1 = dynamic_cast<const saml1::Assertion*>(*t);
93                         if (token1 && !token1->getAttributeStatements().empty()) {
94                             m_query = false;
95                         }
96                     }
97                 }
98             }
99         }
100         
101         ~QueryContext() {
102             if (m_session) {
103                 XMLString::release((XMLCh**)&m_protocol);
104                 XMLString::release((XMLCh**)&m_class);
105                 XMLString::release((XMLCh**)&m_decl);
106             }
107             if (m_metadata)
108                 m_metadata->unlock();
109             for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<shibsp::Attribute>());
110             for_each(m_assertions.begin(), m_assertions.end(), xmltooling::cleanup<opensaml::Assertion>());
111         }
112     
113         bool doQuery() const {
114             return m_query;
115         }
116
117         const Application& getApplication() const {
118             return m_app;
119         }
120         const EntityDescriptor* getEntityDescriptor() const {
121             if (m_entity)
122                 return m_entity;
123             if (m_session && m_session->getEntityID()) {
124                 m_metadata = m_app.getMetadataProvider();
125                 if (m_metadata) {
126                     m_metadata->lock();
127                     return m_entity = m_metadata->getEntityDescriptor(m_session->getEntityID());
128                 }
129             }
130             return NULL;
131         }
132         const XMLCh* getProtocol() const {
133             return m_protocol;
134         }
135         const NameID* getNameID() const {
136             return m_session ? m_session->getNameID() : m_nameid;
137         }
138         const XMLCh* getClassRef() const {
139             return m_class;
140         }
141         const XMLCh* getDeclRef() const {
142             return m_decl;
143         }
144         const Session* getSession() const {
145             return m_session;
146         }
147         vector<shibsp::Attribute*>& getResolvedAttributes() {
148             return m_attributes;
149         }
150         vector<opensaml::Assertion*>& getResolvedAssertions() {
151             return m_assertions;
152         }
153
154     private:
155         bool m_query;
156         const Application& m_app;
157         const Session* m_session;
158         mutable MetadataProvider* m_metadata;
159         mutable const EntityDescriptor* m_entity;
160         const XMLCh* m_protocol;
161         const NameID* m_nameid;
162         const XMLCh* m_class;
163         const XMLCh* m_decl;
164         vector<shibsp::Attribute*> m_attributes;
165         vector<opensaml::Assertion*> m_assertions;
166     };
167     
168     class SHIBSP_DLLLOCAL QueryResolver : public AttributeResolver
169     {
170     public:
171         QueryResolver(const DOMElement* e);
172         ~QueryResolver() {
173             for_each(m_SAML1Designators.begin(), m_SAML1Designators.end(), xmltooling::cleanup<AttributeDesignator>());
174             for_each(m_SAML2Designators.begin(), m_SAML2Designators.end(), xmltooling::cleanup<saml2::Attribute>());
175         }
176
177         Lockable* lock() {return this;}
178         void unlock() {}
179         
180         ResolutionContext* createResolutionContext(
181             const Application& application,
182             const EntityDescriptor* issuer,
183             const XMLCh* protocol,
184             const NameID* nameid,
185             const XMLCh* authncontext_class=NULL,
186             const XMLCh* authncontext_decl=NULL,
187             const vector<const opensaml::Assertion*>* tokens=NULL,
188             const vector<shibsp::Attribute*>* attributes=NULL
189             ) const {
190             return new QueryContext(application,issuer,protocol,nameid,authncontext_class,authncontext_decl,tokens,attributes);
191         }
192
193         ResolutionContext* createResolutionContext(const Application& application, const Session& session) const {
194             return new QueryContext(application,session);
195         }
196
197         void resolveAttributes(ResolutionContext& ctx) const;
198
199         void getAttributeIds(vector<string>& attributes) const {
200             // Nothing to do, only the extractor would actually generate them.
201         }
202
203     private:
204         bool SAML1Query(QueryContext& ctx) const;
205         bool SAML2Query(QueryContext& ctx) const;
206         void signMessage(const Application& app, const RoleDescriptor& role, SignableObject& msg) const;
207
208         Category& m_log;
209         vector<AttributeDesignator*> m_SAML1Designators;
210         vector<saml2::Attribute*> m_SAML2Designators;
211     };
212
213     AttributeResolver* SHIBSP_DLLLOCAL QueryResolverFactory(const DOMElement* const & e)
214     {
215         return new QueryResolver(e);
216     }
217     
218 };
219
220 void SHIBSP_API shibsp::registerAttributeResolvers()
221 {
222     SPConfig::getConfig().AttributeResolverManager.registerFactory(QUERY_ATTRIBUTE_RESOLVER, QueryResolverFactory);
223 }
224
225 QueryResolver::QueryResolver(const DOMElement* e) : m_log(Category::getInstance(SHIBSP_LOGCAT".AttributeResolver"))
226 {
227 #ifdef _DEBUG
228     xmltooling::NDC ndc("QueryResolver");
229 #endif
230     
231     DOMElement* child = XMLHelper::getFirstChildElement(e);
232     while (child) {
233         try {
234             if (XMLHelper::isNodeNamed(e, samlconstants::SAML20_NS, saml2::Attribute::LOCAL_NAME)) {
235                 auto_ptr<XMLObject> obj(saml2::AttributeBuilder::buildOneFromElement(child));
236                 saml2::Attribute* down = dynamic_cast<saml2::Attribute*>(obj.get());
237                 if (down) {
238                     m_SAML2Designators.push_back(down);
239                     obj.release();
240                 }
241             }
242             else if (XMLHelper::isNodeNamed(e, samlconstants::SAML1P_NS, AttributeDesignator::LOCAL_NAME)) {
243                 auto_ptr<XMLObject> obj(AttributeDesignatorBuilder::buildOneFromElement(child));
244                 AttributeDesignator* down = dynamic_cast<AttributeDesignator*>(obj.get());
245                 if (down) {
246                     m_SAML1Designators.push_back(down);
247                     obj.release();
248                 }
249             }
250         }
251         catch (exception& ex) {
252             m_log.error("exception loading attribute designator: %s", ex.what());
253         }
254         child = XMLHelper::getNextSiblingElement(child);
255     }
256 }
257
258 void QueryResolver::signMessage(const Application& application, const RoleDescriptor& role, SignableObject& msg) const
259 {
260     const PropertySet* relyingParty = application.getRelyingParty(dynamic_cast<const EntityDescriptor*>(role.getParent()));
261     pair<bool,const char*> prop = relyingParty->getString("signing");
262     if (prop.first && (!strcmp(prop.second, "true") || !strcmp(prop.second, "back"))) {
263         CredentialResolver* credResolver=application.getCredentialResolver();
264         if (credResolver) {
265             Locker credLocker(credResolver);
266             // Fill in criteria to use.
267             MetadataCredentialCriteria mcc(role);
268             mcc.setUsage(CredentialCriteria::SIGNING_CREDENTIAL);
269             prop = relyingParty->getString("keyName");
270             if (prop.first)
271                 mcc.getKeyNames().insert(prop.second);
272             pair<bool,const XMLCh*> sigalg = relyingParty->getXMLString("signingAlg");
273             if (sigalg.first)
274                 mcc.setXMLAlgorithm(sigalg.second);
275             const Credential* cred = credResolver->resolve(&mcc);
276             if (cred) {
277                 xmlsignature::Signature* sig = xmlsignature::SignatureBuilder::buildSignature();
278                 msg.setSignature(sig);
279                 if (sigalg.first)
280                     sig->setSignatureAlgorithm(sigalg.second);
281                 sigalg = relyingParty->getXMLString("digestAlg");
282                 if (sigalg.first) {
283                     ContentReference* cr = dynamic_cast<ContentReference*>(sig->getContentReference());
284                     if (cr)
285                         cr->setDigestAlgorithm(sigalg.second);
286                 }
287         
288                 // Sign response while marshalling.
289                 vector<xmlsignature::Signature*> sigs(1,sig);
290                 msg.marshall((DOMDocument*)NULL,&sigs,cred);
291             }
292             else {
293                 m_log.warn("no signing credential resolved, leaving query unsigned");
294             }
295         }
296         else {
297             m_log.warn("no credential resolver installed, leaving query unsigned");
298         }
299     }
300 }
301
302 bool QueryResolver::SAML1Query(QueryContext& ctx) const
303 {
304 #ifdef _DEBUG
305     xmltooling::NDC ndc("query");
306 #endif
307
308     int version = XMLString::equals(ctx.getProtocol(), samlconstants::SAML11_PROTOCOL_ENUM) ? 1 : 0;
309     const AttributeAuthorityDescriptor* AA = ctx.getEntityDescriptor()->getAttributeAuthorityDescriptor(ctx.getProtocol());
310     if (!AA) {
311         m_log.warn("no SAML 1.%d AttributeAuthority role found in metadata", version);
312         return false;
313     }
314
315     shibsp::SecurityPolicy policy(ctx.getApplication());
316     MetadataCredentialCriteria mcc(*AA);
317     shibsp::SOAPClient soaper(policy);
318     const PropertySet* policySettings =
319         ctx.getApplication().getServiceProvider().getPolicySettings(ctx.getApplication().getString("policyId").second);
320     pair<bool,bool> signedAssertions = policySettings->getBool("signedAssertions");
321
322     auto_ptr_XMLCh binding(samlconstants::SAML1_BINDING_SOAP);
323     saml1p::Response* response=NULL;
324     const vector<AttributeService*>& endpoints=AA->getAttributeServices();
325     for (vector<AttributeService*>::const_iterator ep=endpoints.begin(); !response && ep!=endpoints.end(); ++ep) {
326         try {
327             if (!XMLString::equals((*ep)->getBinding(),binding.get()))
328                 continue;
329             auto_ptr_char loc((*ep)->getLocation());
330             auto_ptr_XMLCh issuer(ctx.getApplication().getString("entityID").second);
331             NameIdentifier* nameid = NameIdentifierBuilder::buildNameIdentifier();
332             nameid->setName(ctx.getNameID()->getName());
333             nameid->setFormat(ctx.getNameID()->getFormat());
334             nameid->setNameQualifier(ctx.getNameID()->getNameQualifier());
335             saml1::Subject* subject = saml1::SubjectBuilder::buildSubject();
336             subject->setNameIdentifier(nameid);
337             saml1p::AttributeQuery* query = saml1p::AttributeQueryBuilder::buildAttributeQuery();
338             query->setSubject(subject);
339             query->setResource(issuer.get());
340             for (vector<AttributeDesignator*>::const_iterator ad = m_SAML1Designators.begin(); ad!=m_SAML1Designators.end(); ++ad)
341                 query->getAttributeDesignators().push_back((*ad)->cloneAttributeDesignator());
342             Request* request = RequestBuilder::buildRequest();
343             request->setAttributeQuery(query);
344             request->setMinorVersion(version);
345             signMessage(ctx.getApplication(), *AA, *request);
346
347             SAML1SOAPClient client(soaper, false);
348             client.sendSAML(request, mcc, loc.get());
349             response = client.receiveSAML();
350         }
351         catch (exception& ex) {
352             m_log.error("exception making SAML query: %s", ex.what());
353             soaper.reset();
354         }
355     }
356
357     if (!response) {
358         m_log.error("unable to obtain a SAML response from attribute authority");
359         return false;
360     }
361     else if (!response->getStatus() || !response->getStatus()->getStatusCode() || response->getStatus()->getStatusCode()->getValue()==NULL ||
362             *(response->getStatus()->getStatusCode()->getValue()) != saml1p::StatusCode::SUCCESS) {
363         delete response;
364         m_log.error("attribute authority returned a SAML error");
365         return true;
366     }
367
368     const vector<saml1::Assertion*>& assertions = const_cast<const saml1p::Response*>(response)->getAssertions();
369     if (assertions.empty()) {
370         delete response;
371         m_log.warn("response from attribute authority was empty");
372         return true;
373     }
374     else if (assertions.size()>1)
375         m_log.warn("simple resolver only supports one assertion in the query response");
376
377     auto_ptr<saml1p::Response> wrapper(response);
378     saml1::Assertion* newtoken = assertions.front();
379
380     if (!newtoken->getSignature() && signedAssertions.first && signedAssertions.second) {
381         m_log.error("assertion unsigned, rejecting it based on signedAssertions policy");
382         return true;
383     }
384
385     try {
386         policy.evaluate(*newtoken);
387         if (!policy.isSecure())
388             throw SecurityPolicyException("Security of SAML 1.x query result not established.");
389         saml1::AssertionValidator tokval(ctx.getApplication().getAudiences(), time(NULL));
390         tokval.validateAssertion(*newtoken);
391     }
392     catch (exception& ex) {
393         m_log.error("assertion failed policy/validation: %s", ex.what());
394         return true;
395     }
396
397     newtoken->detach();
398     wrapper.release();
399     ctx.getResolvedAssertions().push_back(newtoken);
400
401     // Finally, extract and filter the result.
402     try {
403         AttributeExtractor* extractor = ctx.getApplication().getAttributeExtractor();
404         if (extractor) {
405             Locker extlocker(extractor);
406             extractor->extractAttributes(ctx.getApplication(), AA, *newtoken, ctx.getResolvedAttributes());
407         }
408
409         AttributeFilter* filter = ctx.getApplication().getAttributeFilter();
410         if (filter) {
411             BasicFilteringContext fc(ctx.getApplication(), ctx.getResolvedAttributes(), AA, ctx.getClassRef(), ctx.getDeclRef());
412             Locker filtlocker(filter);
413             filter->filterAttributes(fc, ctx.getResolvedAttributes());
414         }
415     }
416     catch (exception& ex) {
417         m_log.error("caught exception extracting/filtering attributes from query result: %s", ex.what());
418         for_each(ctx.getResolvedAttributes().begin(), ctx.getResolvedAttributes().end(), xmltooling::cleanup<shibsp::Attribute>());
419         ctx.getResolvedAttributes().clear();
420     }
421
422     return true;
423 }
424
425 bool QueryResolver::SAML2Query(QueryContext& ctx) const
426 {
427 #ifdef _DEBUG
428     xmltooling::NDC ndc("query");
429 #endif
430
431     const AttributeAuthorityDescriptor* AA = ctx.getEntityDescriptor()->getAttributeAuthorityDescriptor(samlconstants::SAML20P_NS);
432     if (!AA) {
433         m_log.warn("no SAML 2 AttributeAuthority role found in metadata");
434         return false;
435     }
436
437     shibsp::SecurityPolicy policy(ctx.getApplication());
438     MetadataCredentialCriteria mcc(*AA);
439     shibsp::SOAPClient soaper(policy);
440     const PropertySet* policySettings =
441         ctx.getApplication().getServiceProvider().getPolicySettings(ctx.getApplication().getString("policyId").second);
442     pair<bool,bool> signedAssertions = policySettings->getBool("signedAssertions");
443
444     const PropertySet* relyingParty = ctx.getApplication().getRelyingParty(ctx.getEntityDescriptor());
445     pair<bool,const char*> encryption = relyingParty->getString("encryption");
446
447     auto_ptr_XMLCh binding(samlconstants::SAML20_BINDING_SOAP);
448     saml2p::StatusResponseType* srt=NULL;
449     const vector<AttributeService*>& endpoints=AA->getAttributeServices();
450     for (vector<AttributeService*>::const_iterator ep=endpoints.begin(); !srt && ep!=endpoints.end(); ++ep) {
451         try {
452             if (!XMLString::equals((*ep)->getBinding(),binding.get()))
453                 continue;
454             auto_ptr_char loc((*ep)->getLocation());
455             auto_ptr_XMLCh issuer(ctx.getApplication().getString("entityID").second);
456
457             auto_ptr<saml2::Subject> subject(saml2::SubjectBuilder::buildSubject());
458
459             // Encrypt the NameID?
460             if (encryption.first && (!strcmp(encryption.second, "true") || !strcmp(encryption.second, "back"))) {
461                 auto_ptr<EncryptedID> encrypted(EncryptedIDBuilder::buildEncryptedID());
462                 MetadataCredentialCriteria mcc(*AA);
463                 encrypted->encrypt(
464                     *ctx.getNameID(),
465                     *(ctx.getApplication().getMetadataProvider()),
466                     mcc,
467                     false,
468                     relyingParty->getXMLString("encryptionAlg").second
469                     );
470                 subject->setEncryptedID(encrypted.release());
471             }
472             else {
473                 subject->setNameID(ctx.getNameID()->cloneNameID());
474             }
475
476             saml2p::AttributeQuery* query = saml2p::AttributeQueryBuilder::buildAttributeQuery();
477             query->setSubject(subject.release());
478             Issuer* iss = IssuerBuilder::buildIssuer();
479             iss->setName(issuer.get());
480             query->setIssuer(iss);
481             for (vector<saml2::Attribute*>::const_iterator ad = m_SAML2Designators.begin(); ad!=m_SAML2Designators.end(); ++ad)
482                 query->getAttributes().push_back((*ad)->cloneAttribute());
483             signMessage(ctx.getApplication(), *AA, *query);
484
485             SAML2SOAPClient client(soaper, false);
486             client.sendSAML(query, mcc, loc.get());
487             srt = client.receiveSAML();
488         }
489         catch (exception& ex) {
490             m_log.error("exception making SAML query: %s", ex.what());
491             soaper.reset();
492         }
493     }
494
495     if (!srt) {
496         m_log.error("unable to obtain a SAML response from attribute authority");
497         return false;
498     }
499     saml2p::Response* response = dynamic_cast<saml2p::Response*>(srt);
500     if (!response) {
501         delete srt;
502         m_log.error("message was not a samlp:Response");
503         return true;
504     }
505     else if (!response->getStatus() || !response->getStatus()->getStatusCode() ||
506             !XMLString::equals(response->getStatus()->getStatusCode()->getValue(), saml2p::StatusCode::SUCCESS)) {
507         delete srt;
508         m_log.error("attribute authority returned a SAML error");
509         return true;
510     }
511
512     const vector<saml2::Assertion*>& assertions = const_cast<const saml2p::Response*>(response)->getAssertions();
513     if (assertions.empty()) {
514         delete srt;
515         m_log.warn("response from attribute authority was empty");
516         return true;
517     }
518     else if (assertions.size()>1)
519         m_log.warn("simple resolver only supports one assertion in the query response");
520
521     auto_ptr<saml2p::StatusResponseType> wrapper(srt);
522     saml2::Assertion* newtoken = assertions.front();
523
524     if (!newtoken->getSignature() && signedAssertions.first && signedAssertions.second) {
525         m_log.error("assertion unsigned, rejecting it based on signedAssertions policy");
526         return true;
527     }
528
529     try {
530         policy.evaluate(*newtoken);
531         if (!policy.isSecure())
532             throw SecurityPolicyException("Security of SAML 2.0 query result not established.");
533         saml2::AssertionValidator tokval(ctx.getApplication().getAudiences(), time(NULL));
534         tokval.validateAssertion(*newtoken);
535     }
536     catch (exception& ex) {
537         m_log.error("assertion failed policy/validation: %s", ex.what());
538         return true;
539     }
540
541     newtoken->detach();
542     wrapper.release();
543     ctx.getResolvedAssertions().push_back(newtoken);
544
545     // Finally, extract and filter the result.
546     try {
547         AttributeExtractor* extractor = ctx.getApplication().getAttributeExtractor();
548         if (extractor) {
549             Locker extlocker(extractor);
550             extractor->extractAttributes(ctx.getApplication(), AA, *newtoken, ctx.getResolvedAttributes());
551         }
552
553         AttributeFilter* filter = ctx.getApplication().getAttributeFilter();
554         if (filter) {
555             BasicFilteringContext fc(ctx.getApplication(), ctx.getResolvedAttributes(), AA, ctx.getClassRef(), ctx.getDeclRef());
556             Locker filtlocker(filter);
557             filter->filterAttributes(fc, ctx.getResolvedAttributes());
558         }
559     }
560     catch (exception& ex) {
561         m_log.error("caught exception extracting/filtering attributes from query result: %s", ex.what());
562         for_each(ctx.getResolvedAttributes().begin(), ctx.getResolvedAttributes().end(), xmltooling::cleanup<shibsp::Attribute>());
563         ctx.getResolvedAttributes().clear();
564     }
565
566     return true;
567 }
568
569 void QueryResolver::resolveAttributes(ResolutionContext& ctx) const
570 {
571 #ifdef _DEBUG
572     xmltooling::NDC ndc("resolveAttributes");
573 #endif
574
575     QueryContext& qctx = dynamic_cast<QueryContext&>(ctx);
576     if (!qctx.doQuery()) {
577         m_log.debug("found AttributeStatement in input to new session, skipping query");
578         return;
579     }
580
581     if (qctx.getNameID() && qctx.getEntityDescriptor()) {
582         if (XMLString::equals(qctx.getProtocol(), samlconstants::SAML20P_NS)) {
583             m_log.debug("attempting SAML 2.0 attribute query");
584             SAML2Query(qctx);
585         }
586         else if (XMLString::equals(qctx.getProtocol(), samlconstants::SAML11_PROTOCOL_ENUM) ||
587                 XMLString::equals(qctx.getProtocol(), samlconstants::SAML10_PROTOCOL_ENUM)) {
588             m_log.debug("attempting SAML 1.x attribute query");
589             SAML1Query(qctx);
590         }
591         else
592             m_log.warn("SSO protocol does not allow for attribute query");
593     }
594     else
595         m_log.warn("can't attempt attribute query, either no NameID or no metadata to use");
596 }