#pragma warning( disable : 4250 )\r
#endif\r
\r
- class SHIBSP_DLLLOCAL TokenValidator : public Validator\r
- {\r
- public:\r
- TokenValidator(const Application& app, time_t ts=0, const RoleDescriptor* role=NULL) : m_app(app), m_ts(ts), m_role(role) {}\r
- void validate(const XMLObject*) const;\r
-\r
- private:\r
- const Application& m_app;\r
- time_t m_ts;\r
- const RoleDescriptor* m_role;\r
- };\r
-\r
static vector<const Handler*> g_noHandlers;\r
\r
// Application configuration wrapper\r
AttributeResolver* getAttributeResolver() const {\r
return (!m_attrResolver && m_base) ? m_base->getAttributeResolver() : m_attrResolver;\r
}\r
-\r
- const PropertySet* getCredentialUse(const EntityDescriptor* provider) const;\r
+ const set<string>* getAttributeIds() const {\r
+ return (m_attributeIds.empty() && m_base) ? m_base->getAttributeIds() : (m_attributeIds.empty() ? NULL : &m_attributeIds);\r
+ }\r
+ CredentialResolver* getCredentialResolver() const {\r
+ return (!m_credResolver && m_base) ? m_base->getCredentialResolver() : m_credResolver;\r
+ }\r
+ const PropertySet* getRelyingParty(const EntityDescriptor* provider) const;\r
\r
const Handler* getDefaultSessionInitiator() const;\r
const Handler* getSessionInitiatorById(const char* id) const;\r
const vector<const XMLCh*>& getAudiences() const {\r
return (m_audiences.empty() && m_base) ? m_base->getAudiences() : m_audiences;\r
}\r
- Validator* getTokenValidator(time_t ts=0, const saml2md::RoleDescriptor* role=NULL) const {\r
- return new TokenValidator(*this, ts, role);\r
- }\r
\r
// Provides filter to exclude special config elements.\r
short acceptNode(const DOMNode* node) const;\r
MetadataProvider* m_metadata;\r
TrustEngine* m_trust;\r
AttributeResolver* m_attrResolver;\r
+ CredentialResolver* m_credResolver;\r
vector<const XMLCh*> m_audiences;\r
+ set<string> m_attributeIds;\r
\r
// manage handler objects\r
vector<Handler*> m_handlers;\r
// pointer to default session initiator\r
const Handler* m_sessionInitDefault;\r
\r
- DOMPropertySet* m_credDefault;\r
+ // RelyingParty properties\r
+ DOMPropertySet* m_partyDefault;\r
#ifdef HAVE_GOOD_STL\r
- map<xstring,PropertySet*> m_credMap;\r
+ map<xstring,PropertySet*> m_partyMap;\r
#else\r
- map<const XMLCh*,PropertySet*> m_credMap;\r
+ map<const XMLCh*,PropertySet*> m_partyMap;\r
#endif\r
};\r
\r
\r
RequestMapper* m_requestMapper;\r
map<string,Application*> m_appmap;\r
- map<string,CredentialResolver*> m_credResolverMap;\r
map< string,pair< PropertySet*,vector<const SecurityPolicyRule*> > > m_policyMap;\r
\r
// Provides filter to exclude special config elements.\r
return (i!=m_impl->m_appmap.end()) ? i->second : NULL;\r
}\r
\r
- CredentialResolver* getCredentialResolver(const char* id) const {\r
- if (id) {\r
- map<string,CredentialResolver*>::const_iterator i=m_impl->m_credResolverMap.find(id);\r
- if (i!=m_impl->m_credResolverMap.end())\r
- return i->second;\r
- }\r
- return NULL;\r
- }\r
-\r
const PropertySet* getPolicySettings(const char* id) const {\r
map<string,pair<PropertySet*,vector<const SecurityPolicyRule*> > >::const_iterator i = m_impl->m_policyMap.find(id);\r
if (i!=m_impl->m_policyMap.end())\r
static const XMLCh Applications[] = UNICODE_LITERAL_12(A,p,p,l,i,c,a,t,i,o,n,s);\r
static const XMLCh _ArtifactMap[] = UNICODE_LITERAL_11(A,r,t,i,f,a,c,t,M,a,p);\r
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
- static const XMLCh Credentials[] = UNICODE_LITERAL_11(C,r,e,d,e,n,t,i,a,l,s);\r
- static const XMLCh CredentialUse[] = UNICODE_LITERAL_13(C,r,e,d,e,n,t,i,a,l,U,s,e);\r
+ static const XMLCh _CredentialResolver[] = UNICODE_LITERAL_18(C,r,e,d,e,n,t,i,a,l,R,e,s,o,l,v,e,r);\r
+ static const XMLCh DefaultRelyingParty[] = UNICODE_LITERAL_19(D,e,f,a,u,l,t,R,e,l,y,i,n,g,P,a,r,t,y);\r
static const XMLCh fatal[] = UNICODE_LITERAL_5(f,a,t,a,l);\r
static const XMLCh _Handler[] = UNICODE_LITERAL_7(H,a,n,d,l,e,r);\r
static const XMLCh _id[] = UNICODE_LITERAL_2(i,d);\r
}\r
};\r
\r
-void TokenValidator::validate(const XMLObject* xmlObject) const\r
-{\r
-#ifdef _DEBUG\r
- xmltooling::NDC ndc("validate");\r
-#endif\r
- Category& log=Category::getInstance(SHIBSP_LOGCAT".Application");\r
-\r
- const opensaml::Assertion* root = NULL;\r
- const saml2::Assertion* token2 = dynamic_cast<const saml2::Assertion*>(xmlObject);\r
- if (token2) {\r
- const saml2::Conditions* conds = token2->getConditions();\r
- // First verify the time conditions, using the specified timestamp, if non-zero.\r
- if (m_ts>0 && conds) {\r
- unsigned int skew = XMLToolingConfig::getConfig().clock_skew_secs;\r
- time_t t=conds->getNotBeforeEpoch();\r
- if (m_ts+skew < t)\r
- throw ValidationException("Assertion is not yet valid.");\r
- t=conds->getNotOnOrAfterEpoch();\r
- if (t <= m_ts-skew)\r
- throw ValidationException("Assertion is no longer valid.");\r
- }\r
-\r
- // Now we process conditions. Only audience restrictions at the moment.\r
- const vector<saml2::Condition*>& convec = conds->getConditions();\r
- for (vector<saml2::Condition*>::const_iterator c = convec.begin(); c!=convec.end(); ++c) {\r
- const saml2::AudienceRestriction* ac=dynamic_cast<const saml2::AudienceRestriction*>(*c);\r
- if (!ac) {\r
- log.error("unrecognized Condition in assertion (%s)",\r
- (*c)->getSchemaType() ? (*c)->getSchemaType()->toString().c_str() : (*c)->getElementQName().toString().c_str());\r
- throw ValidationException("Assertion contains an unrecognized condition.");\r
- }\r
-\r
- bool found = false;\r
- const vector<saml2::Audience*>& auds1 = ac->getAudiences();\r
- const vector<const XMLCh*>& auds2 = m_app.getAudiences();\r
- for (vector<saml2::Audience*>::const_iterator a = auds1.begin(); !found && a!=auds1.end(); ++a) {\r
- for (vector<const XMLCh*>::const_iterator a2 = auds2.begin(); !found && a2!=auds2.end(); ++a2) {\r
- found = XMLString::equals((*a)->getAudienceURI(), *a2);\r
- }\r
- }\r
-\r
- if (!found) {\r
- ostringstream os;\r
- os << *ac;\r
- log.error("unacceptable AudienceRestriction in assertion (%s)", os.str().c_str());\r
- throw ValidationException("Assertion contains an unacceptable AudienceRestriction.");\r
- }\r
- }\r
-\r
- root = token2;\r
- }\r
- else {\r
- const saml1::Assertion* token1 = dynamic_cast<const saml1::Assertion*>(xmlObject);\r
- if (token1) {\r
- const saml1::Conditions* conds = token1->getConditions();\r
- // First verify the time conditions, using the specified timestamp, if non-zero.\r
- if (m_ts>0 && conds) {\r
- unsigned int skew = XMLToolingConfig::getConfig().clock_skew_secs;\r
- time_t t=conds->getNotBeforeEpoch();\r
- if (m_ts+skew < t)\r
- throw ValidationException("Assertion is not yet valid.");\r
- t=conds->getNotOnOrAfterEpoch();\r
- if (t <= m_ts-skew)\r
- throw ValidationException("Assertion is no longer valid.");\r
- }\r
-\r
- // Now we process conditions. Only audience restrictions at the moment.\r
- const vector<saml1::Condition*>& convec = conds->getConditions();\r
- for (vector<saml1::Condition*>::const_iterator c = convec.begin(); c!=convec.end(); ++c) {\r
- const saml1::AudienceRestrictionCondition* ac=dynamic_cast<const saml1::AudienceRestrictionCondition*>(*c);\r
- if (!ac) {\r
- log.error("unrecognized Condition in assertion (%s)",\r
- (*c)->getSchemaType() ? (*c)->getSchemaType()->toString().c_str() : (*c)->getElementQName().toString().c_str());\r
- throw ValidationException("Assertion contains an unrecognized condition.");\r
- }\r
-\r
- bool found = false;\r
- const vector<saml1::Audience*>& auds1 = ac->getAudiences();\r
- const vector<const XMLCh*>& auds2 = m_app.getAudiences();\r
- for (vector<saml1::Audience*>::const_iterator a = auds1.begin(); !found && a!=auds1.end(); ++a) {\r
- for (vector<const XMLCh*>::const_iterator a2 = auds2.begin(); !found && a2!=auds2.end(); ++a2) {\r
- found = XMLString::equals((*a)->getAudienceURI(), *a2);\r
- }\r
- }\r
-\r
- if (!found) {\r
- ostringstream os;\r
- os << *ac;\r
- log.error("unacceptable AudienceRestrictionCondition in assertion (%s)", os.str().c_str());\r
- throw ValidationException("Assertion contains an unacceptable AudienceRestrictionCondition.");\r
- }\r
- }\r
-\r
- root = token1;\r
- }\r
- else {\r
- throw ValidationException("Unknown object type passed to token validator.");\r
- }\r
- }\r
-\r
- if (!m_role || !m_app.getTrustEngine()) {\r
- log.warn("no issuer role or TrustEngine provided, so no signature validation performed");\r
- return;\r
- }\r
-\r
- const PropertySet* policy=m_app.getServiceProvider().getPolicySettings(m_app.getString("policyId").second);\r
- pair<bool,bool> signedAssertions=policy ? policy->getBool("signedAssertions") : make_pair(false,false);\r
-\r
- if (root->getSignature()) {\r
- if (!m_app.getTrustEngine()->validate(*(root->getSignature()),*m_role))\r
- throw ValidationException("Assertion signature did not validate.");\r
- }\r
- else if (signedAssertions.first && signedAssertions.second)\r
- throw ValidationException("Assertion was unsigned, violating policy.");\r
-}\r
-\r
XMLApplication::XMLApplication(\r
const ServiceProvider* sp,\r
const DOMElement* e,\r
const XMLApplication* base\r
- ) : m_sp(sp), m_base(base), m_metadata(NULL), m_trust(NULL), m_attrResolver(NULL),\r
- m_credDefault(NULL), m_sessionInitDefault(NULL), m_acsDefault(NULL)\r
+ ) : m_sp(sp), m_base(base), m_metadata(NULL), m_trust(NULL), m_attrResolver(NULL), m_credResolver(NULL),\r
+ m_partyDefault(NULL), m_sessionInitDefault(NULL), m_acsDefault(NULL)\r
{\r
#ifdef _DEBUG\r
xmltooling::NDC ndc("XMLApplication");\r
m_hash+=getString("providerId").second;\r
m_hash=samlConf.hashSHA1(m_hash.c_str(), true);\r
\r
+ pair<bool,const char*> attributes = getString("attributeIds");\r
+ if (attributes.first) {\r
+ char* dup = strdup(attributes.second);\r
+ char* pos;\r
+ char* start = dup;\r
+ while (start && *start) {\r
+ while (*start && isspace(*start))\r
+ start++;\r
+ if (!*start)\r
+ break;\r
+ pos = strchr(start,' ');\r
+ if (pos)\r
+ *pos=0;\r
+ m_attributeIds.insert(start);\r
+ start = pos ? pos+1 : NULL;\r
+ }\r
+ free(dup);\r
+ }\r
+\r
const PropertySet* sessions = getPropertySet("Sessions");\r
\r
// Process handlers.\r
child = XMLHelper::getNextSiblingElement(child);\r
continue;\r
}\r
- handler=conf.AssertionConsumerServiceManager.newPlugin(bindprop.get(),child);\r
+ handler=conf.AssertionConsumerServiceManager.newPlugin(bindprop.get(),make_pair(child, getId()));\r
// Map by binding (may be > 1 per binding, e.g. SAML 1.0 vs 1.1)\r
#ifdef HAVE_GOOD_STL\r
m_acsBindingMap[handler->getXMLString("Binding").second].push_back(handler);\r
child = XMLHelper::getNextSiblingElement(child);\r
continue;\r
}\r
- handler=conf.SessionInitiatorManager.newPlugin(bindprop.get(),child);\r
+ handler=conf.SessionInitiatorManager.newPlugin(bindprop.get(),make_pair(child, getId()));\r
pair<bool,const char*> si_id=handler->getString("id");\r
if (si_id.first && si_id.second)\r
m_sessionInitMap[si_id.second]=handler;\r
child = XMLHelper::getNextSiblingElement(child);\r
continue;\r
}\r
- handler=conf.SingleLogoutServiceManager.newPlugin(bindprop.get(),child);\r
+ handler=conf.SingleLogoutServiceManager.newPlugin(bindprop.get(),make_pair(child, getId()));\r
}\r
else if (XMLHelper::isNodeNamed(child,samlconstants::SAML20MD_NS,ManageNameIDService::LOCAL_NAME)) {\r
auto_ptr_char bindprop(child->getAttributeNS(NULL,EndpointType::BINDING_ATTRIB_NAME));\r
child = XMLHelper::getNextSiblingElement(child);\r
continue;\r
}\r
- handler=conf.ManageNameIDServiceManager.newPlugin(bindprop.get(),child);\r
+ handler=conf.ManageNameIDServiceManager.newPlugin(bindprop.get(),make_pair(child, getId()));\r
}\r
else {\r
auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
child = XMLHelper::getNextSiblingElement(child);\r
continue;\r
}\r
- handler=conf.HandlerManager.newPlugin(type.get(),child);\r
+ handler=conf.HandlerManager.newPlugin(type.get(),make_pair(child, getId()));\r
}\r
\r
// Save off the objects after giving the property set to the handler for its use.\r
}\r
}\r
\r
- // Finally, load credential mappings.\r
- child = XMLHelper::getFirstChildElement(e,CredentialUse);\r
+ if (conf.isEnabled(SPConfig::Credentials)) {\r
+ child = XMLHelper::getFirstChildElement(e,_CredentialResolver);\r
+ if (child) {\r
+ auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
+ log.info("building CredentialResolver of type %s...",type.get());\r
+ try {\r
+ m_credResolver = xmlConf.CredentialResolverManager.newPlugin(type.get(),child);\r
+ }\r
+ catch (exception& ex) {\r
+ log.crit("error building CredentialResolver: %s", ex.what());\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ // Finally, load relying parties.\r
+ child = XMLHelper::getFirstChildElement(e,DefaultRelyingParty);\r
if (child) {\r
- m_credDefault=new DOMPropertySet();\r
- m_credDefault->load(child,log,this);\r
+ m_partyDefault=new DOMPropertySet();\r
+ m_partyDefault->load(child,log,this);\r
child = XMLHelper::getFirstChildElement(child,RelyingParty);\r
while (child) {\r
- DOMPropertySet* rp=new DOMPropertySet();\r
+ auto_ptr<DOMPropertySet> rp(new DOMPropertySet());\r
rp->load(child,log,this);\r
- m_credMap[child->getAttributeNS(NULL,saml2::Attribute::NAME_ATTRIB_NAME)]=rp;\r
+ m_partyMap[child->getAttributeNS(NULL,saml2::Attribute::NAME_ATTRIB_NAME)]=rp.release();\r
child = XMLHelper::getNextSiblingElement(child,RelyingParty);\r
}\r
}\r
\r
void XMLApplication::cleanup()\r
{\r
- for_each(m_handlers.begin(),m_handlers.end(),xmltooling::cleanup<Handler>());\r
- \r
- delete m_credDefault;\r
+ delete m_partyDefault;\r
#ifdef HAVE_GOOD_STL\r
- for_each(m_credMap.begin(),m_credMap.end(),cleanup_pair<xstring,PropertySet>());\r
+ for_each(m_partyMap.begin(),m_partyMap.end(),cleanup_pair<xstring,PropertySet>());\r
#else\r
- for_each(m_credMap.begin(),m_credMap.end(),cleanup_pair<const XMLCh*,PropertySet>());\r
+ for_each(m_partyMap.begin(),m_partyMap.end(),cleanup_pair<const XMLCh*,PropertySet>());\r
#endif\r
-\r
+ for_each(m_handlers.begin(),m_handlers.end(),xmltooling::cleanup<Handler>());\r
+ delete m_credResolver;\r
delete m_attrResolver;\r
delete m_trust;\r
delete m_metadata;\r
XMLString::equals(name,SingleLogoutService::LOCAL_NAME) ||\r
XMLString::equals(name,ManageNameIDService::LOCAL_NAME) ||\r
XMLString::equals(name,SessionInitiator) ||\r
- XMLString::equals(name,CredentialUse) ||\r
+ XMLString::equals(name,DefaultRelyingParty) ||\r
XMLString::equals(name,RelyingParty) ||\r
XMLString::equals(name,_MetadataProvider) ||\r
XMLString::equals(name,_TrustEngine) ||\r
+ XMLString::equals(name,_CredentialResolver) ||\r
XMLString::equals(name,_AttributeResolver))\r
return FILTER_REJECT;\r
\r
return m_base->getPropertySet(name,ns);\r
}\r
\r
-const PropertySet* XMLApplication::getCredentialUse(const EntityDescriptor* provider) const\r
+const PropertySet* XMLApplication::getRelyingParty(const EntityDescriptor* provider) const\r
{\r
- if (!m_credDefault && m_base)\r
- return m_base->getCredentialUse(provider);\r
+ if (!m_partyDefault && m_base)\r
+ return m_base->getRelyingParty(provider);\r
+ else if (!provider)\r
+ return m_partyDefault;\r
\r
#ifdef HAVE_GOOD_STL\r
- map<xstring,PropertySet*>::const_iterator i=m_credMap.find(provider->getEntityID());\r
- if (i!=m_credMap.end())\r
+ map<xstring,PropertySet*>::const_iterator i=m_partyMap.find(provider->getEntityID());\r
+ if (i!=m_partyMap.end())\r
return i->second;\r
const EntitiesDescriptor* group=dynamic_cast<const EntitiesDescriptor*>(provider->getParent());\r
while (group) {\r
if (group->getName()) {\r
- i=m_credMap.find(group->getName());\r
- if (i!=m_credMap.end())\r
+ i=m_partyMap.find(group->getName());\r
+ if (i!=m_partyMap.end())\r
return i->second;\r
}\r
group=dynamic_cast<const EntitiesDescriptor*>(group->getParent());\r
}\r
#else\r
- map<const XMLCh*,PropertySet*>::const_iterator i=m_credMap.begin();\r
- for (; i!=m_credMap.end(); i++) {\r
+ map<const XMLCh*,PropertySet*>::const_iterator i=m_partyMap.begin();\r
+ for (; i!=m_partyMap.end(); i++) {\r
if (XMLString::equals(i->first,provider->getId()))\r
return i->second;\r
const EntitiesDescriptor* group=dynamic_cast<const EntitiesDescriptor*>(provider->getParent());\r
}\r
}\r
#endif\r
- return m_credDefault;\r
+ return m_partyDefault;\r
}\r
\r
const Handler* XMLApplication::getDefaultSessionInitiator() const\r
const XMLCh* name=node->getLocalName();\r
if (XMLString::equals(name,Applications) ||\r
XMLString::equals(name,_ArtifactMap) ||\r
- XMLString::equals(name,Credentials) ||\r
XMLString::equals(name,Extensions::LOCAL_NAME) ||\r
XMLString::equals(name,Implementation) ||\r
XMLString::equals(name,Listener) ||\r
}\r
}\r
else {\r
- log.info("building in-process SessionCache of type %s...",REMOTED_SESSION_CACHE);\r
- m_outer->m_sessionCache=conf.SessionCacheManager.newPlugin(REMOTED_SESSION_CACHE,NULL);\r
+ child=XMLHelper::getFirstChildElement(SHIRE,_SessionCache);\r
+ if (child) {\r
+ auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
+ log.info("building SessionCache of type %s...",type.get());\r
+ m_outer->m_sessionCache=conf.SessionCacheManager.newPlugin(type.get(),child);\r
+ }\r
+ else {\r
+ log.warn("SessionCache unspecified, building SessionCache of type %s...",REMOTED_SESSION_CACHE);\r
+ m_outer->m_sessionCache=conf.SessionCacheManager.newPlugin(REMOTED_SESSION_CACHE,child);\r
+ }\r
}\r
}\r
} // end of first-time-only stuff\r
}\r
}\r
\r
- // Now we load the credentials map.\r
- if (conf.isEnabled(SPConfig::Credentials)) {\r
- child = XMLHelper::getLastChildElement(e,Credentials);\r
- if (child) {\r
- // Step down and process resolvers.\r
- child=XMLHelper::getFirstChildElement(child);\r
- while (child) {\r
- auto_ptr_char id(child->getAttributeNS(NULL,_id));\r
- auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
- try {\r
- CredentialResolver* cr=xmlConf.CredentialResolverManager.newPlugin(type.get(),child);\r
- m_credResolverMap[id.get()] = cr;\r
- }\r
- catch (exception& ex) {\r
- log.crit("failed to instantiate CredentialResolver (%s): %s", id.get(), ex.what());\r
- }\r
- child = XMLHelper::getNextSiblingElement(child);\r
- }\r
- }\r
- }\r
-\r
// Load security policies.\r
child = XMLHelper::getLastChildElement(e,SecurityPolicies);\r
if (child) {\r
XMLConfigImpl::~XMLConfigImpl()\r
{\r
for_each(m_appmap.begin(),m_appmap.end(),cleanup_pair<string,Application>());\r
- for_each(m_credResolverMap.begin(),m_credResolverMap.end(),cleanup_pair<string,CredentialResolver>());\r
for (map< string,pair<PropertySet*,vector<const SecurityPolicyRule*> > >::iterator i=m_policyMap.begin(); i!=m_policyMap.end(); ++i) {\r
delete i->second.first;\r
for_each(i->second.second.begin(), i->second.second.end(), xmltooling::cleanup<SecurityPolicyRule>());\r