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_request(nullptr), 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 GenericRequest* request,
86 const EntityDescriptor* issuer,
87 const XMLCh* protocol,
88 const NameID* nameid=nullptr,
89 const XMLCh* authncontext_class=nullptr,
90 const XMLCh* authncontext_decl=nullptr,
91 const vector<const opensaml::Assertion*>* tokens=nullptr
92 ) : m_query(true), m_app(application), m_request(request), m_session(nullptr), m_metadata(nullptr), m_entity(issuer),
93 m_protocol(protocol), m_nameid(nameid), m_class(authncontext_class), m_decl(authncontext_decl) {
96 for (vector<const opensaml::Assertion*>::const_iterator t = tokens->begin(); t!=tokens->end(); ++t) {
97 const saml2::Assertion* token2 = dynamic_cast<const saml2::Assertion*>(*t);
98 if (token2 && !token2->getAttributeStatements().empty()) {
102 const saml1::Assertion* token1 = dynamic_cast<const saml1::Assertion*>(*t);
103 if (token1 && !token1->getAttributeStatements().empty()) {
113 XMLString::release((XMLCh**)&m_protocol);
114 XMLString::release((XMLCh**)&m_class);
115 XMLString::release((XMLCh**)&m_decl);
118 m_metadata->unlock();
119 for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<shibsp::Attribute>());
120 for_each(m_assertions.begin(), m_assertions.end(), xmltooling::cleanup<opensaml::Assertion>());
123 bool doQuery() const {
127 const Application& getApplication() const {
130 const GenericRequest* getRequest() const {
133 const EntityDescriptor* getEntityDescriptor() const {
136 if (m_session && m_session->getEntityID()) {
137 m_metadata = m_app.getMetadataProvider(false);
140 return m_entity = m_metadata->getEntityDescriptor(MetadataProviderCriteria(m_app, m_session->getEntityID())).first;
145 const XMLCh* getProtocol() const {
148 const NameID* getNameID() const {
149 return m_session ? m_session->getNameID() : m_nameid;
151 const XMLCh* getClassRef() const {
154 const XMLCh* getDeclRef() const {
157 const Session* getSession() const {
160 vector<shibsp::Attribute*>& getResolvedAttributes() {
163 vector<opensaml::Assertion*>& getResolvedAssertions() {
169 const Application& m_app;
170 const GenericRequest* m_request;
171 const Session* m_session;
172 mutable MetadataProvider* m_metadata;
173 mutable const EntityDescriptor* m_entity;
174 const XMLCh* m_protocol;
175 const NameID* m_nameid;
176 const XMLCh* m_class;
178 vector<shibsp::Attribute*> m_attributes;
179 vector<opensaml::Assertion*> m_assertions;
182 class SHIBSP_DLLLOCAL QueryResolver : public AttributeResolver
185 QueryResolver(const DOMElement* e);
188 Lockable* lock() {return this;}
192 ResolutionContext* createResolutionContext(
193 const Application& application,
194 const EntityDescriptor* issuer,
195 const XMLCh* protocol,
196 const NameID* nameid=nullptr,
197 const XMLCh* authncontext_class=nullptr,
198 const XMLCh* authncontext_decl=nullptr,
199 const vector<const opensaml::Assertion*>* tokens=nullptr,
200 const vector<shibsp::Attribute*>* attributes=nullptr
202 return createResolutionContext(application, nullptr, issuer, protocol, nameid, authncontext_class, authncontext_decl, tokens);
205 ResolutionContext* createResolutionContext(
206 const Application& application,
207 const GenericRequest* request,
208 const EntityDescriptor* issuer,
209 const XMLCh* protocol,
210 const NameID* nameid=nullptr,
211 const XMLCh* authncontext_class=nullptr,
212 const XMLCh* authncontext_decl=nullptr,
213 const vector<const opensaml::Assertion*>* tokens=nullptr,
214 const vector<shibsp::Attribute*>* attributes=nullptr
216 return new QueryContext(application, request, issuer, protocol, nameid, authncontext_class, authncontext_decl, tokens);
219 ResolutionContext* createResolutionContext(const Application& application, const Session& session) const {
220 return new QueryContext(application,session);
223 void resolveAttributes(ResolutionContext& ctx) const;
225 void getAttributeIds(vector<string>& attributes) const {
226 // Nothing to do, only the extractor would actually generate them.
230 void SAML1Query(QueryContext& ctx) const;
231 void SAML2Query(QueryContext& ctx) const;
236 ptr_vector<AttributeDesignator> m_SAML1Designators;
237 ptr_vector<saml2::Attribute> m_SAML2Designators;
238 vector<string> m_exceptionId;
241 AttributeResolver* SHIBSP_DLLLOCAL QueryResolverFactory(const DOMElement* const & e)
243 return new QueryResolver(e);
246 static const XMLCh exceptionId[] = UNICODE_LITERAL_11(e,x,c,e,p,t,i,o,n,I,d);
247 static const XMLCh policyId[] = UNICODE_LITERAL_8(p,o,l,i,c,y,I,d);
248 static const XMLCh subjectMatch[] = UNICODE_LITERAL_12(s,u,b,j,e,c,t,M,a,t,c,h);
251 QueryResolver::QueryResolver(const DOMElement* e)
252 : m_log(Category::getInstance(SHIBSP_LOGCAT".AttributeResolver.Query")),
253 m_policyId(XMLHelper::getAttrString(e, nullptr, policyId)),
254 m_subjectMatch(XMLHelper::getAttrBool(e, false, subjectMatch))
257 xmltooling::NDC ndc("QueryResolver");
260 DOMElement* child = XMLHelper::getFirstChildElement(e);
263 if (XMLHelper::isNodeNamed(child, samlconstants::SAML20_NS, saml2::Attribute::LOCAL_NAME)) {
264 auto_ptr<XMLObject> obj(saml2::AttributeBuilder::buildOneFromElement(child));
265 saml2::Attribute* down = dynamic_cast<saml2::Attribute*>(obj.get());
267 m_SAML2Designators.push_back(down);
271 else if (XMLHelper::isNodeNamed(child, samlconstants::SAML1_NS, AttributeDesignator::LOCAL_NAME)) {
272 auto_ptr<XMLObject> obj(AttributeDesignatorBuilder::buildOneFromElement(child));
273 AttributeDesignator* down = dynamic_cast<AttributeDesignator*>(obj.get());
275 m_SAML1Designators.push_back(down);
280 catch (exception& ex) {
281 m_log.error("exception loading attribute designator: %s", ex.what());
283 child = XMLHelper::getNextSiblingElement(child);
286 string exid(XMLHelper::getAttrString(e, nullptr, exceptionId));
288 m_exceptionId.push_back(exid);
291 void QueryResolver::SAML1Query(QueryContext& ctx) const
294 xmltooling::NDC ndc("query");
297 int version = XMLString::equals(ctx.getProtocol(), samlconstants::SAML11_PROTOCOL_ENUM) ? 1 : 0;
298 const AttributeAuthorityDescriptor* AA =
299 find_if(ctx.getEntityDescriptor()->getAttributeAuthorityDescriptors(), isValidForProtocol(ctx.getProtocol()));
301 m_log.warn("no SAML 1.%d AttributeAuthority role found in metadata", version);
305 const Application& application = ctx.getApplication();
306 const PropertySet* relyingParty = application.getRelyingParty(ctx.getEntityDescriptor());
308 // Locate policy key.
309 const char* policyId = m_policyId.empty() ? application.getString("policyId").second : m_policyId.c_str();
311 // Set up policy and SOAP client.
312 scoped_ptr<SecurityPolicy> policy(
313 application.getServiceProvider().getSecurityPolicyProvider()->createSecurityPolicy(application, nullptr, policyId)
315 policy->getAudiences().push_back(relyingParty->getXMLString("entityID").second);
316 MetadataCredentialCriteria mcc(*AA);
317 shibsp::SOAPClient soaper(*policy);
319 auto_ptr_XMLCh binding(samlconstants::SAML1_BINDING_SOAP);
320 auto_ptr<saml1p::Response> response;
321 const vector<AttributeService*>& endpoints=AA->getAttributeServices();
322 for (indirect_iterator<vector<AttributeService*>::const_iterator> ep = make_indirect_iterator(endpoints.begin());
323 !response.get() && ep != make_indirect_iterator(endpoints.end()); ++ep) {
324 if (!XMLString::equals(ep->getBinding(), binding.get()) || !ep->getLocation())
326 auto_ptr_char loc(ep->getLocation());
328 NameIdentifier* nameid = NameIdentifierBuilder::buildNameIdentifier();
329 nameid->setName(ctx.getNameID()->getName());
330 nameid->setFormat(ctx.getNameID()->getFormat());
331 nameid->setNameQualifier(ctx.getNameID()->getNameQualifier());
332 saml1::Subject* subject = saml1::SubjectBuilder::buildSubject();
333 subject->setNameIdentifier(nameid);
334 saml1p::AttributeQuery* query = saml1p::AttributeQueryBuilder::buildAttributeQuery();
335 query->setSubject(subject);
336 query->setResource(relyingParty->getXMLString("entityID").second);
337 for (ptr_vector<AttributeDesignator>::const_iterator ad = m_SAML1Designators.begin(); ad != m_SAML1Designators.end(); ++ad) {
338 auto_ptr<AttributeDesignator> adwrapper(ad->cloneAttributeDesignator());
339 query->getAttributeDesignators().push_back(adwrapper.get());
342 Request* request = RequestBuilder::buildRequest();
343 request->setAttributeQuery(query);
344 request->setMinorVersion(version);
346 SAML1SOAPClient client(soaper, false);
347 client.sendSAML(request, application.getId(), mcc, loc.get());
348 response.reset(client.receiveSAML());
350 catch (exception& ex) {
351 m_log.error("exception during SAML query to %s: %s", loc.get(), ex.what());
356 if (!response.get()) {
357 m_log.error("unable to obtain a SAML response from attribute authority");
358 throw BindingException("Unable to obtain a SAML response from attribute authority.");
360 else if (!response->getStatus() || !response->getStatus()->getStatusCode() || response->getStatus()->getStatusCode()->getValue()==nullptr ||
361 *(response->getStatus()->getStatusCode()->getValue()) != saml1p::StatusCode::SUCCESS) {
362 m_log.error("attribute authority returned a SAML error");
363 throw FatalProfileException("Attribute authority returned a SAML error.");
366 const vector<saml1::Assertion*>& assertions = const_cast<const saml1p::Response*>(response.get())->getAssertions();
367 if (assertions.empty()) {
368 m_log.warn("response from attribute authority was empty");
371 else if (assertions.size() > 1) {
372 m_log.warn("simple resolver only supports one assertion in the query response");
375 saml1::Assertion* newtoken = assertions.front();
377 pair<bool,bool> signedAssertions = relyingParty->getBool("requireSignedAssertions");
378 if (!newtoken->getSignature() && signedAssertions.first && signedAssertions.second) {
379 m_log.error("assertion unsigned, rejecting it based on signedAssertions policy");
380 throw SecurityPolicyException("Rejected unsigned assertion based on local policy.");
384 // We're going to insist that the assertion issuer is the same as the peer.
385 // Reset the policy's message bits and extract them from the assertion.
387 policy->setMessageID(newtoken->getAssertionID());
388 policy->setIssueInstant(newtoken->getIssueInstantEpoch());
389 policy->setIssuer(newtoken->getIssuer());
390 policy->evaluate(*newtoken);
392 // Now we can check the security status of the policy.
393 if (!policy->isAuthenticated())
394 throw SecurityPolicyException("Security of SAML 1.x query result not established.");
396 catch (exception& ex) {
397 m_log.error("assertion failed policy validation: %s", ex.what());
402 response.release(); // detach blows away the Response
403 ctx.getResolvedAssertions().push_back(newtoken);
405 // Finally, extract and filter the result.
407 AttributeExtractor* extractor = application.getAttributeExtractor();
409 Locker extlocker(extractor);
410 const vector<saml1::AttributeStatement*>& statements = const_cast<const saml1::Assertion*>(newtoken)->getAttributeStatements();
411 for (indirect_iterator<vector<saml1::AttributeStatement*>::const_iterator> s = make_indirect_iterator(statements.begin());
412 s != make_indirect_iterator(statements.end()); ++s) {
413 if (m_subjectMatch) {
414 // Check for subject match.
415 const NameIdentifier* respName = s->getSubject() ? s->getSubject()->getNameIdentifier() : nullptr;
416 if (!respName || !XMLString::equals(respName->getName(), ctx.getNameID()->getName()) ||
417 !XMLString::equals(respName->getFormat(), ctx.getNameID()->getFormat()) ||
418 !XMLString::equals(respName->getNameQualifier(), ctx.getNameID()->getNameQualifier())) {
420 m_log.warnStream() << "ignoring AttributeStatement without strongly matching NameIdentifier in Subject: " <<
421 *respName << logging::eol;
423 m_log.warn("ignoring AttributeStatement without NameIdentifier in Subject");
427 extractor->extractAttributes(application, ctx.getRequest(), AA, *s, ctx.getResolvedAttributes());
431 AttributeFilter* filter = application.getAttributeFilter();
433 BasicFilteringContext fc(application, ctx.getResolvedAttributes(), AA, ctx.getClassRef(), ctx.getDeclRef());
434 Locker filtlocker(filter);
435 filter->filterAttributes(fc, ctx.getResolvedAttributes());
438 catch (exception& ex) {
439 m_log.error("caught exception extracting/filtering attributes from query result: %s", ex.what());
440 for_each(ctx.getResolvedAttributes().begin(), ctx.getResolvedAttributes().end(), xmltooling::cleanup<shibsp::Attribute>());
441 ctx.getResolvedAttributes().clear();
446 void QueryResolver::SAML2Query(QueryContext& ctx) const
449 xmltooling::NDC ndc("query");
452 const AttributeAuthorityDescriptor* AA =
453 find_if(ctx.getEntityDescriptor()->getAttributeAuthorityDescriptors(), isValidForProtocol(samlconstants::SAML20P_NS));
455 m_log.warn("no SAML 2 AttributeAuthority role found in metadata");
459 const Application& application = ctx.getApplication();
460 const PropertySet* relyingParty = application.getRelyingParty(ctx.getEntityDescriptor());
461 pair<bool,bool> signedAssertions = relyingParty->getBool("requireSignedAssertions");
462 pair<bool,const char*> encryption = relyingParty->getString("encryption");
464 // Locate policy key.
465 const char* policyId = m_policyId.empty() ? application.getString("policyId").second : m_policyId.c_str();
467 // Set up policy and SOAP client.
468 scoped_ptr<SecurityPolicy> policy(
469 application.getServiceProvider().getSecurityPolicyProvider()->createSecurityPolicy(application, nullptr, policyId)
471 policy->getAudiences().push_back(relyingParty->getXMLString("entityID").second);
472 MetadataCredentialCriteria mcc(*AA);
473 shibsp::SOAPClient soaper(*policy);
475 auto_ptr_XMLCh binding(samlconstants::SAML20_BINDING_SOAP);
476 auto_ptr<saml2p::StatusResponseType> srt;
477 const vector<AttributeService*>& endpoints=AA->getAttributeServices();
478 for (indirect_iterator<vector<AttributeService*>::const_iterator> ep = make_indirect_iterator(endpoints.begin());
479 !srt.get() && ep != make_indirect_iterator(endpoints.end()); ++ep) {
480 if (!XMLString::equals(ep->getBinding(), binding.get()) || !ep->getLocation())
482 auto_ptr_char loc(ep->getLocation());
484 auto_ptr<saml2::Subject> subject(saml2::SubjectBuilder::buildSubject());
486 // Encrypt the NameID?
487 if (encryption.first && (!strcmp(encryption.second, "true") || !strcmp(encryption.second, "back"))) {
488 auto_ptr<EncryptedID> encrypted(EncryptedIDBuilder::buildEncryptedID());
491 *(application.getMetadataProvider()),
494 relyingParty->getXMLString("encryptionAlg").second
496 subject->setEncryptedID(encrypted.get());
500 auto_ptr<NameID> namewrapper(ctx.getNameID()->cloneNameID());
501 subject->setNameID(namewrapper.get());
502 namewrapper.release();
505 saml2p::AttributeQuery* query = saml2p::AttributeQueryBuilder::buildAttributeQuery();
506 query->setSubject(subject.release());
507 Issuer* iss = IssuerBuilder::buildIssuer();
508 iss->setName(relyingParty->getXMLString("entityID").second);
509 query->setIssuer(iss);
510 for (ptr_vector<saml2::Attribute>::const_iterator ad = m_SAML2Designators.begin(); ad != m_SAML2Designators.end(); ++ad) {
511 auto_ptr<saml2::Attribute> adwrapper(ad->cloneAttribute());
512 query->getAttributes().push_back(adwrapper.get());
516 SAML2SOAPClient client(soaper, false);
517 client.sendSAML(query, application.getId(), mcc, loc.get());
518 srt.reset(client.receiveSAML());
520 catch (exception& ex) {
521 m_log.error("exception during SAML query to %s: %s", loc.get(), ex.what());
527 m_log.error("unable to obtain a SAML response from attribute authority");
528 throw BindingException("Unable to obtain a SAML response from attribute authority.");
531 saml2p::Response* response = dynamic_cast<saml2p::Response*>(srt.get());
533 m_log.error("message was not a samlp:Response");
534 throw FatalProfileException("Attribute authority returned an unrecognized message.");
536 else if (!response->getStatus() || !response->getStatus()->getStatusCode() ||
537 !XMLString::equals(response->getStatus()->getStatusCode()->getValue(), saml2p::StatusCode::SUCCESS)) {
538 m_log.error("attribute authority returned a SAML error");
539 throw FatalProfileException("Attribute authority returned a SAML error.");
542 saml2::Assertion* newtoken = nullptr;
543 auto_ptr<saml2::Assertion> newtokenwrapper;
544 const vector<saml2::Assertion*>& assertions = const_cast<const saml2p::Response*>(response)->getAssertions();
545 if (assertions.empty()) {
546 // Check for encryption.
547 const vector<saml2::EncryptedAssertion*>& encassertions = const_cast<const saml2p::Response*>(response)->getEncryptedAssertions();
548 if (encassertions.empty()) {
549 m_log.warn("response from attribute authority was empty");
552 else if (encassertions.size() > 1) {
553 m_log.warn("simple resolver only supports one assertion in the query response");
556 CredentialResolver* cr = application.getCredentialResolver();
558 m_log.warn("found encrypted assertion, but no CredentialResolver was available");
559 throw FatalProfileException("Assertion was encrypted, but no decryption credentials are available.");
562 // With this flag on, we block unauthenticated ciphertext when decrypting,
563 // unless the protocol was authenticated.
564 pair<bool,bool> authenticatedCipher = application.getBool("requireAuthenticatedEncryption");
565 if (policy->isAuthenticated())
566 authenticatedCipher.second = false;
568 // Attempt to decrypt it.
570 Locker credlocker(cr);
571 auto_ptr<XMLObject> tokenwrapper(
572 encassertions.front()->decrypt(
573 *cr, relyingParty->getXMLString("entityID").second, &mcc, authenticatedCipher.first && authenticatedCipher.second
576 newtoken = dynamic_cast<saml2::Assertion*>(tokenwrapper.get());
578 tokenwrapper.release();
579 newtokenwrapper.reset(newtoken);
580 if (m_log.isDebugEnabled())
581 m_log.debugStream() << "decrypted assertion: " << *newtoken << logging::eol;
584 catch (exception& ex) {
585 m_log.error("failed to decrypt assertion: %s", ex.what());
590 if (assertions.size() > 1)
591 m_log.warn("simple resolver only supports one assertion in the query response");
592 newtoken = assertions.front();
595 if (!newtoken->getSignature() && signedAssertions.first && signedAssertions.second) {
596 m_log.error("assertion unsigned, rejecting it based on signedAssertions policy");
597 throw SecurityPolicyException("Rejected unsigned assertion based on local policy.");
601 // We're going to insist that the assertion issuer is the same as the peer.
602 // Reset the policy's message bits and extract them from the assertion.
604 policy->setMessageID(newtoken->getID());
605 policy->setIssueInstant(newtoken->getIssueInstantEpoch());
606 policy->setIssuer(newtoken->getIssuer());
607 policy->evaluate(*newtoken);
609 // Now we can check the security status of the policy.
610 if (!policy->isAuthenticated())
611 throw SecurityPolicyException("Security of SAML 2.0 query result not established.");
613 if (m_subjectMatch) {
614 // Check for subject match.
615 auto_ptr<NameID> nameIDwrapper;
616 NameID* respName = newtoken->getSubject() ? newtoken->getSubject()->getNameID() : nullptr;
618 // Check for encryption.
619 EncryptedID* encname = newtoken->getSubject() ? newtoken->getSubject()->getEncryptedID() : nullptr;
621 CredentialResolver* cr=application.getCredentialResolver();
623 m_log.warn("found EncryptedID, but no CredentialResolver was available");
625 Locker credlocker(cr);
626 auto_ptr<XMLObject> decryptedID(encname->decrypt(*cr, relyingParty->getXMLString("entityID").second, &mcc));
627 respName = dynamic_cast<NameID*>(decryptedID.get());
629 decryptedID.release();
630 nameIDwrapper.reset(respName);
631 if (m_log.isDebugEnabled())
632 m_log.debugStream() << "decrypted NameID: " << *respName << logging::eol;
638 if (!respName || !XMLString::equals(respName->getName(), ctx.getNameID()->getName()) ||
639 !XMLString::equals(respName->getFormat(), ctx.getNameID()->getFormat()) ||
640 !XMLString::equals(respName->getNameQualifier(), ctx.getNameID()->getNameQualifier()) ||
641 !XMLString::equals(respName->getSPNameQualifier(), ctx.getNameID()->getSPNameQualifier())) {
643 m_log.warnStream() << "ignoring Assertion without strongly matching NameID in Subject: " <<
644 *respName << logging::eol;
646 m_log.warn("ignoring Assertion without NameID in Subject");
651 catch (exception& ex) {
652 m_log.error("assertion failed policy validation: %s", ex.what());
656 // If the token's embedded, detach it.
657 if (!newtokenwrapper.get()) {
659 srt.release(); // detach blows away the Response, so avoid a double free
660 newtokenwrapper.reset(newtoken);
662 ctx.getResolvedAssertions().push_back(newtoken);
663 newtokenwrapper.release();
665 // Finally, extract and filter the result.
667 AttributeExtractor* extractor = application.getAttributeExtractor();
669 Locker extlocker(extractor);
670 extractor->extractAttributes(application, ctx.getRequest(), AA, *newtoken, ctx.getResolvedAttributes());
673 AttributeFilter* filter = application.getAttributeFilter();
675 BasicFilteringContext fc(application, ctx.getResolvedAttributes(), AA, ctx.getClassRef(), ctx.getDeclRef());
676 Locker filtlocker(filter);
677 filter->filterAttributes(fc, ctx.getResolvedAttributes());
680 catch (exception& ex) {
681 m_log.error("caught exception extracting/filtering attributes from query result: %s", ex.what());
682 for_each(ctx.getResolvedAttributes().begin(), ctx.getResolvedAttributes().end(), xmltooling::cleanup<shibsp::Attribute>());
683 ctx.getResolvedAttributes().clear();
688 void QueryResolver::resolveAttributes(ResolutionContext& ctx) const
691 xmltooling::NDC ndc("resolveAttributes");
694 QueryContext& qctx = dynamic_cast<QueryContext&>(ctx);
695 if (!qctx.doQuery()) {
696 m_log.debug("found AttributeStatement in input to new session, skipping query");
701 if (qctx.getNameID() && qctx.getEntityDescriptor()) {
702 if (XMLString::equals(qctx.getProtocol(), samlconstants::SAML20P_NS)) {
703 m_log.debug("attempting SAML 2.0 attribute query");
706 else if (XMLString::equals(qctx.getProtocol(), samlconstants::SAML11_PROTOCOL_ENUM) ||
707 XMLString::equals(qctx.getProtocol(), samlconstants::SAML10_PROTOCOL_ENUM)) {
708 m_log.debug("attempting SAML 1.x attribute query");
712 m_log.info("SSO protocol does not allow for attribute query");
716 m_log.warn("can't attempt attribute query, either no NameID or no metadata to use");
719 catch (exception& ex) {
721 if (!m_exceptionId.empty()) {
722 auto_ptr<SimpleAttribute> attr(new SimpleAttribute(m_exceptionId));
723 attr->getValues().push_back(XMLToolingConfig::getConfig().getURLEncoder()->encode(ex.what()));
724 qctx.getResolvedAttributes().push_back(attr.get());