Attribute filtering code.
[shibboleth/sp.git] / shibsp / impl / XMLServiceProvider.cpp
index 54dbde6..d24a5d7 100644 (file)
 #include "exceptions.h"\r
 #include "AccessControl.h"\r
 #include "Application.h"\r
-#include "Handler.h"\r
 #include "RequestMapper.h"\r
 #include "ServiceProvider.h"\r
 #include "SessionCache.h"\r
 #include "SPConfig.h"\r
 #include "SPRequest.h"\r
 #include "TransactionLog.h"\r
-#include "attribute/Attribute.h"\r
+#include "attribute/filtering/AttributeFilter.h"\r
+#include "attribute/resolver/AttributeExtractor.h"\r
+#include "attribute/resolver/AttributeResolver.h"\r
+#include "handler/SessionInitiator.h"\r
 #include "remoting/ListenerService.h"\r
 #include "security/PKIXTrustEngine.h"\r
 #include "util/DOMPropertySet.h"\r
@@ -42,6 +44,7 @@
 #include <log4cpp/Category.hh>\r
 #include <log4cpp/PropertyConfigurator.hh>\r
 #include <saml/SAMLConfig.h>\r
+#include <saml/binding/ArtifactMap.h>\r
 #include <saml/saml1/core/Assertions.h>\r
 #include <saml/saml2/metadata/ChainingMetadataProvider.h>\r
 #include <xmltooling/XMLToolingConfig.h>\r
@@ -57,7 +60,6 @@ using namespace opensaml;
 using namespace xmltooling;\r
 using namespace log4cpp;\r
 using namespace std;\r
-using xmlsignature::CredentialResolver;\r
 \r
 namespace {\r
 \r
@@ -75,29 +77,42 @@ namespace {
         XMLApplication(const ServiceProvider*, const DOMElement* e, const XMLApplication* base=NULL);\r
         ~XMLApplication() { cleanup(); }\r
     \r
-        // PropertySet\r
-        pair<bool,bool> getBool(const char* name, const char* ns=NULL) const;\r
-        pair<bool,const char*> getString(const char* name, const char* ns=NULL) const;\r
-        pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const;\r
-        pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const;\r
-        pair<bool,int> getInt(const char* name, const char* ns=NULL) const;\r
-        const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const;\r
-\r
         // Application\r
+        const ServiceProvider& getServiceProvider() const {return *m_sp;}\r
         const char* getId() const {return getString("id").second;}\r
         const char* getHash() const {return m_hash.c_str();}\r
-        MetadataProvider* getMetadataProvider() const;\r
-        TrustEngine* getTrustEngine() const;\r
-        const vector<const XMLCh*>& getAudiences() const;\r
-        const PropertySet* getCredentialUse(const EntityDescriptor* provider) const;\r
 \r
-        const Handler* getDefaultSessionInitiator() const;\r
-        const Handler* getSessionInitiatorById(const char* id) const;\r
+        MetadataProvider* getMetadataProvider() const {\r
+            return (!m_metadata && m_base) ? m_base->getMetadataProvider() : m_metadata;\r
+        }\r
+        TrustEngine* getTrustEngine() const {\r
+            return (!m_trust && m_base) ? m_base->getTrustEngine() : m_trust;\r
+        }\r
+        AttributeExtractor* getAttributeExtractor() const {\r
+            return (!m_attrExtractor && m_base) ? m_base->getAttributeExtractor() : m_attrExtractor;\r
+        }\r
+        AttributeFilter* getAttributeFilter() const {\r
+            return (!m_attrFilter && m_base) ? m_base->getAttributeFilter() : m_attrFilter;\r
+        }\r
+        AttributeResolver* getAttributeResolver() const {\r
+            return (!m_attrResolver && m_base) ? m_base->getAttributeResolver() : m_attrResolver;\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 SessionInitiator* getDefaultSessionInitiator() const;\r
+        const SessionInitiator* getSessionInitiatorById(const char* id) const;\r
         const Handler* getDefaultAssertionConsumerService() const;\r
         const Handler* getAssertionConsumerServiceByIndex(unsigned short index) const;\r
         const vector<const Handler*>& getAssertionConsumerServicesByBinding(const XMLCh* binding) const;\r
         const Handler* getHandler(const char* path) const;\r
-        \r
+\r
+        const vector<const XMLCh*>& getAudiences() const {\r
+            return (m_audiences.empty() && m_base) ? m_base->getAudiences() : m_audiences;\r
+        }\r
+\r
         // Provides filter to exclude special config elements.\r
         short acceptNode(const DOMNode* node) const;\r
     \r
@@ -108,6 +123,10 @@ namespace {
         string m_hash;\r
         MetadataProvider* m_metadata;\r
         TrustEngine* m_trust;\r
+        AttributeExtractor* m_attrExtractor;\r
+        AttributeFilter* m_attrFilter;\r
+        AttributeResolver* m_attrResolver;\r
+        CredentialResolver* m_credResolver;\r
         vector<const XMLCh*> m_audiences;\r
 \r
         // manage handler objects\r
@@ -130,17 +149,18 @@ namespace {
 #endif\r
         ACSBindingMap m_acsBindingMap;\r
 \r
-        // maps unique ID strings to session initiators\r
-        map<string,const Handler*> m_sessionInitMap;\r
-\r
         // pointer to default session initiator\r
-        const Handler* m_sessionInitDefault;\r
+        const SessionInitiator* m_sessionInitDefault;\r
+\r
+        // maps unique ID strings to session initiators\r
+        map<string,const SessionInitiator*> m_sessionInitMap;\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
@@ -149,12 +169,11 @@ namespace {
     class SHIBSP_DLLLOCAL XMLConfigImpl : public DOMPropertySet, public DOMNodeFilter\r
     {\r
     public:\r
-        XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer);\r
+        XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer, Category& log);\r
         ~XMLConfigImpl();\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
@@ -174,8 +193,8 @@ namespace {
     class SHIBSP_DLLLOCAL XMLConfig : public ServiceProvider, public ReloadableXMLFile\r
     {\r
     public:\r
-        XMLConfig(const DOMElement* e)\r
-            : ReloadableXMLFile(e), m_impl(NULL), m_listener(NULL), m_sessionCache(NULL), m_tranLog(NULL) {\r
+        XMLConfig(const DOMElement* e) : ReloadableXMLFile(e, Category::getInstance(SHIBSP_LOGCAT".Config")),\r
+            m_impl(NULL), m_listener(NULL), m_sessionCache(NULL), m_tranLog(NULL) {\r
         }\r
         \r
         void init() {\r
@@ -188,16 +207,18 @@ namespace {
             delete m_listener;\r
             delete m_tranLog;\r
             XMLToolingConfig::getConfig().setReplayCache(NULL);\r
+            SAMLConfig::getConfig().setArtifactMap(NULL);\r
             for_each(m_storage.begin(), m_storage.end(), cleanup_pair<string,StorageService>());\r
         }\r
 \r
         // PropertySet\r
+        void setParent(const PropertySet* parent) {return m_impl->setParent(parent);}\r
         pair<bool,bool> getBool(const char* name, const char* ns=NULL) const {return m_impl->getBool(name,ns);}\r
         pair<bool,const char*> getString(const char* name, const char* ns=NULL) const {return m_impl->getString(name,ns);}\r
         pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const {return m_impl->getXMLString(name,ns);}\r
         pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const {return m_impl->getUnsignedInt(name,ns);}\r
         pair<bool,int> getInt(const char* name, const char* ns=NULL) const {return m_impl->getInt(name,ns);}\r
-        const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:sp:config:2.0") const {return m_impl->getPropertySet(name,ns);}\r
+        const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:2.0:native:sp:config") const {return m_impl->getPropertySet(name,ns);}\r
         const DOMElement* getElement() const {return m_impl->getElement();}\r
 \r
         // ServiceProvider\r
@@ -239,15 +260,6 @@ namespace {
             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
@@ -280,8 +292,12 @@ namespace {
 \r
     static const XMLCh _Application[] =         UNICODE_LITERAL_11(A,p,p,l,i,c,a,t,i,o,n);\r
     static const XMLCh Applications[] =         UNICODE_LITERAL_12(A,p,p,l,i,c,a,t,i,o,n,s);\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 _ArtifactMap[] =         UNICODE_LITERAL_11(A,r,t,i,f,a,c,t,M,a,p);\r
+    static const XMLCh _AttributeExtractor[] =  UNICODE_LITERAL_18(A,t,t,r,i,b,u,t,e,E,x,t,r,a,c,t,o,r);\r
+    static const XMLCh _AttributeFilter[] =     UNICODE_LITERAL_15(A,t,t,r,i,b,u,t,e,F,i,l,t,e,r);\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 _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
@@ -291,6 +307,9 @@ namespace {
     static const XMLCh Listener[] =             UNICODE_LITERAL_8(L,i,s,t,e,n,e,r);\r
     static const XMLCh logger[] =               UNICODE_LITERAL_6(l,o,g,g,e,r);\r
     static const XMLCh MemoryListener[] =       UNICODE_LITERAL_14(M,e,m,o,r,y,L,i,s,t,e,n,e,r);\r
+    static const XMLCh _MetadataProvider[] =    UNICODE_LITERAL_16(M,e,t,a,d,a,t,a,P,r,o,v,i,d,e,r);\r
+    static const XMLCh OutOfProcess[] =         UNICODE_LITERAL_12(O,u,t,O,f,P,r,o,c,e,s,s);\r
+    static const XMLCh _path[] =                UNICODE_LITERAL_4(p,a,t,h);\r
     static const XMLCh Policy[] =               UNICODE_LITERAL_6(P,o,l,i,c,y);\r
     static const XMLCh RelyingParty[] =         UNICODE_LITERAL_12(R,e,l,y,i,n,g,P,a,r,t,y);\r
     static const XMLCh _ReplayCache[] =         UNICODE_LITERAL_11(R,e,p,l,a,y,C,a,c,h,e);\r
@@ -298,15 +317,12 @@ namespace {
     static const XMLCh Rule[] =                 UNICODE_LITERAL_4(R,u,l,e);\r
     static const XMLCh SecurityPolicies[] =     UNICODE_LITERAL_16(S,e,c,u,r,i,t,y,P,o,l,i,c,i,e,s);\r
     static const XMLCh _SessionCache[] =        UNICODE_LITERAL_12(S,e,s,s,i,o,n,C,a,c,h,e);\r
-    static const XMLCh SessionInitiator[] =     UNICODE_LITERAL_16(S,e,s,s,i,o,n,I,n,i,t,i,a,t,o,r);\r
+    static const XMLCh _SessionInitiator[] =    UNICODE_LITERAL_16(S,e,s,s,i,o,n,I,n,i,t,i,a,t,o,r);\r
     static const XMLCh _StorageService[] =      UNICODE_LITERAL_14(S,t,o,r,a,g,e,S,e,r,v,i,c,e);\r
-    static const XMLCh OutOfProcess[] =         UNICODE_LITERAL_12(O,u,t,O,f,P,r,o,c,e,s,s);\r
     static const XMLCh TCPListener[] =          UNICODE_LITERAL_11(T,C,P,L,i,s,t,e,n,e,r);\r
     static const XMLCh _TrustEngine[] =         UNICODE_LITERAL_11(T,r,u,s,t,E,n,g,i,n,e);\r
-    static const XMLCh UnixListener[] =         UNICODE_LITERAL_12(U,n,i,x,L,i,s,t,e,n,e,r);\r
-    static const XMLCh _MetadataProvider[] =    UNICODE_LITERAL_16(M,e,t,a,d,a,t,a,P,r,o,v,i,d,e,r);\r
-    static const XMLCh _path[] =                UNICODE_LITERAL_4(p,a,t,h);\r
     static const XMLCh _type[] =                UNICODE_LITERAL_4(t,y,p,e);\r
+    static const XMLCh UnixListener[] =         UNICODE_LITERAL_12(U,n,i,x,L,i,s,t,e,n,e,r);\r
 \r
     class SHIBSP_DLLLOCAL PolicyNodeFilter : public DOMNodeFilter\r
     {\r
@@ -330,8 +346,8 @@ XMLApplication::XMLApplication(
     const ServiceProvider* sp,\r
     const DOMElement* e,\r
     const XMLApplication* base\r
-    ) : m_sp(sp), m_base(base), m_metadata(NULL), m_trust(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_attrExtractor(NULL), m_attrFilter(NULL), m_attrResolver(NULL),\r
+        m_credResolver(NULL), m_partyDefault(NULL), m_sessionInitDefault(NULL), m_acsDefault(NULL)\r
 {\r
 #ifdef _DEBUG\r
     xmltooling::NDC ndc("XMLApplication");\r
@@ -341,13 +357,15 @@ XMLApplication::XMLApplication(
     try {\r
         // First load any property sets.\r
         load(e,log,this);\r
+        if (base)\r
+            setParent(base);\r
 \r
         SPConfig& conf=SPConfig::getConfig();\r
         SAMLConfig& samlConf=SAMLConfig::getConfig();\r
         XMLToolingConfig& xmlConf=XMLToolingConfig::getConfig();\r
 \r
         m_hash=getId();\r
-        m_hash+=getString("providerId").second;\r
+        m_hash+=getString("entityID").second;\r
         m_hash=samlConf.hashSHA1(m_hash.c_str(), true);\r
 \r
         const PropertySet* sessions = getPropertySet("Sessions");\r
@@ -367,7 +385,7 @@ XMLApplication::XMLApplication(
                         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
@@ -388,27 +406,28 @@ XMLApplication::XMLApplication(
                             m_acsDefault=handler;\r
                     }\r
                 }\r
-                else if (XMLString::equals(child->getLocalName(),SessionInitiator)) {\r
-                    auto_ptr_char bindprop(child->getAttributeNS(NULL,EndpointType::BINDING_ATTRIB_NAME));\r
-                    if (!bindprop.get() || !*(bindprop.get())) {\r
-                        log.warn("SessionInitiator element has no Binding attribute, skipping it...");\r
+                else if (XMLString::equals(child->getLocalName(),_SessionInitiator)) {\r
+                    auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
+                    if (!type.get() || !*(type.get())) {\r
+                        log.warn("SessionInitiator element has no type attribute, skipping it...");\r
                         child = XMLHelper::getNextSiblingElement(child);\r
                         continue;\r
                     }\r
-                    handler=conf.SessionInitiatorManager.newPlugin(bindprop.get(),child);\r
+                    SessionInitiator* sihandler=conf.SessionInitiatorManager.newPlugin(type.get(),make_pair(child, getId()));\r
+                    handler=sihandler;\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
+                        m_sessionInitMap[si_id.second]=sihandler;\r
                     if (!hardSessionInit) {\r
                         pair<bool,bool> defprop=handler->getBool("isDefault");\r
                         if (defprop.first) {\r
                             if (defprop.second) {\r
                                 hardSessionInit=true;\r
-                                m_sessionInitDefault=handler;\r
+                                m_sessionInitDefault=sihandler;\r
                             }\r
                         }\r
                         else if (!m_sessionInitDefault)\r
-                            m_sessionInitDefault=handler;\r
+                            m_sessionInitDefault=sihandler;\r
                     }\r
                 }\r
                 else if (XMLHelper::isNodeNamed(child,samlconstants::SAML20MD_NS,SingleLogoutService::LOCAL_NAME)) {\r
@@ -418,7 +437,7 @@ XMLApplication::XMLApplication(
                         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
@@ -427,7 +446,7 @@ XMLApplication::XMLApplication(
                         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
@@ -436,7 +455,7 @@ XMLApplication::XMLApplication(
                         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
@@ -462,12 +481,8 @@ XMLApplication::XMLApplication(
             if (nlist->item(i)->getParentNode()->isSameNode(e) && nlist->item(i)->hasChildNodes())\r
                 m_audiences.push_back(nlist->item(i)->getFirstChild()->getNodeValue());\r
 \r
-        // Always include our own providerId as an audience.\r
-        m_audiences.push_back(getXMLString("providerId").second);\r
-\r
-        if (conf.isEnabled(SPConfig::AttributeResolver)) {\r
-            // TODO\r
-        }\r
+        // Always include our own entityID as an audience.\r
+        m_audiences.push_back(getXMLString("entityID").second);\r
 \r
         if (conf.isEnabled(SPConfig::Metadata)) {\r
             child = XMLHelper::getFirstChildElement(e,_MetadataProvider);\r
@@ -494,21 +509,74 @@ XMLApplication::XMLApplication(
                     m_trust = xmlConf.TrustEngineManager.newPlugin(type.get(),child);\r
                 }\r
                 catch (exception& ex) {\r
-                    log.crit("error building TrustEngine: %s",ex.what());\r
+                    log.crit("error building TrustEngine: %s", ex.what());\r
                 }\r
             }\r
         }\r
-        \r
-        // Finally, load credential mappings.\r
-        child = XMLHelper::getFirstChildElement(e,CredentialUse);\r
+\r
+        if (conf.isEnabled(SPConfig::AttributeResolution)) {\r
+            child = XMLHelper::getFirstChildElement(e,_AttributeExtractor);\r
+            if (child) {\r
+                auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
+                log.info("building AttributeExtractor of type %s...",type.get());\r
+                try {\r
+                    m_attrExtractor = conf.AttributeExtractorManager.newPlugin(type.get(),child);\r
+                }\r
+                catch (exception& ex) {\r
+                    log.crit("error building AttributeExtractor: %s", ex.what());\r
+                }\r
+            }\r
+\r
+            child = XMLHelper::getFirstChildElement(e,_AttributeFilter);\r
+            if (child) {\r
+                auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
+                log.info("building AttributeFilter of type %s...",type.get());\r
+                try {\r
+                    m_attrFilter = conf.AttributeFilterManager.newPlugin(type.get(),child);\r
+                }\r
+                catch (exception& ex) {\r
+                    log.crit("error building AttributeFilter: %s", ex.what());\r
+                }\r
+            }\r
+\r
+            child = XMLHelper::getFirstChildElement(e,_AttributeResolver);\r
+            if (child) {\r
+                auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
+                log.info("building AttributeResolver of type %s...",type.get());\r
+                try {\r
+                    m_attrResolver = conf.AttributeResolverManager.newPlugin(type.get(),child);\r
+                }\r
+                catch (exception& ex) {\r
+                    log.crit("error building AttributeResolver: %s", ex.what());\r
+                }\r
+            }\r
+        }\r
+\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,opensaml::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
@@ -532,22 +600,24 @@ XMLApplication::XMLApplication(
 \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_attrFilter;\r
+    delete m_attrExtractor;\r
     delete m_trust;\r
     delete m_metadata;\r
 }\r
 \r
 short XMLApplication::acceptNode(const DOMNode* node) const\r
 {\r
-    if (XMLHelper::isNodeNamed(node,samlconstants::SAML20_NS,opensaml::saml2::Attribute::LOCAL_NAME))\r
+    if (XMLHelper::isNodeNamed(node,samlconstants::SAML20_NS,saml2::Attribute::LOCAL_NAME))\r
         return FILTER_REJECT;\r
     else if (XMLHelper::isNodeNamed(node,samlconstants::SAML20_NS,Audience::LOCAL_NAME))\r
         return FILTER_REJECT;\r
@@ -556,100 +626,43 @@ short XMLApplication::acceptNode(const DOMNode* node) const
         XMLString::equals(name,AssertionConsumerService::LOCAL_NAME) ||\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,_SessionInitiator) ||\r
+        XMLString::equals(name,DefaultRelyingParty) ||\r
         XMLString::equals(name,RelyingParty) ||\r
         XMLString::equals(name,_MetadataProvider) ||\r
-        XMLString::equals(name,_TrustEngine))\r
+        XMLString::equals(name,_TrustEngine) ||\r
+        XMLString::equals(name,_CredentialResolver) ||\r
+        XMLString::equals(name,_AttributeFilter) ||\r
+        XMLString::equals(name,_AttributeExtractor) ||\r
+        XMLString::equals(name,_AttributeResolver))\r
         return FILTER_REJECT;\r
 \r
     return FILTER_ACCEPT;\r
 }\r
 \r
-pair<bool,bool> XMLApplication::getBool(const char* name, const char* ns) const\r
-{\r
-    pair<bool,bool> ret=DOMPropertySet::getBool(name,ns);\r
-    if (ret.first)\r
-        return ret;\r
-    return m_base ? m_base->getBool(name,ns) : ret;\r
-}\r
-\r
-pair<bool,const char*> XMLApplication::getString(const char* name, const char* ns) const\r
+const PropertySet* XMLApplication::getRelyingParty(const EntityDescriptor* provider) const\r
 {\r
-    pair<bool,const char*> ret=DOMPropertySet::getString(name,ns);\r
-    if (ret.first)\r
-        return ret;\r
-    return m_base ? m_base->getString(name,ns) : ret;\r
-}\r
-\r
-pair<bool,const XMLCh*> XMLApplication::getXMLString(const char* name, const char* ns) const\r
-{\r
-    pair<bool,const XMLCh*> ret=DOMPropertySet::getXMLString(name,ns);\r
-    if (ret.first)\r
-        return ret;\r
-    return m_base ? m_base->getXMLString(name,ns) : ret;\r
-}\r
-\r
-pair<bool,unsigned int> XMLApplication::getUnsignedInt(const char* name, const char* ns) const\r
-{\r
-    pair<bool,unsigned int> ret=DOMPropertySet::getUnsignedInt(name,ns);\r
-    if (ret.first)\r
-        return ret;\r
-    return m_base ? m_base->getUnsignedInt(name,ns) : ret;\r
-}\r
-\r
-pair<bool,int> XMLApplication::getInt(const char* name, const char* ns) const\r
-{\r
-    pair<bool,int> ret=DOMPropertySet::getInt(name,ns);\r
-    if (ret.first)\r
-        return ret;\r
-    return m_base ? m_base->getInt(name,ns) : ret;\r
-}\r
-\r
-const PropertySet* XMLApplication::getPropertySet(const char* name, const char* ns) const\r
-{\r
-    const PropertySet* ret=DOMPropertySet::getPropertySet(name,ns);\r
-    if (ret || !m_base)\r
-        return ret;\r
-    return m_base->getPropertySet(name,ns);\r
-}\r
-\r
-MetadataProvider* XMLApplication::getMetadataProvider() const\r
-{\r
-    return (!m_metadata && m_base) ? m_base->getMetadataProvider() : m_metadata;\r
-}\r
-\r
-TrustEngine* XMLApplication::getTrustEngine() const\r
-{\r
-    return (!m_trust && m_base) ? m_base->getTrustEngine() : m_trust;\r
-}\r
-\r
-const vector<const XMLCh*>& XMLApplication::getAudiences() const\r
-{\r
-    return (m_audiences.empty() && m_base) ? m_base->getAudiences() : m_audiences;\r
-}\r
-\r
-const PropertySet* XMLApplication::getCredentialUse(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
@@ -660,18 +673,18 @@ const PropertySet* XMLApplication::getCredentialUse(const EntityDescriptor* prov
         }\r
     }\r
 #endif\r
-    return m_credDefault;\r
+    return m_partyDefault;\r
 }\r
 \r
-const Handler* XMLApplication::getDefaultSessionInitiator() const\r
+const SessionInitiator* XMLApplication::getDefaultSessionInitiator() const\r
 {\r
     if (m_sessionInitDefault) return m_sessionInitDefault;\r
     return m_base ? m_base->getDefaultSessionInitiator() : NULL;\r
 }\r
 \r
-const Handler* XMLApplication::getSessionInitiatorById(const char* id) const\r
+const SessionInitiator* XMLApplication::getSessionInitiatorById(const char* id) const\r
 {\r
-    map<string,const Handler*>::const_iterator i=m_sessionInitMap.find(id);\r
+    map<string,const SessionInitiator*>::const_iterator i=m_sessionInitMap.find(id);\r
     if (i!=m_sessionInitMap.end()) return i->second;\r
     return m_base ? m_base->getSessionInitiatorById(id) : NULL;\r
 }\r
@@ -717,7 +730,7 @@ short XMLConfigImpl::acceptNode(const DOMNode* node) const
         return FILTER_ACCEPT;\r
     const XMLCh* name=node->getLocalName();\r
     if (XMLString::equals(name,Applications) ||\r
-        XMLString::equals(name,Credentials) ||\r
+        XMLString::equals(name,_ArtifactMap) ||\r
         XMLString::equals(name,Extensions::LOCAL_NAME) ||\r
         XMLString::equals(name,Implementation) ||\r
         XMLString::equals(name,Listener) ||\r
@@ -762,12 +775,12 @@ void XMLConfigImpl::doExtensions(const DOMElement* e, const char* label, Categor
     }\r
 }\r
 \r
-XMLConfigImpl::XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer) : m_requestMapper(NULL), m_outer(outer), m_document(NULL)\r
+XMLConfigImpl::XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer, Category& log)\r
+    : m_requestMapper(NULL), m_outer(outer), m_document(NULL)\r
 {\r
 #ifdef _DEBUG\r
     xmltooling::NDC ndc("XMLConfigImpl");\r
 #endif\r
-    Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");\r
 \r
     try {\r
         SPConfig& conf=SPConfig::getConfig();\r
@@ -912,10 +925,32 @@ XMLConfigImpl::XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* o
                         replaySS = m_outer->m_storage[inmemID];\r
                     }\r
                     xmlConf.setReplayCache(new ReplayCache(replaySS));\r
+                    \r
+                    // ArtifactMap\r
+                    child=XMLHelper::getFirstChildElement(SHAR,_ArtifactMap);\r
+                    if (child) {\r
+                        auto_ptr_char ssid(child->getAttributeNS(NULL,_StorageService));\r
+                        if (ssid.get() && *ssid.get() && m_outer->m_storage.count(ssid.get())) {\r
+                            log.info("building ArtifactMap on top of StorageService (%s)...", ssid.get());\r
+                            samlConf.setArtifactMap(new ArtifactMap(child, m_outer->m_storage[ssid.get()]));\r
+                        }\r
+                    }\r
+                    if (samlConf.getArtifactMap()==NULL) {\r
+                        log.info("building in-memory ArtifactMap...");\r
+                        samlConf.setArtifactMap(new ArtifactMap(child));\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
@@ -930,27 +965,6 @@ XMLConfigImpl::XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* o
             }\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
@@ -1014,7 +1028,6 @@ XMLConfigImpl::XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* o
 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
@@ -1032,7 +1045,7 @@ pair<bool,DOMElement*> XMLConfig::load()
     // If we own it, wrap it.\r
     XercesJanitor<DOMDocument> docjanitor(raw.first ? raw.second->getOwnerDocument() : NULL);\r
 \r
-    XMLConfigImpl* impl = new XMLConfigImpl(raw.second,(m_impl==NULL),this);\r
+    XMLConfigImpl* impl = new XMLConfigImpl(raw.second,(m_impl==NULL),this,m_log);\r
     \r
     // If we held the document, transfer it to the impl. If we didn't, it's a no-op.\r
     impl->setDocument(docjanitor.release());\r