2 * Copyright 2001-2007 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 * SimpleAttributeResolver.cpp
\r
20 * AttributeResolver based on a simple mapping of SAML information.
\r
23 #include "internal.h"
\r
24 #include "Application.h"
\r
25 #include "SessionCache.h"
\r
26 #include "attribute/AttributeDecoder.h"
\r
27 #include "attribute/resolver/AttributeResolver.h"
\r
28 #include "attribute/resolver/ResolutionContext.h"
\r
29 #include "binding/SOAPClient.h"
\r
30 #include "util/SPConstants.h"
\r
33 #include <log4cpp/Category.hh>
\r
34 #include <saml/binding/SecurityPolicy.h>
\r
35 #include <saml/saml1/binding/SAML1SOAPClient.h>
\r
36 #include <saml/saml1/core/Assertions.h>
\r
37 #include <saml/saml1/core/Protocols.h>
\r
38 #include <saml/saml2/binding/SAML2SOAPClient.h>
\r
39 #include <saml/saml2/core/Protocols.h>
\r
40 #include <saml/saml2/metadata/Metadata.h>
\r
41 #include <saml/saml2/metadata/MetadataProvider.h>
\r
42 #include <xmltooling/util/NDC.h>
\r
43 #include <xmltooling/util/ReloadableXMLFile.h>
\r
44 #include <xmltooling/util/XMLHelper.h>
\r
45 #include <xercesc/util/XMLUniDefs.hpp>
\r
47 using namespace shibsp;
\r
48 using namespace opensaml::saml1;
\r
49 using namespace opensaml::saml1p;
\r
50 using namespace opensaml::saml2;
\r
51 using namespace opensaml::saml2p;
\r
52 using namespace opensaml::saml2md;
\r
53 using namespace opensaml;
\r
54 using namespace xmltooling;
\r
55 using namespace log4cpp;
\r
56 using namespace std;
\r
60 class SHIBSP_DLLLOCAL SimpleContext : public ResolutionContext
\r
63 SimpleContext(const Application& application, const Session& session)
\r
64 : m_app(application), m_session(&session), m_client_addr(NULL), m_metadata(NULL), m_entity(NULL),
\r
65 m_nameid(session.getNameID()), m_tokens(NULL) {
\r
69 const Application& application,
\r
70 const char* client_addr,
\r
71 const EntityDescriptor* issuer,
\r
72 const NameID& nameid,
\r
73 const vector<const opensaml::Assertion*>* tokens=NULL
\r
74 ) : m_app(application), m_session(NULL), m_client_addr(client_addr), m_entity(issuer), m_nameid(nameid), m_tokens(tokens) {
\r
79 m_metadata->unlock();
\r
80 for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<shibsp::Attribute>());
\r
81 for_each(m_assertions.begin(), m_assertions.end(), xmltooling::cleanup<opensaml::Assertion>());
\r
84 const Application& getApplication() const {
\r
87 const char* getClientAddress() const {
\r
88 return m_session ? m_session->getClientAddress() : m_client_addr;
\r
90 const EntityDescriptor* getEntityDescriptor() const {
\r
93 if (m_session && m_session->getEntityID()) {
\r
94 m_metadata = m_app.getMetadataProvider();
\r
97 return m_entity = m_metadata->getEntityDescriptor(m_session->getEntityID());
\r
102 const NameID& getNameID() const {
\r
105 const vector<const opensaml::Assertion*>* getTokens() const {
\r
108 const Session* getSession() const {
\r
111 vector<shibsp::Attribute*>& getResolvedAttributes() {
\r
112 return m_attributes;
\r
114 vector<opensaml::Assertion*>& getResolvedAssertions() {
\r
115 return m_assertions;
\r
119 const Application& m_app;
\r
120 const Session* m_session;
\r
121 const char* m_client_addr;
\r
122 mutable MetadataProvider* m_metadata;
\r
123 mutable const EntityDescriptor* m_entity;
\r
124 const NameID& m_nameid;
\r
125 const vector<const opensaml::Assertion*>* m_tokens;
\r
126 vector<shibsp::Attribute*> m_attributes;
\r
127 vector<opensaml::Assertion*> m_assertions;
\r
130 #if defined (_MSC_VER)
\r
131 #pragma warning( push )
\r
132 #pragma warning( disable : 4250 )
\r
135 class SimpleResolverImpl
\r
138 SimpleResolverImpl(const DOMElement* e);
\r
139 ~SimpleResolverImpl() {
\r
140 for_each(m_decoderMap.begin(), m_decoderMap.end(), cleanup_pair<string,AttributeDecoder>());
\r
142 m_document->release();
\r
145 void setDocument(DOMDocument* doc) {
\r
150 ResolutionContext& ctx, const NameIdentifier& nameid, const vector<const char*>* attributes=NULL
\r
153 ResolutionContext& ctx, const NameID& nameid, const vector<const char*>* attributes=NULL
\r
156 ResolutionContext& ctx, const saml1::Assertion* token, const vector<const char*>* attributes=NULL
\r
159 ResolutionContext& ctx, const saml2::Assertion* token, const vector<const char*>* attributes=NULL
\r
164 DOMDocument* m_document;
\r
165 map<string,AttributeDecoder*> m_decoderMap;
\r
166 #ifdef HAVE_GOOD_STL
\r
167 map< pair<xstring,xstring>,pair<const AttributeDecoder*,string> > m_attrMap;
\r
169 map< pair<string,string>,pair<const AttributeDecoder*,string> > m_attrMap;
\r
173 class SimpleResolver : public AttributeResolver, public ReloadableXMLFile
\r
176 SimpleResolver(const DOMElement* e) : ReloadableXMLFile(e), m_impl(NULL) {
\r
179 ~SimpleResolver() {
\r
183 ResolutionContext* createResolutionContext(
\r
184 const Application& application,
\r
185 const char* client_addr,
\r
186 const EntityDescriptor* issuer,
\r
187 const NameID& nameid,
\r
188 const vector<const opensaml::Assertion*>* tokens=NULL
\r
190 return new SimpleContext(application,client_addr,issuer,nameid,tokens);
\r
193 ResolutionContext* createResolutionContext(const Application& application, const Session& session) const {
\r
194 return new SimpleContext(application,session);
\r
197 void resolveAttributes(ResolutionContext& ctx, const vector<const char*>* attributes=NULL) const;
\r
200 pair<bool,DOMElement*> load();
\r
201 SimpleResolverImpl* m_impl;
\r
204 #if defined (_MSC_VER)
\r
205 #pragma warning( pop )
\r
208 AttributeResolver* SHIBSP_DLLLOCAL SimpleAttributeResolverFactory(const DOMElement* const & e)
\r
210 return new SimpleResolver(e);
\r
213 static const XMLCh SIMPLE_NS[] = {
\r
214 chLatin_u, chLatin_r, chLatin_n, chColon, chLatin_m, chLatin_a, chLatin_c, chLatin_e, chColon,
\r
215 chLatin_s, chLatin_h, chLatin_i, chLatin_b, chLatin_b, chLatin_o, chLatin_l, chLatin_e, chLatin_t, chLatin_h, chColon,
\r
216 chDigit_2, chPeriod, chDigit_0, chColon,
\r
217 chLatin_r, chLatin_e, chLatin_s, chLatin_o, chLatin_l, chLatin_v, chLatin_e, chLatin_r, chColon,
\r
218 chLatin_s, chLatin_i, chLatin_m, chLatin_p, chLatin_l, chLatin_e, chNull
\r
220 static const XMLCh _AttributeDecoder[] = UNICODE_LITERAL_16(A,t,t,r,i,b,u,t,e,D,e,c,o,d,e,r);
\r
221 static const XMLCh _AttributeResolver[] = UNICODE_LITERAL_17(A,t,t,r,i,b,u,t,e,R,e,s,o,l,v,e,r);
\r
222 static const XMLCh allowQuery[] = UNICODE_LITERAL_10(a,l,l,o,w,Q,u,e,r,y);
\r
223 static const XMLCh decoderId[] = UNICODE_LITERAL_9(d,e,c,o,d,e,r,I,d);
\r
224 static const XMLCh _id[] = UNICODE_LITERAL_2(i,d);
\r
225 static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e);
\r
228 SimpleResolverImpl::SimpleResolverImpl(const DOMElement* e) : m_document(NULL), m_allowQuery(true)
\r
231 xmltooling::NDC ndc("SimpleResolverImpl");
\r
233 Category& log=Category::getInstance(SHIBSP_LOGCAT".AttributeResolver");
\r
235 if (!XMLHelper::isNodeNamed(e, SIMPLE_NS, _AttributeResolver))
\r
236 throw ConfigurationException("Simple resolver requires resolver:AttributeResolver at root of configuration.");
\r
238 const XMLCh* flag = e->getAttributeNS(NULL,allowQuery);
\r
239 if (flag && (*flag==chLatin_f || *flag==chDigit_0)) {
\r
240 log.info("SAML attribute queries disabled");
\r
241 m_allowQuery = false;
\r
244 DOMElement* child = XMLHelper::getFirstChildElement(e, SIMPLE_NS, _AttributeDecoder);
\r
246 auto_ptr_char id(child->getAttributeNS(NULL, _id));
\r
247 auto_ptr_char type(child->getAttributeNS(NULL, _type));
\r
249 log.info("building AttributeDecoder (%s) of type %s", id.get(), type.get());
\r
250 m_decoderMap[id.get()] = SPConfig::getConfig().AttributeDecoderManager.newPlugin(type.get(), child);
\r
252 catch (exception& ex) {
\r
253 log.error("error building AttributeDecoder (%s): %s", id.get(), ex.what());
\r
255 child = XMLHelper::getNextSiblingElement(child, SIMPLE_NS, _AttributeDecoder);
\r
258 child = XMLHelper::getFirstChildElement(e, samlconstants::SAML20_NS, saml2::Attribute::LOCAL_NAME);
\r
260 // Check for missing Name.
\r
261 const XMLCh* name = child->getAttributeNS(NULL, saml2::Attribute::NAME_ATTRIB_NAME);
\r
262 if (!name || !*name) {
\r
263 log.warn("skipping saml:Attribute declared with no Name");
\r
264 child = XMLHelper::getNextSiblingElement(child, samlconstants::SAML20_NS, saml2::Attribute::LOCAL_NAME);
\r
268 const AttributeDecoder* decoder=NULL;
\r
269 auto_ptr_char id(child->getAttributeNS(NULL, saml2::Attribute::FRIENDLYNAME_ATTRIB_NAME));
\r
270 auto_ptr_char d(child->getAttributeNS(SIMPLE_NS, decoderId));
\r
271 if (!id.get() || !*id.get() || !d.get() || !*d.get() || !(decoder=m_decoderMap[d.get()])) {
\r
272 log.warn("skipping saml:Attribute declared with no FriendlyName or resolvable AttributeDecoder");
\r
273 child = XMLHelper::getNextSiblingElement(child, samlconstants::SAML20_NS, saml2::Attribute::LOCAL_NAME);
\r
277 // Empty NameFormat implies the usual Shib URI naming defaults.
\r
278 const XMLCh* format = child->getAttributeNS(NULL, saml2::Attribute::NAMEFORMAT_ATTRIB_NAME);
\r
279 if (!format || XMLString::equals(format, shibspconstants::SHIB1_ATTRIBUTE_NAMESPACE_URI) ||
\r
280 XMLString::equals(format, saml2::Attribute::URI_REFERENCE))
\r
281 format = &chNull; // ignore default Format/Namespace values
\r
283 // Fetch/create the map entry and see if it's a duplicate rule.
\r
284 #ifdef HAVE_GOOD_STL
\r
285 pair<const AttributeDecoder*,string>& decl = m_attrMap[make_pair(name,format)];
\r
287 auto_ptr_char n(name);
\r
288 auto_ptr_char f(format);
\r
289 pair<const AttributeDecoder*,string>& decl = m_attrMap[make_pair(n.get(),f.get())];
\r
292 log.warn("skipping duplicate saml:Attribute declaration (same Name and NameFormat)");
\r
293 child = XMLHelper::getNextSiblingElement(child, samlconstants::SAML20_NS, saml2::Attribute::LOCAL_NAME);
\r
297 if (log.isDebugEnabled()) {
\r
298 #ifdef HAVE_GOOD_STL
\r
299 auto_ptr_char n(name);
\r
300 auto_ptr_char f(format);
\r
302 log.debug("creating declaration for Attribute %s%s%s", n.get(), *f.get() ? ", Format/Namespace:" : "", f.get());
\r
305 decl.first = decoder;
\r
306 decl.second = id.get();
\r
308 child = XMLHelper::getNextSiblingElement(child, samlconstants::SAML20_NS, saml2::Attribute::LOCAL_NAME);
\r
312 void SimpleResolverImpl::resolve(
\r
313 ResolutionContext& ctx, const saml1::Assertion* token, const vector<const char*>* attributes
\r
318 for(vector<const char*>::const_iterator i=attributes->begin(); i!=attributes->end(); ++i)
\r
321 vector<shibsp::Attribute*>& resolved = ctx.getResolvedAttributes();
\r
323 auto_ptr_char assertingParty(ctx.getEntityDescriptor() ? ctx.getEntityDescriptor()->getEntityID() : NULL);
\r
324 const char* relyingParty = ctx.getApplication().getString("providerId").second;
\r
326 #ifdef HAVE_GOOD_STL
\r
327 map< pair<xstring,xstring>,pair<const AttributeDecoder*,string> >::const_iterator rule;
\r
329 map< pair<string,string>,pair<const AttributeDecoder*,string> >::const_iterator rule;
\r
332 // Check the NameID based on the format.
\r
334 const XMLCh* format = ctx.getNameID().getFormat();
\r
336 format = NameID::UNSPECIFIED;
\r
337 #ifdef HAVE_GOOD_STL
\r
338 if ((rule=m_attrMap.find(make_pair(format,xstring()))) != m_attrMap.end()) {
\r
340 auto_ptr_char temp(format);
\r
341 if ((rule=m_attrMap.find(make_pair(temp.get(),string()))) != m_attrMap.end()) {
\r
343 if (aset.empty() || aset.count(rule->second.second)) {
\r
344 resolved.push_back(
\r
345 rule->second.first->decode(
\r
346 rule->second.second.c_str(), &ctx.getNameID(), assertingParty.get(), relyingParty
\r
353 const vector<saml1::AttributeStatement*>& statements = token->getAttributeStatements();
\r
354 for (vector<saml1::AttributeStatement*>::const_iterator s = statements.begin(); s!=statements.end(); ++s) {
\r
355 const vector<saml1::Attribute*>& attrs = const_cast<const saml1::AttributeStatement*>(*s)->getAttributes();
\r
356 for (vector<saml1::Attribute*>::const_iterator a = attrs.begin(); a!=attrs.end(); ++a) {
\r
357 name = (*a)->getAttributeName();
\r
358 format = (*a)->getAttributeNamespace();
\r
359 if (!name || !*name)
\r
363 #ifdef HAVE_GOOD_STL
\r
364 if ((rule=m_attrMap.find(make_pair(name,format))) != m_attrMap.end()) {
\r
366 auto_ptr_char temp1(name);
\r
367 auto_ptr_char temp2(format);
\r
368 if ((rule=m_attrMap.find(make_pair(temp1.get(),temp2.get()))) != m_attrMap.end()) {
\r
370 if (aset.empty() || aset.count(rule->second.second)) {
\r
371 resolved.push_back(
\r
372 rule->second.first->decode(rule->second.second.c_str(), *a, assertingParty.get(), relyingParty)
\r
380 void SimpleResolverImpl::resolve(
\r
381 ResolutionContext& ctx, const saml2::Assertion* token, const vector<const char*>* attributes
\r
386 for(vector<const char*>::const_iterator i=attributes->begin(); i!=attributes->end(); ++i)
\r
389 vector<shibsp::Attribute*>& resolved = ctx.getResolvedAttributes();
\r
391 auto_ptr_char assertingParty(ctx.getEntityDescriptor() ? ctx.getEntityDescriptor()->getEntityID() : NULL);
\r
392 const char* relyingParty = ctx.getApplication().getString("providerId").second;
\r
394 #ifdef HAVE_GOOD_STL
\r
395 map< pair<xstring,xstring>,pair<const AttributeDecoder*,string> >::const_iterator rule;
\r
397 map< pair<string,string>,pair<const AttributeDecoder*,string> >::const_iterator rule;
\r
400 // Check the NameID based on the format.
\r
402 const XMLCh* format = ctx.getNameID().getFormat();
\r
404 format = NameID::UNSPECIFIED;
\r
405 #ifdef HAVE_GOOD_STL
\r
406 if ((rule=m_attrMap.find(make_pair(format,xstring()))) != m_attrMap.end()) {
\r
408 auto_ptr_char temp(format);
\r
409 if ((rule=m_attrMap.find(make_pair(temp.get(),string()))) != m_attrMap.end()) {
\r
411 if (aset.empty() || aset.count(rule->second.second)) {
\r
412 resolved.push_back(
\r
413 rule->second.first->decode(
\r
414 rule->second.second.c_str(), &ctx.getNameID(), assertingParty.get(), relyingParty
\r
421 const vector<saml2::AttributeStatement*>& statements = token->getAttributeStatements();
\r
422 for (vector<saml2::AttributeStatement*>::const_iterator s = statements.begin(); s!=statements.end(); ++s) {
\r
423 const vector<saml2::Attribute*>& attrs = const_cast<const saml2::AttributeStatement*>(*s)->getAttributes();
\r
424 for (vector<saml2::Attribute*>::const_iterator a = attrs.begin(); a!=attrs.end(); ++a) {
\r
425 name = (*a)->getName();
\r
426 format = (*a)->getNameFormat();
\r
427 if (!name || !*name)
\r
431 #ifdef HAVE_GOOD_STL
\r
432 if ((rule=m_attrMap.find(make_pair(name,format))) != m_attrMap.end()) {
\r
434 auto_ptr_char temp1(name);
\r
435 auto_ptr_char temp2(format);
\r
436 if ((rule=m_attrMap.find(make_pair(temp1.get(),temp2.get()))) != m_attrMap.end()) {
\r
438 if (aset.empty() || aset.count(rule->second.second)) {
\r
439 resolved.push_back(
\r
440 rule->second.first->decode(rule->second.second.c_str(), *a, assertingParty.get(), relyingParty)
\r
448 void SimpleResolverImpl::query(ResolutionContext& ctx, const NameIdentifier& nameid, const vector<const char*>* attributes) const
\r
451 xmltooling::NDC ndc("query");
\r
453 Category& log=Category::getInstance(SHIBSP_LOGCAT".AttributeResolver");
\r
455 const EntityDescriptor* entity = ctx.getEntityDescriptor();
\r
457 log.debug("no issuer information available, skipping query");
\r
462 const AttributeAuthorityDescriptor* AA = entity->getAttributeAuthorityDescriptor(samlconstants::SAML11_PROTOCOL_ENUM);
\r
464 AA = entity->getAttributeAuthorityDescriptor(samlconstants::SAML10_PROTOCOL_ENUM);
\r
468 log.info("no SAML 1.x AttributeAuthority role found in metadata");
\r
472 SecurityPolicy policy;
\r
473 shibsp::SOAPClient soaper(ctx.getApplication(),policy);
\r
475 auto_ptr_XMLCh binding(samlconstants::SAML1_BINDING_SOAP);
\r
476 saml1p::Response* response=NULL;
\r
477 const vector<AttributeService*>& endpoints=AA->getAttributeServices();
\r
478 for (vector<AttributeService*>::const_iterator ep=endpoints.begin(); !response && ep!=endpoints.end(); ++ep) {
\r
480 if (!XMLString::equals((*ep)->getBinding(),binding.get()))
\r
482 auto_ptr_char loc((*ep)->getLocation());
\r
483 auto_ptr_XMLCh issuer(ctx.getApplication().getString("providerId").second);
\r
484 saml1::Subject* subject = saml1::SubjectBuilder::buildSubject();
\r
485 subject->setNameIdentifier(nameid.cloneNameIdentifier());
\r
486 saml1p::AttributeQuery* query = saml1p::AttributeQueryBuilder::buildAttributeQuery();
\r
487 query->setSubject(subject);
\r
488 Request* request = RequestBuilder::buildRequest();
\r
489 request->setAttributeQuery(query);
\r
490 query->setResource(issuer.get());
\r
491 request->setMinorVersion(version);
\r
492 SAML1SOAPClient client(soaper);
\r
493 client.sendSAML(request, *AA, loc.get());
\r
494 response = client.receiveSAML();
\r
496 catch (exception& ex) {
\r
497 log.error("exception making SAML query: %s", ex.what());
\r
503 log.error("unable to successfully query for attributes");
\r
507 time_t now = time(NULL);
\r
508 const Validator* tokval = ctx.getApplication().getTokenValidator(now, AA);
\r
509 const vector<saml1::Assertion*>& assertions = const_cast<const saml1p::Response*>(response)->getAssertions();
\r
510 if (assertions.size()==1) {
\r
511 auto_ptr<saml1p::Response> wrapper(response);
\r
512 saml1::Assertion* newtoken = assertions.front();
\r
513 if (!XMLString::equals(policy.getIssuer() ? policy.getIssuer()->getName() : NULL, newtoken->getIssuer())) {
\r
514 log.error("assertion issued by someone other than AA, rejecting it");
\r
518 tokval->validate(newtoken);
\r
520 catch (exception& ex) {
\r
521 log.error("assertion failed validation check: %s", ex.what());
\r
523 newtoken->detach();
\r
525 ctx.getResolvedAssertions().push_back(newtoken);
\r
526 resolve(ctx, newtoken, attributes);
\r
529 auto_ptr<saml1p::Response> wrapper(response);
\r
530 for (vector<saml1::Assertion*>::const_iterator a = assertions.begin(); a!=assertions.end(); ++a) {
\r
531 if (!XMLString::equals(policy.getIssuer() ? policy.getIssuer()->getName() : NULL, (*a)->getIssuer())) {
\r
532 log.error("assertion issued by someone other than AA, rejecting it");
\r
536 tokval->validate(*a);
\r
538 catch (exception& ex) {
\r
539 log.error("assertion failed validation check: %s", ex.what());
\r
541 resolve(ctx, *a, attributes);
\r
542 ctx.getResolvedAssertions().push_back((*a)->cloneAssertion());
\r
547 void SimpleResolverImpl::query(ResolutionContext& ctx, const NameID& nameid, const vector<const char*>* attributes) const
\r
550 xmltooling::NDC ndc("query");
\r
552 Category& log=Category::getInstance(SHIBSP_LOGCAT".AttributeResolver");
\r
554 const EntityDescriptor* entity = ctx.getEntityDescriptor();
\r
556 log.debug("no issuer information available, skipping query");
\r
559 const AttributeAuthorityDescriptor* AA = entity->getAttributeAuthorityDescriptor(samlconstants::SAML20P_NS);
\r
561 log.info("no SAML 2 AttributeAuthority role found in metadata");
\r
565 SecurityPolicy policy;
\r
566 shibsp::SOAPClient soaper(ctx.getApplication(),policy);
\r
568 auto_ptr_XMLCh binding(samlconstants::SAML20_BINDING_SOAP);
\r
569 saml2p::StatusResponseType* srt=NULL;
\r
570 const vector<AttributeService*>& endpoints=AA->getAttributeServices();
\r
571 for (vector<AttributeService*>::const_iterator ep=endpoints.begin(); !srt && ep!=endpoints.end(); ++ep) {
\r
573 if (!XMLString::equals((*ep)->getBinding(),binding.get()))
\r
575 auto_ptr_char loc((*ep)->getLocation());
\r
576 auto_ptr_XMLCh issuer(ctx.getApplication().getString("providerId").second);
\r
577 saml2::Subject* subject = saml2::SubjectBuilder::buildSubject();
\r
578 subject->setNameID(nameid.cloneNameID());
\r
579 saml2p::AttributeQuery* query = saml2p::AttributeQueryBuilder::buildAttributeQuery();
\r
580 query->setSubject(subject);
\r
581 Issuer* iss = IssuerBuilder::buildIssuer();
\r
582 query->setIssuer(iss);
\r
583 iss->setName(issuer.get());
\r
584 SAML2SOAPClient client(soaper);
\r
585 client.sendSAML(query, *AA, loc.get());
\r
586 srt = client.receiveSAML();
\r
588 catch (exception& ex) {
\r
589 log.error("exception making SAML query: %s", ex.what());
\r
595 log.error("unable to successfully query for attributes");
\r
598 saml2p::Response* response = dynamic_cast<saml2p::Response*>(srt);
\r
601 log.error("message was not a samlp:Response");
\r
605 time_t now = time(NULL);
\r
606 const Validator* tokval = ctx.getApplication().getTokenValidator(now, AA);
\r
607 const vector<saml2::Assertion*>& assertions = const_cast<const saml2p::Response*>(response)->getAssertions();
\r
608 if (assertions.size()==1) {
\r
609 auto_ptr<saml2p::Response> wrapper(response);
\r
610 saml2::Assertion* newtoken = assertions.front();
\r
611 if (!XMLString::equals(policy.getIssuer() ? policy.getIssuer()->getName() : NULL, newtoken->getIssuer() ? newtoken->getIssuer()->getName() : NULL)) {
\r
612 log.error("assertion issued by someone other than AA, rejecting it");
\r
616 tokval->validate(newtoken);
\r
618 catch (exception& ex) {
\r
619 log.error("assertion failed validation check: %s", ex.what());
\r
621 newtoken->detach();
\r
623 ctx.getResolvedAssertions().push_back(newtoken);
\r
624 resolve(ctx, newtoken, attributes);
\r
627 auto_ptr<saml2p::Response> wrapper(response);
\r
628 for (vector<saml2::Assertion*>::const_iterator a = assertions.begin(); a!=assertions.end(); ++a) {
\r
629 if (!XMLString::equals(policy.getIssuer() ? policy.getIssuer()->getName() : NULL, (*a)->getIssuer() ? (*a)->getIssuer()->getName() : NULL)) {
\r
630 log.error("assertion issued by someone other than AA, rejecting it");
\r
634 tokval->validate(*a);
\r
636 catch (exception& ex) {
\r
637 log.error("assertion failed validation check: %s", ex.what());
\r
639 resolve(ctx, *a, attributes);
\r
640 ctx.getResolvedAssertions().push_back((*a)->cloneAssertion());
\r
645 void SimpleResolver::resolveAttributes(ResolutionContext& ctx, const vector<const char*>* attributes) const
\r
648 xmltooling::NDC ndc("resolveAttributes");
\r
650 Category& log=Category::getInstance(SHIBSP_LOGCAT".AttributeResolver");
\r
652 log.debug("examining tokens to resolve");
\r
654 bool query = m_impl->m_allowQuery;
\r
655 const saml1::Assertion* token1;
\r
656 const saml2::Assertion* token2;
\r
657 if (ctx.getTokens()) {
\r
658 for (vector<const opensaml::Assertion*>::const_iterator t = ctx.getTokens()->begin(); t!=ctx.getTokens()->end(); ++t) {
\r
659 token2 = dynamic_cast<const saml2::Assertion*>(*t);
\r
660 if (token2 && !token2->getAttributeStatements().empty()) {
\r
661 log.debug("resolving SAML 2 token with an AttributeStatement");
\r
662 m_impl->resolve(ctx, token2, attributes);
\r
666 token1 = dynamic_cast<const saml1::Assertion*>(*t);
\r
667 if (token1 && !token1->getAttributeStatements().empty()) {
\r
668 log.debug("resolving SAML 1 token with an AttributeStatement");
\r
669 m_impl->resolve(ctx, token1, attributes);
\r
677 if (token1 && !token1->getAuthenticationStatements().empty()) {
\r
678 log.debug("attempting SAML 1.x attribute query");
\r
679 return m_impl->query(ctx, *(token1->getAuthenticationStatements().front()->getSubject()->getNameIdentifier()), attributes);
\r
681 log.debug("attempting SAML 2.0 attribute query");
\r
682 m_impl->query(ctx, ctx.getNameID(), attributes);
\r
686 pair<bool,DOMElement*> SimpleResolver::load()
\r
688 // Load from source using base class.
\r
689 pair<bool,DOMElement*> raw = ReloadableXMLFile::load();
\r
691 // If we own it, wrap it.
\r
692 XercesJanitor<DOMDocument> docjanitor(raw.first ? raw.second->getOwnerDocument() : NULL);
\r
694 SimpleResolverImpl* impl = new SimpleResolverImpl(raw.second);
\r
696 // If we held the document, transfer it to the impl. If we didn't, it's a no-op.
\r
697 impl->setDocument(docjanitor.release());
\r
702 return make_pair(false,(DOMElement*)NULL);
\r