2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * QueryAttributeResolver.cpp
24 * AttributeResolver based on SAML queries.
28 #include "Application.h"
29 #include "ServiceProvider.h"
30 #include "SessionCache.h"
31 #include "attribute/SimpleAttribute.h"
32 #include "attribute/filtering/AttributeFilter.h"
33 #include "attribute/filtering/BasicFilteringContext.h"
34 #include "attribute/resolver/AttributeExtractor.h"
35 #include "attribute/resolver/AttributeResolver.h"
36 #include "attribute/resolver/ResolutionContext.h"
37 #include "binding/SOAPClient.h"
38 #include "metadata/MetadataProviderCriteria.h"
39 #include "security/SecurityPolicy.h"
40 #include "security/SecurityPolicyProvider.h"
41 #include "util/SPConstants.h"
43 #include <boost/iterator/indirect_iterator.hpp>
44 #include <boost/ptr_container/ptr_vector.hpp>
45 #include <saml/exceptions.h>
46 #include <saml/saml1/binding/SAML1SOAPClient.h>
47 #include <saml/saml1/core/Assertions.h>
48 #include <saml/saml1/core/Protocols.h>
49 #include <saml/saml2/binding/SAML2SOAPClient.h>
50 #include <saml/saml2/core/Protocols.h>
51 #include <saml/saml2/metadata/Metadata.h>
52 #include <saml/saml2/metadata/MetadataCredentialCriteria.h>
53 #include <saml/saml2/metadata/MetadataProvider.h>
54 #include <xmltooling/XMLToolingConfig.h>
55 #include <xmltooling/util/NDC.h>
56 #include <xmltooling/util/URLEncoder.h>
57 #include <xmltooling/util/XMLHelper.h>
58 #include <xercesc/util/XMLUniDefs.hpp>
60 using namespace shibsp;
61 using namespace opensaml::saml1;
62 using namespace opensaml::saml1p;
63 using namespace opensaml::saml2;
64 using namespace opensaml::saml2p;
65 using namespace opensaml::saml2md;
66 using namespace opensaml;
67 using namespace xmltooling;
68 using namespace boost;
73 class SHIBSP_DLLLOCAL QueryContext : public ResolutionContext
76 QueryContext(const Application& application, const Session& session)
77 : m_query(true), m_app(application), m_session(&session), m_metadata(nullptr), m_entity(nullptr), m_nameid(nullptr) {
78 m_protocol = XMLString::transcode(session.getProtocol());
79 m_class = XMLString::transcode(session.getAuthnContextClassRef());
80 m_decl = XMLString::transcode(session.getAuthnContextDeclRef());
84 const Application& application,
85 const EntityDescriptor* issuer,
86 const XMLCh* protocol,
87 const NameID* nameid=nullptr,
88 const XMLCh* authncontext_class=nullptr,
89 const XMLCh* authncontext_decl=nullptr,
90 const vector<const opensaml::Assertion*>* tokens=nullptr
91 ) : m_query(true), m_app(application), m_session(nullptr), m_metadata(nullptr), m_entity(issuer),
92 m_protocol(protocol), m_nameid(nameid), m_class(authncontext_class), m_decl(authncontext_decl) {
95 for (vector<const opensaml::Assertion*>::const_iterator t = tokens->begin(); t!=tokens->end(); ++t) {
96 const saml2::Assertion* token2 = dynamic_cast<const saml2::Assertion*>(*t);
97 if (token2 && !token2->getAttributeStatements().empty()) {
101 const saml1::Assertion* token1 = dynamic_cast<const saml1::Assertion*>(*t);
102 if (token1 && !token1->getAttributeStatements().empty()) {
112 XMLString::release((XMLCh**)&m_protocol);
113 XMLString::release((XMLCh**)&m_class);
114 XMLString::release((XMLCh**)&m_decl);
117 m_metadata->unlock();
118 for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<shibsp::Attribute>());
119 for_each(m_assertions.begin(), m_assertions.end(), xmltooling::cleanup<opensaml::Assertion>());
122 bool doQuery() const {
126 const Application& getApplication() const {
129 const EntityDescriptor* getEntityDescriptor() const {
132 if (m_session && m_session->getEntityID()) {
133 m_metadata = m_app.getMetadataProvider(false);
136 return m_entity = m_metadata->getEntityDescriptor(MetadataProviderCriteria(m_app, m_session->getEntityID())).first;
141 const XMLCh* getProtocol() const {
144 const NameID* getNameID() const {
145 return m_session ? m_session->getNameID() : m_nameid;
147 const XMLCh* getClassRef() const {
150 const XMLCh* getDeclRef() const {
153 const Session* getSession() const {
156 vector<shibsp::Attribute*>& getResolvedAttributes() {
159 vector<opensaml::Assertion*>& getResolvedAssertions() {
165 const Application& m_app;
166 const Session* m_session;
167 mutable MetadataProvider* m_metadata;
168 mutable const EntityDescriptor* m_entity;
169 const XMLCh* m_protocol;
170 const NameID* m_nameid;
171 const XMLCh* m_class;
173 vector<shibsp::Attribute*> m_attributes;
174 vector<opensaml::Assertion*> m_assertions;
177 class SHIBSP_DLLLOCAL QueryResolver : public AttributeResolver
180 QueryResolver(const DOMElement* e);
183 Lockable* lock() {return this;}
186 ResolutionContext* createResolutionContext(
187 const Application& application,
188 const EntityDescriptor* issuer,
189 const XMLCh* protocol,
190 const NameID* nameid=nullptr,
191 const XMLCh* authncontext_class=nullptr,
192 const XMLCh* authncontext_decl=nullptr,
193 const vector<const opensaml::Assertion*>* tokens=nullptr,
194 const vector<shibsp::Attribute*>* attributes=nullptr
196 return new QueryContext(application,issuer,protocol,nameid,authncontext_class,authncontext_decl,tokens);
199 ResolutionContext* createResolutionContext(const Application& application, const Session& session) const {
200 return new QueryContext(application,session);
203 void resolveAttributes(ResolutionContext& ctx) const;
205 void getAttributeIds(vector<string>& attributes) const {
206 // Nothing to do, only the extractor would actually generate them.
210 void SAML1Query(QueryContext& ctx) const;
211 void SAML2Query(QueryContext& ctx) const;
216 ptr_vector<AttributeDesignator> m_SAML1Designators;
217 ptr_vector<saml2::Attribute> m_SAML2Designators;
218 vector<string> m_exceptionId;
221 AttributeResolver* SHIBSP_DLLLOCAL QueryResolverFactory(const DOMElement* const & e)
223 return new QueryResolver(e);
226 static const XMLCh exceptionId[] = UNICODE_LITERAL_11(e,x,c,e,p,t,i,o,n,I,d);
227 static const XMLCh policyId[] = UNICODE_LITERAL_8(p,o,l,i,c,y,I,d);
228 static const XMLCh subjectMatch[] = UNICODE_LITERAL_12(s,u,b,j,e,c,t,M,a,t,c,h);
231 QueryResolver::QueryResolver(const DOMElement* e)
232 : m_log(Category::getInstance(SHIBSP_LOGCAT".AttributeResolver.Query")),
233 m_policyId(XMLHelper::getAttrString(e, nullptr, policyId)),
234 m_subjectMatch(XMLHelper::getAttrBool(e, false, subjectMatch))
237 xmltooling::NDC ndc("QueryResolver");
240 DOMElement* child = XMLHelper::getFirstChildElement(e);
243 if (XMLHelper::isNodeNamed(child, samlconstants::SAML20_NS, saml2::Attribute::LOCAL_NAME)) {
244 auto_ptr<XMLObject> obj(saml2::AttributeBuilder::buildOneFromElement(child));
245 saml2::Attribute* down = dynamic_cast<saml2::Attribute*>(obj.get());
247 m_SAML2Designators.push_back(down);
251 else if (XMLHelper::isNodeNamed(child, samlconstants::SAML1_NS, AttributeDesignator::LOCAL_NAME)) {
252 auto_ptr<XMLObject> obj(AttributeDesignatorBuilder::buildOneFromElement(child));
253 AttributeDesignator* down = dynamic_cast<AttributeDesignator*>(obj.get());
255 m_SAML1Designators.push_back(down);
260 catch (exception& ex) {
261 m_log.error("exception loading attribute designator: %s", ex.what());
263 child = XMLHelper::getNextSiblingElement(child);
266 string exid(XMLHelper::getAttrString(e, nullptr, exceptionId));
268 m_exceptionId.push_back(exid);
271 void QueryResolver::SAML1Query(QueryContext& ctx) const
274 xmltooling::NDC ndc("query");
277 int version = XMLString::equals(ctx.getProtocol(), samlconstants::SAML11_PROTOCOL_ENUM) ? 1 : 0;
278 const AttributeAuthorityDescriptor* AA =
279 find_if(ctx.getEntityDescriptor()->getAttributeAuthorityDescriptors(), isValidForProtocol(ctx.getProtocol()));
281 m_log.warn("no SAML 1.%d AttributeAuthority role found in metadata", version);
285 const Application& application = ctx.getApplication();
286 const PropertySet* relyingParty = application.getRelyingParty(ctx.getEntityDescriptor());
288 // Locate policy key.
289 const char* policyId = m_policyId.empty() ? application.getString("policyId").second : m_policyId.c_str();
291 // Set up policy and SOAP client.
292 scoped_ptr<SecurityPolicy> policy(
293 application.getServiceProvider().getSecurityPolicyProvider()->createSecurityPolicy(application, nullptr, policyId)
295 policy->getAudiences().push_back(relyingParty->getXMLString("entityID").second);
296 MetadataCredentialCriteria mcc(*AA);
297 shibsp::SOAPClient soaper(*policy);
299 auto_ptr_XMLCh binding(samlconstants::SAML1_BINDING_SOAP);
300 auto_ptr<saml1p::Response> response;
301 const vector<AttributeService*>& endpoints=AA->getAttributeServices();
302 for (indirect_iterator<vector<AttributeService*>::const_iterator> ep = make_indirect_iterator(endpoints.begin());
303 !response.get() && ep != make_indirect_iterator(endpoints.end()); ++ep) {
304 if (!XMLString::equals(ep->getBinding(), binding.get()) || !ep->getLocation())
306 auto_ptr_char loc(ep->getLocation());
308 NameIdentifier* nameid = NameIdentifierBuilder::buildNameIdentifier();
309 nameid->setName(ctx.getNameID()->getName());
310 nameid->setFormat(ctx.getNameID()->getFormat());
311 nameid->setNameQualifier(ctx.getNameID()->getNameQualifier());
312 saml1::Subject* subject = saml1::SubjectBuilder::buildSubject();
313 subject->setNameIdentifier(nameid);
314 saml1p::AttributeQuery* query = saml1p::AttributeQueryBuilder::buildAttributeQuery();
315 query->setSubject(subject);
316 query->setResource(relyingParty->getXMLString("entityID").second);
317 for (ptr_vector<AttributeDesignator>::const_iterator ad = m_SAML1Designators.begin(); ad != m_SAML1Designators.end(); ++ad) {
318 auto_ptr<AttributeDesignator> adwrapper(ad->cloneAttributeDesignator());
319 query->getAttributeDesignators().push_back(adwrapper.get());
322 Request* request = RequestBuilder::buildRequest();
323 request->setAttributeQuery(query);
324 request->setMinorVersion(version);
326 SAML1SOAPClient client(soaper, false);
327 client.sendSAML(request, application.getId(), mcc, loc.get());
328 response.reset(client.receiveSAML());
330 catch (exception& ex) {
331 m_log.error("exception during SAML query to %s: %s", loc.get(), ex.what());
336 if (!response.get()) {
337 m_log.error("unable to obtain a SAML response from attribute authority");
338 throw BindingException("Unable to obtain a SAML response from attribute authority.");
340 else if (!response->getStatus() || !response->getStatus()->getStatusCode() || response->getStatus()->getStatusCode()->getValue()==nullptr ||
341 *(response->getStatus()->getStatusCode()->getValue()) != saml1p::StatusCode::SUCCESS) {
342 m_log.error("attribute authority returned a SAML error");
343 throw FatalProfileException("Attribute authority returned a SAML error.");
346 const vector<saml1::Assertion*>& assertions = const_cast<const saml1p::Response*>(response.get())->getAssertions();
347 if (assertions.empty()) {
348 m_log.warn("response from attribute authority was empty");
351 else if (assertions.size() > 1) {
352 m_log.warn("simple resolver only supports one assertion in the query response");
355 saml1::Assertion* newtoken = assertions.front();
357 pair<bool,bool> signedAssertions = relyingParty->getBool("requireSignedAssertions");
358 if (!newtoken->getSignature() && signedAssertions.first && signedAssertions.second) {
359 m_log.error("assertion unsigned, rejecting it based on signedAssertions policy");
360 throw SecurityPolicyException("Rejected unsigned assertion based on local policy.");
364 // We're going to insist that the assertion issuer is the same as the peer.
365 // Reset the policy's message bits and extract them from the assertion.
367 policy->setMessageID(newtoken->getAssertionID());
368 policy->setIssueInstant(newtoken->getIssueInstantEpoch());
369 policy->setIssuer(newtoken->getIssuer());
370 policy->evaluate(*newtoken);
372 // Now we can check the security status of the policy.
373 if (!policy->isAuthenticated())
374 throw SecurityPolicyException("Security of SAML 1.x query result not established.");
376 catch (exception& ex) {
377 m_log.error("assertion failed policy validation: %s", ex.what());
382 response.release(); // detach blows away the Response
383 ctx.getResolvedAssertions().push_back(newtoken);
385 // Finally, extract and filter the result.
387 AttributeExtractor* extractor = application.getAttributeExtractor();
389 Locker extlocker(extractor);
390 const vector<saml1::AttributeStatement*>& statements = const_cast<const saml1::Assertion*>(newtoken)->getAttributeStatements();
391 for (indirect_iterator<vector<saml1::AttributeStatement*>::const_iterator> s = make_indirect_iterator(statements.begin());
392 s != make_indirect_iterator(statements.end()); ++s) {
393 if (m_subjectMatch) {
394 // Check for subject match.
395 const NameIdentifier* respName = s->getSubject() ? s->getSubject()->getNameIdentifier() : nullptr;
396 if (!respName || !XMLString::equals(respName->getName(), ctx.getNameID()->getName()) ||
397 !XMLString::equals(respName->getFormat(), ctx.getNameID()->getFormat()) ||
398 !XMLString::equals(respName->getNameQualifier(), ctx.getNameID()->getNameQualifier())) {
400 m_log.warnStream() << "ignoring AttributeStatement without strongly matching NameIdentifier in Subject: " <<
401 *respName << logging::eol;
403 m_log.warn("ignoring AttributeStatement without NameIdentifier in Subject");
407 extractor->extractAttributes(application, AA, *s, ctx.getResolvedAttributes());
411 AttributeFilter* filter = application.getAttributeFilter();
413 BasicFilteringContext fc(application, ctx.getResolvedAttributes(), AA, ctx.getClassRef(), ctx.getDeclRef());
414 Locker filtlocker(filter);
415 filter->filterAttributes(fc, ctx.getResolvedAttributes());
418 catch (exception& ex) {
419 m_log.error("caught exception extracting/filtering attributes from query result: %s", ex.what());
420 for_each(ctx.getResolvedAttributes().begin(), ctx.getResolvedAttributes().end(), xmltooling::cleanup<shibsp::Attribute>());
421 ctx.getResolvedAttributes().clear();
426 void QueryResolver::SAML2Query(QueryContext& ctx) const
429 xmltooling::NDC ndc("query");
432 const AttributeAuthorityDescriptor* AA =
433 find_if(ctx.getEntityDescriptor()->getAttributeAuthorityDescriptors(), isValidForProtocol(samlconstants::SAML20P_NS));
435 m_log.warn("no SAML 2 AttributeAuthority role found in metadata");
439 const Application& application = ctx.getApplication();
440 const PropertySet* relyingParty = application.getRelyingParty(ctx.getEntityDescriptor());
441 pair<bool,bool> signedAssertions = relyingParty->getBool("requireSignedAssertions");
442 pair<bool,const char*> encryption = relyingParty->getString("encryption");
444 // Locate policy key.
445 const char* policyId = m_policyId.empty() ? application.getString("policyId").second : m_policyId.c_str();
447 // Set up policy and SOAP client.
448 scoped_ptr<SecurityPolicy> policy(
449 application.getServiceProvider().getSecurityPolicyProvider()->createSecurityPolicy(application, nullptr, policyId)
451 policy->getAudiences().push_back(relyingParty->getXMLString("entityID").second);
452 MetadataCredentialCriteria mcc(*AA);
453 shibsp::SOAPClient soaper(*policy);
455 auto_ptr_XMLCh binding(samlconstants::SAML20_BINDING_SOAP);
456 auto_ptr<saml2p::StatusResponseType> srt;
457 const vector<AttributeService*>& endpoints=AA->getAttributeServices();
458 for (indirect_iterator<vector<AttributeService*>::const_iterator> ep = make_indirect_iterator(endpoints.begin());
459 !srt.get() && ep != make_indirect_iterator(endpoints.end()); ++ep) {
460 if (!XMLString::equals(ep->getBinding(), binding.get()) || !ep->getLocation())
462 auto_ptr_char loc(ep->getLocation());
464 auto_ptr<saml2::Subject> subject(saml2::SubjectBuilder::buildSubject());
466 // Encrypt the NameID?
467 if (encryption.first && (!strcmp(encryption.second, "true") || !strcmp(encryption.second, "back"))) {
468 auto_ptr<EncryptedID> encrypted(EncryptedIDBuilder::buildEncryptedID());
471 *(application.getMetadataProvider()),
474 relyingParty->getXMLString("encryptionAlg").second
476 subject->setEncryptedID(encrypted.get());
480 auto_ptr<NameID> namewrapper(ctx.getNameID()->cloneNameID());
481 subject->setNameID(namewrapper.get());
482 namewrapper.release();
485 saml2p::AttributeQuery* query = saml2p::AttributeQueryBuilder::buildAttributeQuery();
486 query->setSubject(subject.release());
487 Issuer* iss = IssuerBuilder::buildIssuer();
488 iss->setName(relyingParty->getXMLString("entityID").second);
489 query->setIssuer(iss);
490 for (ptr_vector<saml2::Attribute>::const_iterator ad = m_SAML2Designators.begin(); ad != m_SAML2Designators.end(); ++ad) {
491 auto_ptr<saml2::Attribute> adwrapper(ad->cloneAttribute());
492 query->getAttributes().push_back(adwrapper.get());
496 SAML2SOAPClient client(soaper, false);
497 client.sendSAML(query, application.getId(), mcc, loc.get());
498 srt.reset(client.receiveSAML());
500 catch (exception& ex) {
501 m_log.error("exception during SAML query to %s: %s", loc.get(), ex.what());
507 m_log.error("unable to obtain a SAML response from attribute authority");
508 throw BindingException("Unable to obtain a SAML response from attribute authority.");
511 saml2p::Response* response = dynamic_cast<saml2p::Response*>(srt.get());
513 m_log.error("message was not a samlp:Response");
514 throw FatalProfileException("Attribute authority returned an unrecognized message.");
516 else if (!response->getStatus() || !response->getStatus()->getStatusCode() ||
517 !XMLString::equals(response->getStatus()->getStatusCode()->getValue(), saml2p::StatusCode::SUCCESS)) {
518 m_log.error("attribute authority returned a SAML error");
519 throw FatalProfileException("Attribute authority returned a SAML error.");
522 saml2::Assertion* newtoken = nullptr;
523 auto_ptr<saml2::Assertion> newtokenwrapper;
524 const vector<saml2::Assertion*>& assertions = const_cast<const saml2p::Response*>(response)->getAssertions();
525 if (assertions.empty()) {
526 // Check for encryption.
527 const vector<saml2::EncryptedAssertion*>& encassertions = const_cast<const saml2p::Response*>(response)->getEncryptedAssertions();
528 if (encassertions.empty()) {
529 m_log.warn("response from attribute authority was empty");
532 else if (encassertions.size() > 1) {
533 m_log.warn("simple resolver only supports one assertion in the query response");
536 CredentialResolver* cr = application.getCredentialResolver();
538 m_log.warn("found encrypted assertion, but no CredentialResolver was available");
539 throw FatalProfileException("Assertion was encrypted, but no decryption credentials are available.");
542 // With this flag on, we block unauthenticated ciphertext when decrypting,
543 // unless the protocol was authenticated.
544 pair<bool,bool> authenticatedCipher = application.getBool("requireAuthenticatedCipher");
545 if (policy->isAuthenticated())
546 authenticatedCipher.second = false;
548 // Attempt to decrypt it.
550 Locker credlocker(cr);
551 auto_ptr<XMLObject> tokenwrapper(
552 encassertions.front()->decrypt(
553 *cr, relyingParty->getXMLString("entityID").second, &mcc, authenticatedCipher.first && authenticatedCipher.second
556 newtoken = dynamic_cast<saml2::Assertion*>(tokenwrapper.get());
558 tokenwrapper.release();
559 newtokenwrapper.reset(newtoken);
560 if (m_log.isDebugEnabled())
561 m_log.debugStream() << "decrypted Assertion: " << *newtoken << logging::eol;
564 catch (exception& ex) {
565 m_log.error(ex.what());
570 if (assertions.size() > 1)
571 m_log.warn("simple resolver only supports one assertion in the query response");
572 newtoken = assertions.front();
575 if (!newtoken->getSignature() && signedAssertions.first && signedAssertions.second) {
576 m_log.error("assertion unsigned, rejecting it based on signedAssertions policy");
577 throw SecurityPolicyException("Rejected unsigned assertion based on local policy.");
581 // We're going to insist that the assertion issuer is the same as the peer.
582 // Reset the policy's message bits and extract them from the assertion.
584 policy->setMessageID(newtoken->getID());
585 policy->setIssueInstant(newtoken->getIssueInstantEpoch());
586 policy->setIssuer(newtoken->getIssuer());
587 policy->evaluate(*newtoken);
589 // Now we can check the security status of the policy.
590 if (!policy->isAuthenticated())
591 throw SecurityPolicyException("Security of SAML 2.0 query result not established.");
593 if (m_subjectMatch) {
594 // Check for subject match.
595 auto_ptr<NameID> nameIDwrapper;
596 NameID* respName = newtoken->getSubject() ? newtoken->getSubject()->getNameID() : nullptr;
598 // Check for encryption.
599 EncryptedID* encname = newtoken->getSubject() ? newtoken->getSubject()->getEncryptedID() : nullptr;
601 CredentialResolver* cr=application.getCredentialResolver();
603 m_log.warn("found EncryptedID, but no CredentialResolver was available");
605 Locker credlocker(cr);
606 auto_ptr<XMLObject> decryptedID(encname->decrypt(*cr, relyingParty->getXMLString("entityID").second, &mcc));
607 respName = dynamic_cast<NameID*>(decryptedID.get());
609 decryptedID.release();
610 nameIDwrapper.reset(respName);
611 if (m_log.isDebugEnabled())
612 m_log.debugStream() << "decrypted NameID: " << *respName << logging::eol;
618 if (!respName || !XMLString::equals(respName->getName(), ctx.getNameID()->getName()) ||
619 !XMLString::equals(respName->getFormat(), ctx.getNameID()->getFormat()) ||
620 !XMLString::equals(respName->getNameQualifier(), ctx.getNameID()->getNameQualifier()) ||
621 !XMLString::equals(respName->getSPNameQualifier(), ctx.getNameID()->getSPNameQualifier())) {
623 m_log.warnStream() << "ignoring Assertion without strongly matching NameID in Subject: " <<
624 *respName << logging::eol;
626 m_log.warn("ignoring Assertion without NameID in Subject");
631 catch (exception& ex) {
632 m_log.error("assertion failed policy validation: %s", ex.what());
636 // If the token's embedded, detach it.
637 if (!newtokenwrapper.get()) {
639 srt.release(); // detach blows away the Response, so avoid a double free
640 newtokenwrapper.reset(newtoken);
642 ctx.getResolvedAssertions().push_back(newtoken);
643 newtokenwrapper.release();
645 // Finally, extract and filter the result.
647 AttributeExtractor* extractor = application.getAttributeExtractor();
649 Locker extlocker(extractor);
650 extractor->extractAttributes(application, AA, *newtoken, ctx.getResolvedAttributes());
653 AttributeFilter* filter = application.getAttributeFilter();
655 BasicFilteringContext fc(application, ctx.getResolvedAttributes(), AA, ctx.getClassRef(), ctx.getDeclRef());
656 Locker filtlocker(filter);
657 filter->filterAttributes(fc, ctx.getResolvedAttributes());
660 catch (exception& ex) {
661 m_log.error("caught exception extracting/filtering attributes from query result: %s", ex.what());
662 for_each(ctx.getResolvedAttributes().begin(), ctx.getResolvedAttributes().end(), xmltooling::cleanup<shibsp::Attribute>());
663 ctx.getResolvedAttributes().clear();
668 void QueryResolver::resolveAttributes(ResolutionContext& ctx) const
671 xmltooling::NDC ndc("resolveAttributes");
674 QueryContext& qctx = dynamic_cast<QueryContext&>(ctx);
675 if (!qctx.doQuery()) {
676 m_log.debug("found AttributeStatement in input to new session, skipping query");
681 if (qctx.getNameID() && qctx.getEntityDescriptor()) {
682 if (XMLString::equals(qctx.getProtocol(), samlconstants::SAML20P_NS)) {
683 m_log.debug("attempting SAML 2.0 attribute query");
686 else if (XMLString::equals(qctx.getProtocol(), samlconstants::SAML11_PROTOCOL_ENUM) ||
687 XMLString::equals(qctx.getProtocol(), samlconstants::SAML10_PROTOCOL_ENUM)) {
688 m_log.debug("attempting SAML 1.x attribute query");
692 m_log.info("SSO protocol does not allow for attribute query");
696 m_log.warn("can't attempt attribute query, either no NameID or no metadata to use");
699 catch (exception& ex) {
701 if (!m_exceptionId.empty()) {
702 auto_ptr<SimpleAttribute> attr(new SimpleAttribute(m_exceptionId));
703 attr->getValues().push_back(XMLToolingConfig::getConfig().getURLEncoder()->encode(ex.what()));
704 qctx.getResolvedAttributes().push_back(attr.get());