Implement artifact generation, start work on resolution support.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Fri, 25 May 2007 16:23:13 +0000 (16:23 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Fri, 25 May 2007 16:23:13 +0000 (16:23 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2262 cb58f699-b61c-0410-a6fe-9272a202ed29

configs/shibboleth.xml.in
schemas/shibboleth-2.0-native-sp-config.xsd
shibsp/Application.h
shibsp/SPConfig.cpp
shibsp/SPConfig.h
shibsp/handler/impl/SAML2SessionInitiator.cpp
shibsp/impl/XMLServiceProvider.cpp

index 93b6bb7..bceda8d 100644 (file)
                                Binding="urn:oasis:names:tc:SAML:1.0:profiles:browser-post"/>
                        <md:AssertionConsumerService Location="/SAML/Artifact" index="4"
                                Binding="urn:oasis:names:tc:SAML:1.0:profiles:artifact-01"/>
+
+                       <!--
+                       md:ArtifactResolutionService elements resolve artifacts issued when using the
+                       SAML 2.0 HTTP-Artifact binding on outgoing messages, generally uses SOAP.
+                       -->
+            <md:ArtifactResolutionService Location="/SOAP/Artifact" index="1"
+                Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP"/>
                        
                        <!--
                        md:SingleLogoutService elements are mostly a placeholder for 2.0, but a simple
                        styleSheet="/shibboleth-sp/main.css"/>
                
                <!-- Configure handling of outgoing messages and SOAP client authentication. -->
-               <DefaultRelyingParty authType="TLS" signRequests="false" encryptRequests="true">
+               <DefaultRelyingParty authType="TLS" signRequests="false" encryptRequests="true" artifactEndpointIndex="1">
                        <!-- Uncomment and modify to tweak settings for specific IdPs or groups. -->
                        <!--
                        <RelyingParty Name="SpecialFederation" keyName="SpecialKey"/>
index 0bf4630..7d27a38 100644 (file)
                        <documentation>Container for specifying protocol handlers and session policy</documentation>\r
                </annotation>\r
                <complexType>\r
-                       <choice maxOccurs="unbounded">\r
+                       <choice minOccurs="0" maxOccurs="unbounded">\r
                                <element ref="conf:SessionInitiator"/>\r
                                <element ref="md:AssertionConsumerService"/>\r
+                               <element ref="md:ArtifactResolutionService"/>\r
                                <element ref="md:SingleLogoutService"/>\r
                                <element ref="md:ManageNameIDService"/>\r
                                <element name="Handler">
                                        <attribute name="URL" type="anyURI"/>\r
                                        <attribute name="outgoingBindings" type="conf:listOfURIs"/>\r
                                        <attribute name="template" type="anyURI"/>\r
+                                       <attribute name="postArtifact" type="boolean"/>\r
                                        <attribute name="acsByIndex" type="boolean"/>\r
                                        <anyAttribute namespace="##any" processContents="lax"/>\r
                                </restriction>\r
                <attribute name="encryptRequests" type="boolean"/>\r
                <attribute name="encryptionAlg" type="anyURI"/>\r
                <attribute name="keyName" type="conf:string"/>\r
+               <attribute name="artifactEndpointIndex" type="unsignedShort"/>\r
        </attributeGroup>\r
        \r
        <element name="SecurityPolicies">
index e76b839..352fca6 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <set>
 #ifndef SHIBSP_LITE
+# include <saml/binding/MessageEncoder.h>
 # include <saml/saml2/metadata/MetadataProvider.h>
 # include <xmltooling/security/CredentialResolver.h>
 # include <xmltooling/security/TrustEngine.h>
@@ -51,6 +52,9 @@ namespace shibsp {
      * of session management and policy.
      */
     class SHIBSP_API Application : public virtual PropertySet
+#ifndef SHIBSP_LITE
+        ,public virtual opensaml::MessageEncoder::ArtifactGenerator
+#endif
     {
         MAKE_NONCOPYABLE(Application);
     protected:
@@ -177,7 +181,7 @@ namespace shibsp {
          * @return the designated SessionInitiator, or NULL
          */
         virtual const SessionInitiator* getSessionInitiatorById(const char* id) const=0;
-        
+
         /**
          * Returns the default AssertionConsumerService Handler
          * for use in AuthnRequest messages.
index 3df7a26..ca0c879 100644 (file)
@@ -194,6 +194,7 @@ void SPInternalConfig::term()
     setArtifactResolver(NULL);
 #endif
 
+    ArtifactResolutionServiceManager.deregisterFactories();
     AssertionConsumerServiceManager.deregisterFactories();
     ManageNameIDServiceManager.deregisterFactories();
     SessionInitiatorManager.deregisterFactories();
index 30fe579..b3a4e23 100644 (file)
@@ -208,6 +208,11 @@ namespace shibsp {
 #endif
 
         /**
+         * Manages factories for Handler plugins that implement ArtifactResolutionService functionality.
+         */
+        xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > ArtifactResolutionServiceManager;
+
+        /**
          * Manages factories for Handler plugins that implement AssertionConsumerService functionality.
          */
         xmltooling::PluginManager< Handler,std::string,std::pair<const xercesc::DOMElement*,const char*> > AssertionConsumerServiceManager;
index 7f1e2a0..5f9e87f 100644 (file)
@@ -32,7 +32,6 @@
 
 #ifndef SHIBSP_LITE
 # include <saml/SAMLConfig.h>
-# include <saml/binding/MessageEncoder.h>
 # include <saml/saml2/core/Protocols.h>
 # include <saml/saml2/metadata/EndpointManager.h>
 # include <saml/saml2/metadata/Metadata.h>
@@ -144,7 +143,7 @@ SAML2SessionInitiator::SAML2SessionInitiator(const DOMElement* e, const char* ap
                 auto_ptr_char b(start);
                 MessageEncoder * encoder = SAMLConfig::getConfig().MessageEncoderManager.newPlugin(b.get(),e);
                 m_encoders[start] = encoder;
-                m_log.info("supporting outgoing binding (%s)", b.get());
+                m_log.debug("supporting outgoing binding (%s)", b.get());
             }
             catch (exception& ex) {
                 m_log.error("error building MessageEncoder: %s", ex.what());
@@ -506,6 +505,7 @@ pair<bool,long> SAML2SessionInitiator::doRequest(
                     dest.get(),
                     entity,
                     relayState.c_str(),
+                    &app,
                     cred,
                     sigalg.second,
                     relyingParty->getXMLString("digestAlg").second
@@ -520,7 +520,7 @@ pair<bool,long> SAML2SessionInitiator::doRequest(
     }
 
     // Unsigned request.
-    long ret = encoder->encode(httpResponse, req.get(), dest.get(), entity, relayState.c_str());
+    long ret = encoder->encode(httpResponse, req.get(), dest.get(), entity, relayState.c_str(), &app);
     req.release();  // freed by encoder
     return make_pair(true,ret);
 #else
index cf479c0..187394f 100644 (file)
-/*\r
- *  Copyright 2001-2007 Internet2\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/**\r
- * XMLServiceProvider.cpp\r
- *\r
- * XML-based SP configuration and mgmt\r
- */\r
-\r
-#include "internal.h"\r
-#include "exceptions.h"\r
-#include "AccessControl.h"\r
-#include "Application.h"\r
-#include "RequestMapper.h"\r
-#include "ServiceProvider.h"\r
-#include "SessionCache.h"\r
-#include "SPConfig.h"\r
-#include "SPRequest.h"\r
-#include "handler/SessionInitiator.h"\r
-#include "remoting/ListenerService.h"\r
-#include "util/DOMPropertySet.h"\r
-#include "util/SPConstants.h"\r
-\r
-#include <log4cpp/Category.hh>\r
-#include <log4cpp/PropertyConfigurator.hh>\r
-#include <xercesc/util/XMLUniDefs.hpp>\r
-#include <xmltooling/XMLToolingConfig.h>\r
-#include <xmltooling/util/NDC.h>\r
-#include <xmltooling/util/ReloadableXMLFile.h>\r
-#include <xmltooling/util/XMLHelper.h>\r
-\r
-#ifndef SHIBSP_LITE\r
-# include "TransactionLog.h"\r
-# include "attribute/filtering/AttributeFilter.h"\r
-# include "attribute/resolver/AttributeExtractor.h"\r
-# include "attribute/resolver/AttributeResolver.h"\r
-# include "security/PKIXTrustEngine.h"\r
-# include <saml/SAMLConfig.h>\r
-# include <saml/binding/ArtifactMap.h>\r
-# include <saml/binding/SAMLArtifact.h>\r
-# include <saml/saml1/core/Assertions.h>\r
-# include <saml/saml2/metadata/ChainingMetadataProvider.h>\r
-# include <xmltooling/security/ChainingTrustEngine.h>\r
-#include <xmltooling/util/ReplayCache.h>\r
-using namespace opensaml::saml2;\r
-using namespace opensaml::saml2md;\r
-using namespace opensaml;\r
-#endif\r
-\r
-using namespace shibsp;\r
-using namespace xmltooling;\r
-using namespace log4cpp;\r
-using namespace std;\r
-\r
-namespace {\r
-\r
-#if defined (_MSC_VER)\r
-    #pragma warning( push )\r
-    #pragma warning( disable : 4250 )\r
-#endif\r
-\r
-    static vector<const Handler*> g_noHandlers;\r
-\r
-    // Application configuration wrapper\r
-    class SHIBSP_DLLLOCAL XMLApplication : public virtual Application, public Remoted, public DOMPropertySet, public DOMNodeFilter\r
-    {\r
-    public:\r
-        XMLApplication(const ServiceProvider*, const DOMElement* e, const XMLApplication* base=NULL);\r
-        ~XMLApplication() { cleanup(); }\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
-\r
-#ifndef SHIBSP_LITE\r
-        MetadataProvider* getMetadataProvider(bool required=true) const {\r
-            if (required && !m_base && !m_metadata)\r
-                throw ConfigurationException("No MetadataProvider available.");\r
-            return (!m_metadata && m_base) ? m_base->getMetadataProvider() : m_metadata;\r
-        }\r
-        TrustEngine* getTrustEngine(bool required=true) const {\r
-            if (required && !m_base && !m_trust)\r
-                throw ConfigurationException("No TrustEngine available.");\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
-        const vector<const XMLCh*>& getAudiences() const {\r
-            return (m_audiences.empty() && m_base) ? m_base->getAudiences() : m_audiences;\r
-        }\r
-#endif\r
-        const set<string>& getRemoteUserAttributeIds() const {\r
-            return (m_remoteUsers.empty() && m_base) ? m_base->getRemoteUserAttributeIds() : m_remoteUsers;\r
-        }\r
-\r
-        void clearAttributeHeaders(SPRequest& request) const;\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
-        void receive(DDF& in, ostream& out) {\r
-            // Only current function is to return the headers to clear.\r
-            DDF header;\r
+/*
+ *  Copyright 2001-2007 Internet2
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * XMLServiceProvider.cpp
+ *
+ * XML-based SP configuration and mgmt
+ */
+
+#include "internal.h"
+#include "exceptions.h"
+#include "AccessControl.h"
+#include "Application.h"
+#include "RequestMapper.h"
+#include "ServiceProvider.h"
+#include "SessionCache.h"
+#include "SPConfig.h"
+#include "SPRequest.h"
+#include "handler/SessionInitiator.h"
+#include "remoting/ListenerService.h"
+#include "util/DOMPropertySet.h"
+#include "util/SPConstants.h"
+
+#include <log4cpp/Category.hh>
+#include <log4cpp/PropertyConfigurator.hh>
+#include <xercesc/util/XMLUniDefs.hpp>
+#include <xmltooling/XMLToolingConfig.h>
+#include <xmltooling/util/NDC.h>
+#include <xmltooling/util/ReloadableXMLFile.h>
+#include <xmltooling/util/XMLHelper.h>
+
+#ifndef SHIBSP_LITE
+# include "TransactionLog.h"
+# include "attribute/filtering/AttributeFilter.h"
+# include "attribute/resolver/AttributeExtractor.h"
+# include "attribute/resolver/AttributeResolver.h"
+# include "security/PKIXTrustEngine.h"
+# include <saml/SAMLConfig.h>
+# include <saml/binding/ArtifactMap.h>
+# include <saml/binding/SAMLArtifact.h>
+# include <saml/saml1/core/Assertions.h>
+# include <saml/saml2/binding/SAML2ArtifactType0004.h>
+# include <saml/saml2/metadata/ChainingMetadataProvider.h>
+# include <xmltooling/security/ChainingTrustEngine.h>
+#include <xmltooling/util/ReplayCache.h>
+using namespace opensaml::saml2;
+using namespace opensaml::saml2p;
+using namespace opensaml::saml2md;
+using namespace opensaml;
+#endif
+
+using namespace shibsp;
+using namespace xmltooling;
+using namespace log4cpp;
+using namespace std;
+
+namespace {
+
+#if defined (_MSC_VER)
+    #pragma warning( push )
+    #pragma warning( disable : 4250 )
+#endif
+
+    static vector<const Handler*> g_noHandlers;
+
+    // Application configuration wrapper
+    class SHIBSP_DLLLOCAL XMLApplication : public Application, public Remoted, public DOMPropertySet, public DOMNodeFilter
+    {
+    public:
+        XMLApplication(const ServiceProvider*, const DOMElement* e, const XMLApplication* base=NULL);
+        ~XMLApplication() { cleanup(); }
+    
+        // Application
+        const ServiceProvider& getServiceProvider() const {return *m_sp;}
+        const char* getId() const {return getString("id").second;}
+        const char* getHash() const {return m_hash.c_str();}
+
+#ifndef SHIBSP_LITE
+        SAMLArtifact* generateSAML1Artifact(const EntityDescriptor* relyingParty) const {
+            throw ConfigurationException("No support for SAML 1.x artifact generation.");
+        }
+        SAML2Artifact* generateSAML2Artifact(const EntityDescriptor* relyingParty) const {
+            pair<bool,int> index = make_pair(false,0);
+            const PropertySet* props = getRelyingParty(relyingParty);
+            if (props)
+                index = getInt("artifactEndpointIndex");
+            if (!index.first)
+                index = getArtifactEndpointIndex();
+            return new SAML2ArtifactType0004(SAMLConfig::getConfig().hashSHA1(getString("entityID").second),index.first ? index.second : 1);
+        }
+
+        MetadataProvider* getMetadataProvider(bool required=true) const {
+            if (required && !m_base && !m_metadata)
+                throw ConfigurationException("No MetadataProvider available.");
+            return (!m_metadata && m_base) ? m_base->getMetadataProvider() : m_metadata;
+        }
+        TrustEngine* getTrustEngine(bool required=true) const {
+            if (required && !m_base && !m_trust)
+                throw ConfigurationException("No TrustEngine available.");
+            return (!m_trust && m_base) ? m_base->getTrustEngine() : m_trust;
+        }
+        AttributeExtractor* getAttributeExtractor() const {
+            return (!m_attrExtractor && m_base) ? m_base->getAttributeExtractor() : m_attrExtractor;
+        }
+        AttributeFilter* getAttributeFilter() const {
+            return (!m_attrFilter && m_base) ? m_base->getAttributeFilter() : m_attrFilter;
+        }
+        AttributeResolver* getAttributeResolver() const {
+            return (!m_attrResolver && m_base) ? m_base->getAttributeResolver() : m_attrResolver;
+        }
+        CredentialResolver* getCredentialResolver() const {
+            return (!m_credResolver && m_base) ? m_base->getCredentialResolver() : m_credResolver;
+        }
+        const PropertySet* getRelyingParty(const EntityDescriptor* provider) const;
+        const vector<const XMLCh*>& getAudiences() const {
+            return (m_audiences.empty() && m_base) ? m_base->getAudiences() : m_audiences;
+        }
+#endif
+        const set<string>& getRemoteUserAttributeIds() const {
+            return (m_remoteUsers.empty() && m_base) ? m_base->getRemoteUserAttributeIds() : m_remoteUsers;
+        }
+
+        void clearAttributeHeaders(SPRequest& request) const;
+        const SessionInitiator* getDefaultSessionInitiator() const;
+        const SessionInitiator* getSessionInitiatorById(const char* id) const;
+        const Handler* getDefaultAssertionConsumerService() const;
+        const Handler* getAssertionConsumerServiceByIndex(unsigned short index) const;
+        const vector<const Handler*>& getAssertionConsumerServicesByBinding(const XMLCh* binding) const;
+        const Handler* getHandler(const char* path) const;
+
+        void receive(DDF& in, ostream& out) {
+            // Only current function is to return the headers to clear.
+            DDF header;
             DDF ret=DDF(NULL).list();
             DDFJanitor jret(ret);
             for (vector<string>::const_iterator i = m_unsetHeaders.begin(); i!=m_unsetHeaders.end(); ++i) {
@@ -136,579 +151,608 @@ namespace {
                 ret.add(header);
             }
             out << ret;
-        }\r
-\r
-        // Provides filter to exclude special config elements.\r
-        short acceptNode(const DOMNode* node) const;\r
-    \r
-    private:\r
-        void cleanup();\r
-        const ServiceProvider* m_sp;   // this is ok because its locking scope includes us\r
-        const XMLApplication* m_base;\r
-        string m_hash;\r
-#ifndef SHIBSP_LITE\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
-#endif\r
-        set<string> m_remoteUsers;\r
-        mutable vector<string> m_unsetHeaders;\r
-        RWLock* m_unsetLock;\r
-\r
-        // manage handler objects\r
-        vector<Handler*> m_handlers;\r
-\r
-        // maps location (path info) to applicable handlers\r
-        map<string,const Handler*> m_handlerMap;\r
-\r
-        // maps unique indexes to consumer services\r
-        map<unsigned int,const Handler*> m_acsIndexMap;\r
-        \r
-        // pointer to default consumer service\r
-        const Handler* m_acsDefault;\r
-\r
-        // maps binding strings to supporting consumer service(s)\r
-#ifdef HAVE_GOOD_STL\r
-        typedef map<xstring,vector<const Handler*> > ACSBindingMap;\r
-#else\r
-        typedef map<string,vector<const Handler*> > ACSBindingMap;\r
-#endif\r
-        ACSBindingMap m_acsBindingMap;\r
-\r
-        // pointer to default session initiator\r
-        const SessionInitiator* m_sessionInitDefault;\r
-\r
-        // maps unique ID strings to session initiators\r
-        map<string,const SessionInitiator*> m_sessionInitMap;\r
-\r
-#ifndef SHIBSP_LITE\r
-        // RelyingParty properties\r
-        DOMPropertySet* m_partyDefault;\r
-#ifdef HAVE_GOOD_STL\r
-        map<xstring,PropertySet*> m_partyMap;\r
-#else\r
-        map<const XMLCh*,PropertySet*> m_partyMap;\r
-#endif\r
-#endif\r
-    };\r
-\r
-    // Top-level configuration implementation\r
-    class SHIBSP_DLLLOCAL XMLConfig;\r
-    class SHIBSP_DLLLOCAL XMLConfigImpl : public DOMPropertySet, public DOMNodeFilter\r
-    {\r
-    public:\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
-#ifndef SHIBSP_LITE\r
-        map< string,pair< PropertySet*,vector<const SecurityPolicyRule*> > > m_policyMap;\r
-#endif\r
-        \r
-        // Provides filter to exclude special config elements.\r
-        short acceptNode(const DOMNode* node) const;\r
-\r
-        void setDocument(DOMDocument* doc) {\r
-            m_document = doc;\r
-        }\r
-\r
-    private:\r
-        void doExtensions(const DOMElement* e, const char* label, Category& log);\r
-\r
-        const XMLConfig* m_outer;\r
-        DOMDocument* m_document;\r
-    };\r
-\r
-    class SHIBSP_DLLLOCAL XMLConfig : public ServiceProvider, public ReloadableXMLFile, public Remoted\r
-    {\r
-    public:\r
-        XMLConfig(const DOMElement* e) : ReloadableXMLFile(e, Category::getInstance(SHIBSP_LOGCAT".Config")),\r
-            m_impl(NULL), m_listener(NULL), m_sessionCache(NULL)\r
-#ifndef SHIBSP_LITE\r
-            , m_tranLog(NULL)\r
-#endif\r
-        {\r
-        }\r
-        \r
-        void init() {\r
-            load();\r
-        }\r
-\r
-        ~XMLConfig() {\r
-            delete m_impl;\r
-            delete m_sessionCache;\r
-            delete m_listener;\r
-#ifndef SHIBSP_LITE\r
-            delete m_tranLog;\r
-            SAMLConfig::getConfig().setArtifactMap(NULL);\r
-            XMLToolingConfig::getConfig().setReplayCache(NULL);\r
-            for_each(m_storage.begin(), m_storage.end(), cleanup_pair<string,StorageService>());\r
-#endif\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:2.0:native:sp:config") const {return m_impl->getPropertySet(name,ns);}\r
-        const DOMElement* getElement() const {return m_impl->getElement();}\r
-\r
-        // Remoted\r
-        void receive(DDF& in, ostream& out);\r
-\r
-        // ServiceProvider\r
-#ifndef SHIBSP_LITE\r
-        TransactionLog* getTransactionLog() const {\r
-            if (m_tranLog)\r
-                return m_tranLog;\r
-            throw ConfigurationException("No TransactionLog available.");\r
-        }\r
-\r
-        StorageService* getStorageService(const char* id) const {\r
-            if (id) {\r
-                map<string,StorageService*>::const_iterator i=m_storage.find(id);\r
-                if (i!=m_storage.end())\r
-                    return i->second;\r
-            }\r
-            return NULL;\r
-        }\r
-#endif\r
-\r
-        ListenerService* getListenerService(bool required=true) const {\r
-            if (required && !m_listener)\r
-                throw ConfigurationException("No ListenerService available.");\r
-            return m_listener;\r
-        }\r
-\r
-        SessionCache* getSessionCache(bool required=true) const {\r
-            if (required && !m_sessionCache)\r
-                throw ConfigurationException("No SessionCache available.");\r
-            return m_sessionCache;\r
-        }\r
-\r
-        RequestMapper* getRequestMapper(bool required=true) const {\r
-            if (required && !m_impl->m_requestMapper)\r
-                throw ConfigurationException("No RequestMapper available.");\r
-            return m_impl->m_requestMapper;\r
-        }\r
-\r
-        const Application* getApplication(const char* applicationId) const {\r
-            map<string,Application*>::const_iterator i=m_impl->m_appmap.find(applicationId);\r
-            return (i!=m_impl->m_appmap.end()) ? i->second : NULL;\r
-        }\r
-\r
-#ifndef SHIBSP_LITE\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
-                return i->second.first;\r
-            throw ConfigurationException("Security Policy ($1) not found, check <SecurityPolicies> element.", params(1,id));\r
-        }\r
-\r
-        const vector<const SecurityPolicyRule*>& getPolicyRules(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
-                return i->second.second;\r
-            throw ConfigurationException("Security Policy ($1) not found, check <SecurityPolicies> element.", params(1,id));\r
-        }\r
-#endif\r
-\r
-    protected:\r
-        pair<bool,DOMElement*> load();\r
-\r
-    private:\r
-        friend class XMLConfigImpl;\r
-        XMLConfigImpl* m_impl;\r
-        mutable ListenerService* m_listener;\r
-        mutable SessionCache* m_sessionCache;\r
-#ifndef SHIBSP_LITE\r
-        mutable TransactionLog* m_tranLog;\r
-        mutable map<string,StorageService*> m_storage;\r
-#endif\r
-    };\r
-\r
-#if defined (_MSC_VER)\r
-    #pragma warning( pop )\r
-#endif\r
-\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 _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 _AssertionConsumerService[] = UNICODE_LITERAL_24(A,s,s,e,r,t,i,o,n,C,o,n,s,u,m,e,r,S,e,r,v,i,c,e);\r
-    static const XMLCh _Audience[] =            UNICODE_LITERAL_8(A,u,d,i,e,n,c,e);\r
-    static const XMLCh Binding[] =              UNICODE_LITERAL_7(B,i,n,d,i,n,g);\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 _Extensions[] =          UNICODE_LITERAL_10(E,x,t,e,n,s,i,o,n,s);\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
-    static const XMLCh Implementation[] =       UNICODE_LITERAL_14(I,m,p,l,e,m,e,n,t,a,t,i,o,n);\r
-    static const XMLCh InProcess[] =            UNICODE_LITERAL_9(I,n,P,r,o,c,e,s,s);\r
-    static const XMLCh Library[] =              UNICODE_LITERAL_7(L,i,b,r,a,r,y);\r
-    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 _ManageNameIDService[] = UNICODE_LITERAL_19(M,a,n,a,g,e,N,a,m,e,I,D,S,e,r,v,i,c,e);\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
-    static const XMLCh _RequestMapper[] =       UNICODE_LITERAL_13(R,e,q,u,e,s,t,M,a,p,p,e,r);\r
-    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 _SingleLogoutService[] = UNICODE_LITERAL_19(S,i,n,g,l,e,L,o,g,o,u,t,S,e,r,v,i,c,e);\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 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 _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
-    public:\r
-        short acceptNode(const DOMNode* node) const {\r
-            if (XMLHelper::isNodeNamed(node,shibspconstants::SHIB2SPCONFIG_NS,Rule))\r
-                return FILTER_REJECT;\r
-            return FILTER_ACCEPT;\r
-        }\r
-    };\r
-};\r
-\r
-namespace shibsp {\r
-    ServiceProvider* XMLServiceProviderFactory(const DOMElement* const & e)\r
-    {\r
-        return new XMLConfig(e);\r
-    }\r
-};\r
-\r
-XMLApplication::XMLApplication(\r
-    const ServiceProvider* sp,\r
-    const DOMElement* e,\r
-    const XMLApplication* base\r
-    ) : m_sp(sp), m_base(base),\r
-#ifndef SHIBSP_LITE\r
-        m_metadata(NULL), m_trust(NULL), m_attrExtractor(NULL), m_attrFilter(NULL), m_attrResolver(NULL), m_credResolver(NULL), m_partyDefault(NULL),\r
-#endif\r
-        m_sessionInitDefault(NULL), m_unsetLock(NULL), m_acsDefault(NULL)\r
-{\r
-#ifdef _DEBUG\r
-    xmltooling::NDC ndc("XMLApplication");\r
-#endif\r
-    Category& log=Category::getInstance(SHIBSP_LOGCAT".Application");\r
-\r
-    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
-#ifndef SHIBSP_LITE\r
-        SAMLConfig& samlConf=SAMLConfig::getConfig();\r
-#endif\r
-        XMLToolingConfig& xmlConf=XMLToolingConfig::getConfig();\r
-\r
-        // This used to be an actual hash, but now it's just a hex-encode to avoid xmlsec.\r
-        static char DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};\r
-        string tohash=getId();\r
-        tohash+=getString("entityID").second;\r
-        for (const char* ch = tohash.c_str(); *ch; ++ch) {\r
-            m_hash += (DIGITS[((unsigned char)(0xF0 & *ch)) >> 4 ]);\r
-            m_hash += (DIGITS[0x0F & *ch]);\r
-        }\r
-\r
-        // Load attribute ID lists for REMOTE_USER and header clearing.\r
-        if (conf.isEnabled(SPConfig::InProcess)) {\r
-            pair<bool,const char*> attributes = getString("REMOTE_USER");\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_remoteUsers.insert(start);\r
-                    start = pos ? pos+1 : NULL;\r
-                }\r
-                free(dup);\r
-            }\r
-\r
-            attributes = getString("unsetHeaders");\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_unsetHeaders.push_back(start);\r
-                    start = pos ? pos+1 : NULL;\r
-                }\r
-                free(dup);\r
-                m_unsetHeaders.push_back("Shib-Application-ID");\r
-            }\r
-        }\r
-\r
-        const PropertySet* sessions = getPropertySet("Sessions");\r
-\r
-        // Process handlers.\r
-        Handler* handler=NULL;\r
-        bool hardACS=false, hardSessionInit=false;\r
-        const DOMElement* child = sessions ? XMLHelper::getFirstChildElement(sessions->getElement()) : NULL;\r
-        while (child) {\r
-            try {\r
-                // A handler is based on the Binding property in conjunction with the element name.\r
-                // If it's an ACS or SI, also handle index/id mappings and defaulting.\r
-                if (XMLString::equals(child->getLocalName(),_AssertionConsumerService)) {\r
-                    auto_ptr_char bindprop(child->getAttributeNS(NULL,Binding));\r
-                    if (!bindprop.get() || !*(bindprop.get())) {\r
-                        log.warn("md:AssertionConsumerService element has no Binding attribute, skipping it...");\r
-                        child = XMLHelper::getNextSiblingElement(child);\r
-                        continue;\r
-                    }\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
-#else\r
-                    m_acsBindingMap[handler->getString("Binding").second].push_back(handler);\r
-#endif\r
-                    m_acsIndexMap[handler->getUnsignedInt("index").second]=handler;\r
-                    \r
-                    if (!hardACS) {\r
-                        pair<bool,bool> defprop=handler->getBool("isDefault");\r
-                        if (defprop.first) {\r
-                            if (defprop.second) {\r
-                                hardACS=true;\r
-                                m_acsDefault=handler;\r
-                            }\r
-                        }\r
-                        else if (!m_acsDefault)\r
-                            m_acsDefault=handler;\r
-                    }\r
-                }\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
-                    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]=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=sihandler;\r
-                            }\r
-                        }\r
-                        else if (!m_sessionInitDefault)\r
-                            m_sessionInitDefault=sihandler;\r
-                    }\r
-                }\r
-                else if (XMLString::equals(child->getLocalName(),_SingleLogoutService)) {\r
-                    auto_ptr_char bindprop(child->getAttributeNS(NULL,Binding));\r
-                    if (!bindprop.get() || !*(bindprop.get())) {\r
-                        log.warn("md:SingleLogoutService element has no Binding attribute, skipping it...");\r
-                        child = XMLHelper::getNextSiblingElement(child);\r
-                        continue;\r
-                    }\r
-                    handler=conf.SingleLogoutServiceManager.newPlugin(bindprop.get(),make_pair(child, getId()));\r
-                }\r
-                else if (XMLString::equals(child->getLocalName(),_ManageNameIDService)) {\r
-                    auto_ptr_char bindprop(child->getAttributeNS(NULL,Binding));\r
-                    if (!bindprop.get() || !*(bindprop.get())) {\r
-                        log.warn("md:ManageNameIDService element has no Binding attribute, skipping it...");\r
-                        child = XMLHelper::getNextSiblingElement(child);\r
-                        continue;\r
-                    }\r
-                    handler=conf.ManageNameIDServiceManager.newPlugin(bindprop.get(),make_pair(child, getId()));\r
-                }\r
-                else {\r
-                    auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
-                    if (!type.get() || !*(type.get())) {\r
-                        log.warn("Handler element has no type attribute, skipping it...");\r
-                        child = XMLHelper::getNextSiblingElement(child);\r
-                        continue;\r
-                    }\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
-                m_handlers.push_back(handler);\r
-\r
-                // Insert into location map.\r
-                pair<bool,const char*> location=handler->getString("Location");\r
-                if (location.first && *location.second == '/')\r
-                    m_handlerMap[location.second]=handler;\r
-                else if (location.first)\r
-                    m_handlerMap[string("/") + location.second]=handler;\r
-\r
-            }\r
-            catch (exception& ex) {\r
-                log.error("caught exception processing handler element: %s", ex.what());\r
-            }\r
-            \r
-            child = XMLHelper::getNextSiblingElement(child);\r
-        }\r
-\r
-#ifndef SHIBSP_LITE\r
-        DOMNodeList* nlist=e->getElementsByTagNameNS(samlconstants::SAML20_NS,Audience::LOCAL_NAME);\r
-        for (XMLSize_t i=0; nlist && i<nlist->getLength(); i++)\r
-            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 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
-            if (child) {\r
-                auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
-                log.info("building MetadataProvider of type %s...",type.get());\r
-                try {\r
-                    auto_ptr<MetadataProvider> mp(samlConf.MetadataProviderManager.newPlugin(type.get(),child));\r
-                    mp->init();\r
-                    m_metadata = mp.release();\r
-                }\r
-                catch (exception& ex) {\r
-                    log.crit("error building/initializing MetadataProvider: %s", ex.what());\r
-                }\r
-            }\r
-        }\r
-\r
-        if (conf.isEnabled(SPConfig::Trust)) {\r
-            child = XMLHelper::getFirstChildElement(e,_TrustEngine);\r
-            if (child) {\r
-                auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
-                log.info("building TrustEngine of type %s...",type.get());\r
-                try {\r
-                    m_trust = xmlConf.TrustEngineManager.newPlugin(type.get(),child);\r
-                }\r
-                catch (exception& ex) {\r
-                    log.crit("error building TrustEngine: %s", ex.what());\r
-                }\r
-            }\r
-        }\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
-            if (m_unsetHeaders.empty()) {\r
-                if (m_attrExtractor) {\r
-                    Locker extlock(m_attrExtractor);\r
-                    m_attrExtractor->getAttributeIds(m_unsetHeaders);\r
-                }\r
-                if (m_attrResolver) {\r
-                    Locker reslock(m_attrResolver);\r
-                    m_attrResolver->getAttributeIds(m_unsetHeaders);\r
-                }\r
-                if (m_base && m_unsetHeaders.empty())\r
-                    m_unsetHeaders.insert(m_unsetHeaders.end(), m_base->m_unsetHeaders.begin(), m_base->m_unsetHeaders.end());\r
-                else\r
-                    m_unsetHeaders.push_back("Shib-Application-ID");\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
-        // Finally, load relying parties.\r
-        child = XMLHelper::getFirstChildElement(e,DefaultRelyingParty);\r
-        if (child) {\r
-            m_partyDefault=new DOMPropertySet();\r
-            m_partyDefault->load(child,log,this);\r
-            child = XMLHelper::getFirstChildElement(child,RelyingParty);\r
-            while (child) {\r
-                auto_ptr<DOMPropertySet> rp(new DOMPropertySet());\r
-                rp->load(child,log,this);\r
-                rp->setParent(m_partyDefault);\r
-                m_partyMap[child->getAttributeNS(NULL,saml2::Attribute::NAME_ATTRIB_NAME)]=rp.release();\r
-                child = XMLHelper::getNextSiblingElement(child,RelyingParty);\r
-            }\r
-        }\r
-#endif\r
-\r
-        // In process only, we need a shared lock around accessing the header clearing list.\r
-        if (!conf.isEnabled(SPConfig::OutOfProcess)) {\r
-            m_unsetLock = RWLock::create();\r
-        }\r
+        }
+
+        // Provides filter to exclude special config elements.
+        short acceptNode(const DOMNode* node) const;
+    
+    private:
+        void cleanup();
+        const ServiceProvider* m_sp;   // this is ok because its locking scope includes us
+        const XMLApplication* m_base;
+        string m_hash;
+#ifndef SHIBSP_LITE
+        MetadataProvider* m_metadata;
+        TrustEngine* m_trust;
+        AttributeExtractor* m_attrExtractor;
+        AttributeFilter* m_attrFilter;
+        AttributeResolver* m_attrResolver;
+        CredentialResolver* m_credResolver;
+        vector<const XMLCh*> m_audiences;
+
+        // RelyingParty properties
+        DOMPropertySet* m_partyDefault;
+#ifdef HAVE_GOOD_STL
+        map<xstring,PropertySet*> m_partyMap;
+#else
+        map<const XMLCh*,PropertySet*> m_partyMap;
+#endif
+#endif
+        set<string> m_remoteUsers;
+        mutable vector<string> m_unsetHeaders;
+        RWLock* m_unsetLock;
+
+        // manage handler objects
+        vector<Handler*> m_handlers;
+
+        // maps location (path info) to applicable handlers
+        map<string,const Handler*> m_handlerMap;
+
+        // maps unique indexes to consumer services
+        map<unsigned int,const Handler*> m_acsIndexMap;
+        
+        // pointer to default consumer service
+        const Handler* m_acsDefault;
+
+        // maps binding strings to supporting consumer service(s)
+#ifdef HAVE_GOOD_STL
+        typedef map<xstring,vector<const Handler*> > ACSBindingMap;
+#else
+        typedef map<string,vector<const Handler*> > ACSBindingMap;
+#endif
+        ACSBindingMap m_acsBindingMap;
+
+        // pointer to default session initiator
+        const SessionInitiator* m_sessionInitDefault;
+
+        // maps unique ID strings to session initiators
+        map<string,const SessionInitiator*> m_sessionInitMap;
+
+        // pointer to default artifact resolution service
+        const Handler* m_artifactResolutionDefault;
+
+        pair<bool,int> getArtifactEndpointIndex() const {
+            if (m_artifactResolutionDefault) return m_artifactResolutionDefault->getInt("index");
+            return m_base ? m_base->getArtifactEndpointIndex() : make_pair(false,0);
+        }
+    };
+
+    // Top-level configuration implementation
+    class SHIBSP_DLLLOCAL XMLConfig;
+    class SHIBSP_DLLLOCAL XMLConfigImpl : public DOMPropertySet, public DOMNodeFilter
+    {
+    public:
+        XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer, Category& log);
+        ~XMLConfigImpl();
+        
+        RequestMapper* m_requestMapper;
+        map<string,Application*> m_appmap;
+#ifndef SHIBSP_LITE
+        map< string,pair< PropertySet*,vector<const SecurityPolicyRule*> > > m_policyMap;
+#endif
+        
+        // Provides filter to exclude special config elements.
+        short acceptNode(const DOMNode* node) const;
+
+        void setDocument(DOMDocument* doc) {
+            m_document = doc;
+        }
+
+    private:
+        void doExtensions(const DOMElement* e, const char* label, Category& log);
+
+        const XMLConfig* m_outer;
+        DOMDocument* m_document;
+    };
+
+    class SHIBSP_DLLLOCAL XMLConfig : public ServiceProvider, public ReloadableXMLFile, public Remoted
+    {
+    public:
+        XMLConfig(const DOMElement* e) : ReloadableXMLFile(e, Category::getInstance(SHIBSP_LOGCAT".Config")),
+            m_impl(NULL), m_listener(NULL), m_sessionCache(NULL)
+#ifndef SHIBSP_LITE
+            , m_tranLog(NULL)
+#endif
+        {
+        }
+        
+        void init() {
+            load();
+        }
+
+        ~XMLConfig() {
+            delete m_impl;
+            delete m_sessionCache;
+            delete m_listener;
+#ifndef SHIBSP_LITE
+            delete m_tranLog;
+            SAMLConfig::getConfig().setArtifactMap(NULL);
+            XMLToolingConfig::getConfig().setReplayCache(NULL);
+            for_each(m_storage.begin(), m_storage.end(), cleanup_pair<string,StorageService>());
+#endif
+        }
+
+        // PropertySet
+        void setParent(const PropertySet* parent) {return m_impl->setParent(parent);}
+        pair<bool,bool> getBool(const char* name, const char* ns=NULL) const {return m_impl->getBool(name,ns);}
+        pair<bool,const char*> getString(const char* name, const char* ns=NULL) const {return m_impl->getString(name,ns);}
+        pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const {return m_impl->getXMLString(name,ns);}
+        pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const {return m_impl->getUnsignedInt(name,ns);}
+        pair<bool,int> getInt(const char* name, const char* ns=NULL) const {return m_impl->getInt(name,ns);}
+        const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:2.0:native:sp:config") const {return m_impl->getPropertySet(name,ns);}
+        const DOMElement* getElement() const {return m_impl->getElement();}
+
+        // Remoted
+        void receive(DDF& in, ostream& out);
+
+        // ServiceProvider
+#ifndef SHIBSP_LITE
+        TransactionLog* getTransactionLog() const {
+            if (m_tranLog)
+                return m_tranLog;
+            throw ConfigurationException("No TransactionLog available.");
+        }
+
+        StorageService* getStorageService(const char* id) const {
+            if (id) {
+                map<string,StorageService*>::const_iterator i=m_storage.find(id);
+                if (i!=m_storage.end())
+                    return i->second;
+            }
+            return NULL;
+        }
+#endif
+
+        ListenerService* getListenerService(bool required=true) const {
+            if (required && !m_listener)
+                throw ConfigurationException("No ListenerService available.");
+            return m_listener;
+        }
+
+        SessionCache* getSessionCache(bool required=true) const {
+            if (required && !m_sessionCache)
+                throw ConfigurationException("No SessionCache available.");
+            return m_sessionCache;
+        }
+
+        RequestMapper* getRequestMapper(bool required=true) const {
+            if (required && !m_impl->m_requestMapper)
+                throw ConfigurationException("No RequestMapper available.");
+            return m_impl->m_requestMapper;
+        }
+
+        const Application* getApplication(const char* applicationId) const {
+            map<string,Application*>::const_iterator i=m_impl->m_appmap.find(applicationId);
+            return (i!=m_impl->m_appmap.end()) ? i->second : NULL;
+        }
+
+#ifndef SHIBSP_LITE
+        const PropertySet* getPolicySettings(const char* id) const {
+            map<string,pair<PropertySet*,vector<const SecurityPolicyRule*> > >::const_iterator i = m_impl->m_policyMap.find(id);
+            if (i!=m_impl->m_policyMap.end())
+                return i->second.first;
+            throw ConfigurationException("Security Policy ($1) not found, check <SecurityPolicies> element.", params(1,id));
+        }
+
+        const vector<const SecurityPolicyRule*>& getPolicyRules(const char* id) const {
+            map<string,pair<PropertySet*,vector<const SecurityPolicyRule*> > >::const_iterator i = m_impl->m_policyMap.find(id);
+            if (i!=m_impl->m_policyMap.end())
+                return i->second.second;
+            throw ConfigurationException("Security Policy ($1) not found, check <SecurityPolicies> element.", params(1,id));
+        }
+#endif
+
+    protected:
+        pair<bool,DOMElement*> load();
+
+    private:
+        friend class XMLConfigImpl;
+        XMLConfigImpl* m_impl;
+        mutable ListenerService* m_listener;
+        mutable SessionCache* m_sessionCache;
+#ifndef SHIBSP_LITE
+        mutable TransactionLog* m_tranLog;
+        mutable map<string,StorageService*> m_storage;
+#endif
+    };
+
+#if defined (_MSC_VER)
+    #pragma warning( pop )
+#endif
+
+    static const XMLCh _Application[] =         UNICODE_LITERAL_11(A,p,p,l,i,c,a,t,i,o,n);
+    static const XMLCh Applications[] =         UNICODE_LITERAL_12(A,p,p,l,i,c,a,t,i,o,n,s);
+    static const XMLCh _ArtifactMap[] =         UNICODE_LITERAL_11(A,r,t,i,f,a,c,t,M,a,p);
+    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);
+    static const XMLCh _AttributeFilter[] =     UNICODE_LITERAL_15(A,t,t,r,i,b,u,t,e,F,i,l,t,e,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);
+    static const XMLCh _AssertionConsumerService[] = UNICODE_LITERAL_24(A,s,s,e,r,t,i,o,n,C,o,n,s,u,m,e,r,S,e,r,v,i,c,e);
+    static const XMLCh _ArtifactResolutionService[] =UNICODE_LITERAL_25(A,r,t,i,f,a,c,t,R,e,s,o,l,u,t,i,o,n,S,e,r,v,i,c,e);
+    static const XMLCh _Audience[] =            UNICODE_LITERAL_8(A,u,d,i,e,n,c,e);
+    static const XMLCh Binding[] =              UNICODE_LITERAL_7(B,i,n,d,i,n,g);
+    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);
+    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);
+    static const XMLCh _Extensions[] =          UNICODE_LITERAL_10(E,x,t,e,n,s,i,o,n,s);
+    static const XMLCh fatal[] =                UNICODE_LITERAL_5(f,a,t,a,l);
+    static const XMLCh _Handler[] =             UNICODE_LITERAL_7(H,a,n,d,l,e,r);
+    static const XMLCh _id[] =                  UNICODE_LITERAL_2(i,d);
+    static const XMLCh Implementation[] =       UNICODE_LITERAL_14(I,m,p,l,e,m,e,n,t,a,t,i,o,n);
+    static const XMLCh InProcess[] =            UNICODE_LITERAL_9(I,n,P,r,o,c,e,s,s);
+    static const XMLCh Library[] =              UNICODE_LITERAL_7(L,i,b,r,a,r,y);
+    static const XMLCh Listener[] =             UNICODE_LITERAL_8(L,i,s,t,e,n,e,r);
+    static const XMLCh logger[] =               UNICODE_LITERAL_6(l,o,g,g,e,r);
+    static const XMLCh _ManageNameIDService[] = UNICODE_LITERAL_19(M,a,n,a,g,e,N,a,m,e,I,D,S,e,r,v,i,c,e);
+    static const XMLCh MemoryListener[] =       UNICODE_LITERAL_14(M,e,m,o,r,y,L,i,s,t,e,n,e,r);
+    static const XMLCh _MetadataProvider[] =    UNICODE_LITERAL_16(M,e,t,a,d,a,t,a,P,r,o,v,i,d,e,r);
+    static const XMLCh OutOfProcess[] =         UNICODE_LITERAL_12(O,u,t,O,f,P,r,o,c,e,s,s);
+    static const XMLCh _path[] =                UNICODE_LITERAL_4(p,a,t,h);
+    static const XMLCh Policy[] =               UNICODE_LITERAL_6(P,o,l,i,c,y);
+    static const XMLCh RelyingParty[] =         UNICODE_LITERAL_12(R,e,l,y,i,n,g,P,a,r,t,y);
+    static const XMLCh _ReplayCache[] =         UNICODE_LITERAL_11(R,e,p,l,a,y,C,a,c,h,e);
+    static const XMLCh _RequestMapper[] =       UNICODE_LITERAL_13(R,e,q,u,e,s,t,M,a,p,p,e,r);
+    static const XMLCh Rule[] =                 UNICODE_LITERAL_4(R,u,l,e);
+    static const XMLCh SecurityPolicies[] =     UNICODE_LITERAL_16(S,e,c,u,r,i,t,y,P,o,l,i,c,i,e,s);
+    static const XMLCh _SessionCache[] =        UNICODE_LITERAL_12(S,e,s,s,i,o,n,C,a,c,h,e);
+    static const XMLCh _SessionInitiator[] =    UNICODE_LITERAL_16(S,e,s,s,i,o,n,I,n,i,t,i,a,t,o,r);
+    static const XMLCh _SingleLogoutService[] = UNICODE_LITERAL_19(S,i,n,g,l,e,L,o,g,o,u,t,S,e,r,v,i,c,e);
+    static const XMLCh _StorageService[] =      UNICODE_LITERAL_14(S,t,o,r,a,g,e,S,e,r,v,i,c,e);
+    static const XMLCh TCPListener[] =          UNICODE_LITERAL_11(T,C,P,L,i,s,t,e,n,e,r);
+    static const XMLCh _TrustEngine[] =         UNICODE_LITERAL_11(T,r,u,s,t,E,n,g,i,n,e);
+    static const XMLCh _type[] =                UNICODE_LITERAL_4(t,y,p,e);
+    static const XMLCh UnixListener[] =         UNICODE_LITERAL_12(U,n,i,x,L,i,s,t,e,n,e,r);
+
+    class SHIBSP_DLLLOCAL PolicyNodeFilter : public DOMNodeFilter
+    {
+    public:
+        short acceptNode(const DOMNode* node) const {
+            if (XMLHelper::isNodeNamed(node,shibspconstants::SHIB2SPCONFIG_NS,Rule))
+                return FILTER_REJECT;
+            return FILTER_ACCEPT;
+        }
+    };
+};
+
+namespace shibsp {
+    ServiceProvider* XMLServiceProviderFactory(const DOMElement* const & e)
+    {
+        return new XMLConfig(e);
+    }
+};
+
+XMLApplication::XMLApplication(
+    const ServiceProvider* sp,
+    const DOMElement* e,
+    const XMLApplication* base
+    ) : m_sp(sp), m_base(base),
+#ifndef SHIBSP_LITE
+        m_metadata(NULL), m_trust(NULL),
+        m_attrExtractor(NULL), m_attrFilter(NULL), m_attrResolver(NULL),
+        m_credResolver(NULL), m_partyDefault(NULL),
+#endif
+        m_unsetLock(NULL), m_acsDefault(NULL), m_sessionInitDefault(NULL), m_artifactResolutionDefault(NULL)
+{
+#ifdef _DEBUG
+    xmltooling::NDC ndc("XMLApplication");
+#endif
+    Category& log=Category::getInstance(SHIBSP_LOGCAT".Application");
+
+    try {
+        // First load any property sets.
+        load(e,log,this);
+        if (base)
+            setParent(base);
+
+        SPConfig& conf=SPConfig::getConfig();
+#ifndef SHIBSP_LITE
+        SAMLConfig& samlConf=SAMLConfig::getConfig();
+#endif
+        XMLToolingConfig& xmlConf=XMLToolingConfig::getConfig();
+
+        // This used to be an actual hash, but now it's just a hex-encode to avoid xmlsec.
+        static char DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+        string tohash=getId();
+        tohash+=getString("entityID").second;
+        for (const char* ch = tohash.c_str(); *ch; ++ch) {
+            m_hash += (DIGITS[((unsigned char)(0xF0 & *ch)) >> 4 ]);
+            m_hash += (DIGITS[0x0F & *ch]);
+        }
+
+        // Load attribute ID lists for REMOTE_USER and header clearing.
+        if (conf.isEnabled(SPConfig::InProcess)) {
+            pair<bool,const char*> attributes = getString("REMOTE_USER");
+            if (attributes.first) {
+                char* dup = strdup(attributes.second);
+                char* pos;
+                char* start = dup;
+                while (start && *start) {
+                    while (*start && isspace(*start))
+                        start++;
+                    if (!*start)
+                        break;
+                    pos = strchr(start,' ');
+                    if (pos)
+                        *pos=0;
+                    m_remoteUsers.insert(start);
+                    start = pos ? pos+1 : NULL;
+                }
+                free(dup);
+            }
+
+            attributes = getString("unsetHeaders");
+            if (attributes.first) {
+                char* dup = strdup(attributes.second);
+                char* pos;
+                char* start = dup;
+                while (start && *start) {
+                    while (*start && isspace(*start))
+                        start++;
+                    if (!*start)
+                        break;
+                    pos = strchr(start,' ');
+                    if (pos)
+                        *pos=0;
+                    m_unsetHeaders.push_back(start);
+                    start = pos ? pos+1 : NULL;
+                }
+                free(dup);
+                m_unsetHeaders.push_back("Shib-Application-ID");
+            }
+        }
+
+        const PropertySet* sessions = getPropertySet("Sessions");
+
+        // Process handlers.
+        Handler* handler=NULL;
+        bool hardACS=false, hardSessionInit=false, hardArt=false;
+        const DOMElement* child = sessions ? XMLHelper::getFirstChildElement(sessions->getElement()) : NULL;
+        while (child) {
+            try {
+                // A handler is based on the Binding property in conjunction with the element name.
+                // If it's an ACS or SI, also handle index/id mappings and defaulting.
+                if (XMLString::equals(child->getLocalName(),_AssertionConsumerService)) {
+                    auto_ptr_char bindprop(child->getAttributeNS(NULL,Binding));
+                    if (!bindprop.get() || !*(bindprop.get())) {
+                        log.warn("md:AssertionConsumerService element has no Binding attribute, skipping it...");
+                        child = XMLHelper::getNextSiblingElement(child);
+                        continue;
+                    }
+                    handler=conf.AssertionConsumerServiceManager.newPlugin(bindprop.get(),make_pair(child, getId()));
+                    // Map by binding (may be > 1 per binding, e.g. SAML 1.0 vs 1.1)
+#ifdef HAVE_GOOD_STL
+                    m_acsBindingMap[handler->getXMLString("Binding").second].push_back(handler);
+#else
+                    m_acsBindingMap[handler->getString("Binding").second].push_back(handler);
+#endif
+                    m_acsIndexMap[handler->getUnsignedInt("index").second]=handler;
+                    
+                    if (!hardACS) {
+                        pair<bool,bool> defprop=handler->getBool("isDefault");
+                        if (defprop.first) {
+                            if (defprop.second) {
+                                hardACS=true;
+                                m_acsDefault=handler;
+                            }
+                        }
+                        else if (!m_acsDefault)
+                            m_acsDefault=handler;
+                    }
+                }
+                else if (XMLString::equals(child->getLocalName(),_SessionInitiator)) {
+                    auto_ptr_char type(child->getAttributeNS(NULL,_type));
+                    if (!type.get() || !*(type.get())) {
+                        log.warn("SessionInitiator element has no type attribute, skipping it...");
+                        child = XMLHelper::getNextSiblingElement(child);
+                        continue;
+                    }
+                    SessionInitiator* sihandler=conf.SessionInitiatorManager.newPlugin(type.get(),make_pair(child, getId()));
+                    handler=sihandler;
+                    pair<bool,const char*> si_id=handler->getString("id");
+                    if (si_id.first && si_id.second)
+                        m_sessionInitMap[si_id.second]=sihandler;
+                    if (!hardSessionInit) {
+                        pair<bool,bool> defprop=handler->getBool("isDefault");
+                        if (defprop.first) {
+                            if (defprop.second) {
+                                hardSessionInit=true;
+                                m_sessionInitDefault=sihandler;
+                            }
+                        }
+                        else if (!m_sessionInitDefault)
+                            m_sessionInitDefault=sihandler;
+                    }
+                }
+                else if (XMLString::equals(child->getLocalName(),_ArtifactResolutionService)) {
+                    auto_ptr_char bindprop(child->getAttributeNS(NULL,Binding));
+                    if (!bindprop.get() || !*(bindprop.get())) {
+                        log.warn("md:ArtifactResolutionService element has no Binding attribute, skipping it...");
+                        child = XMLHelper::getNextSiblingElement(child);
+                        continue;
+                    }
+                    handler=conf.ArtifactResolutionServiceManager.newPlugin(bindprop.get(),make_pair(child, getId()));
+                    
+                    if (!hardArt) {
+                        pair<bool,bool> defprop=handler->getBool("isDefault");
+                        if (defprop.first) {
+                            if (defprop.second) {
+                                hardArt=true;
+                                m_artifactResolutionDefault=handler;
+                            }
+                        }
+                        else if (!m_artifactResolutionDefault)
+                            m_artifactResolutionDefault=handler;
+                    }
+                }
+                else if (XMLString::equals(child->getLocalName(),_SingleLogoutService)) {
+                    auto_ptr_char bindprop(child->getAttributeNS(NULL,Binding));
+                    if (!bindprop.get() || !*(bindprop.get())) {
+                        log.warn("md:SingleLogoutService element has no Binding attribute, skipping it...");
+                        child = XMLHelper::getNextSiblingElement(child);
+                        continue;
+                    }
+                    handler=conf.SingleLogoutServiceManager.newPlugin(bindprop.get(),make_pair(child, getId()));
+                }
+                else if (XMLString::equals(child->getLocalName(),_ManageNameIDService)) {
+                    auto_ptr_char bindprop(child->getAttributeNS(NULL,Binding));
+                    if (!bindprop.get() || !*(bindprop.get())) {
+                        log.warn("md:ManageNameIDService element has no Binding attribute, skipping it...");
+                        child = XMLHelper::getNextSiblingElement(child);
+                        continue;
+                    }
+                    handler=conf.ManageNameIDServiceManager.newPlugin(bindprop.get(),make_pair(child, getId()));
+                }
+                else {
+                    auto_ptr_char type(child->getAttributeNS(NULL,_type));
+                    if (!type.get() || !*(type.get())) {
+                        log.warn("Handler element has no type attribute, skipping it...");
+                        child = XMLHelper::getNextSiblingElement(child);
+                        continue;
+                    }
+                    handler=conf.HandlerManager.newPlugin(type.get(),make_pair(child, getId()));
+                }
+
+                m_handlers.push_back(handler);
+
+                // Insert into location map.
+                pair<bool,const char*> location=handler->getString("Location");
+                if (location.first && *location.second == '/')
+                    m_handlerMap[location.second]=handler;
+                else if (location.first)
+                    m_handlerMap[string("/") + location.second]=handler;
+
+            }
+            catch (exception& ex) {
+                log.error("caught exception processing handler element: %s", ex.what());
+            }
+            
+            child = XMLHelper::getNextSiblingElement(child);
+        }
+
+#ifndef SHIBSP_LITE
+        DOMNodeList* nlist=e->getElementsByTagNameNS(samlconstants::SAML20_NS,Audience::LOCAL_NAME);
+        for (XMLSize_t i=0; nlist && i<nlist->getLength(); i++)
+            if (nlist->item(i)->getParentNode()->isSameNode(e) && nlist->item(i)->hasChildNodes())
+                m_audiences.push_back(nlist->item(i)->getFirstChild()->getNodeValue());
+
+        // Always include our own entityID as an audience.
+        m_audiences.push_back(getXMLString("entityID").second);
+
+        if (conf.isEnabled(SPConfig::Metadata)) {
+            child = XMLHelper::getFirstChildElement(e,_MetadataProvider);
+            if (child) {
+                auto_ptr_char type(child->getAttributeNS(NULL,_type));
+                log.info("building MetadataProvider of type %s...",type.get());
+                try {
+                    auto_ptr<MetadataProvider> mp(samlConf.MetadataProviderManager.newPlugin(type.get(),child));
+                    mp->init();
+                    m_metadata = mp.release();
+                }
+                catch (exception& ex) {
+                    log.crit("error building/initializing MetadataProvider: %s", ex.what());
+                }
+            }
+        }
+
+        if (conf.isEnabled(SPConfig::Trust)) {
+            child = XMLHelper::getFirstChildElement(e,_TrustEngine);
+            if (child) {
+                auto_ptr_char type(child->getAttributeNS(NULL,_type));
+                log.info("building TrustEngine of type %s...",type.get());
+                try {
+                    m_trust = xmlConf.TrustEngineManager.newPlugin(type.get(),child);
+                }
+                catch (exception& ex) {
+                    log.crit("error building TrustEngine: %s", ex.what());
+                }
+            }
+        }
+
+        if (conf.isEnabled(SPConfig::AttributeResolution)) {
+            child = XMLHelper::getFirstChildElement(e,_AttributeExtractor);
+            if (child) {
+                auto_ptr_char type(child->getAttributeNS(NULL,_type));
+                log.info("building AttributeExtractor of type %s...",type.get());
+                try {
+                    m_attrExtractor = conf.AttributeExtractorManager.newPlugin(type.get(),child);
+                }
+                catch (exception& ex) {
+                    log.crit("error building AttributeExtractor: %s", ex.what());
+                }
+            }
+
+            child = XMLHelper::getFirstChildElement(e,_AttributeFilter);
+            if (child) {
+                auto_ptr_char type(child->getAttributeNS(NULL,_type));
+                log.info("building AttributeFilter of type %s...",type.get());
+                try {
+                    m_attrFilter = conf.AttributeFilterManager.newPlugin(type.get(),child);
+                }
+                catch (exception& ex) {
+                    log.crit("error building AttributeFilter: %s", ex.what());
+                }
+            }
+
+            child = XMLHelper::getFirstChildElement(e,_AttributeResolver);
+            if (child) {
+                auto_ptr_char type(child->getAttributeNS(NULL,_type));
+                log.info("building AttributeResolver of type %s...",type.get());
+                try {
+                    m_attrResolver = conf.AttributeResolverManager.newPlugin(type.get(),child);
+                }
+                catch (exception& ex) {
+                    log.crit("error building AttributeResolver: %s", ex.what());
+                }
+            }
+
+            if (m_unsetHeaders.empty()) {
+                if (m_attrExtractor) {
+                    Locker extlock(m_attrExtractor);
+                    m_attrExtractor->getAttributeIds(m_unsetHeaders);
+                }
+                if (m_attrResolver) {
+                    Locker reslock(m_attrResolver);
+                    m_attrResolver->getAttributeIds(m_unsetHeaders);
+                }
+                if (m_base && m_unsetHeaders.empty())
+                    m_unsetHeaders.insert(m_unsetHeaders.end(), m_base->m_unsetHeaders.begin(), m_base->m_unsetHeaders.end());
+                else
+                    m_unsetHeaders.push_back("Shib-Application-ID");
+            }
+        }
+
+        if (conf.isEnabled(SPConfig::Credentials)) {
+            child = XMLHelper::getFirstChildElement(e,_CredentialResolver);
+            if (child) {
+                auto_ptr_char type(child->getAttributeNS(NULL,_type));
+                log.info("building CredentialResolver of type %s...",type.get());
+                try {
+                    m_credResolver = xmlConf.CredentialResolverManager.newPlugin(type.get(),child);
+                }
+                catch (exception& ex) {
+                    log.crit("error building CredentialResolver: %s", ex.what());
+                }
+            }
+        }
+
+        // Finally, load relying parties.
+        child = XMLHelper::getFirstChildElement(e,DefaultRelyingParty);
+        if (child) {
+            m_partyDefault=new DOMPropertySet();
+            m_partyDefault->load(child,log,this);
+            child = XMLHelper::getFirstChildElement(child,RelyingParty);
+            while (child) {
+                auto_ptr<DOMPropertySet> rp(new DOMPropertySet());
+                rp->load(child,log,this);
+                rp->setParent(m_partyDefault);
+                m_partyMap[child->getAttributeNS(NULL,saml2::Attribute::NAME_ATTRIB_NAME)]=rp.release();
+                child = XMLHelper::getNextSiblingElement(child,RelyingParty);
+            }
+        }
+#endif
+
+        // In process only, we need a shared lock around accessing the header clearing list.
+        if (!conf.isEnabled(SPConfig::OutOfProcess)) {
+            m_unsetLock = RWLock::create();
+        }
         else if (!conf.isEnabled(SPConfig::InProcess)) {
             ListenerService* listener = sp->getListenerService(false);
             if (listener) {
@@ -718,170 +762,171 @@ XMLApplication::XMLApplication(
             else
                 log.info("no ListenerService available, Application remoting disabled");
         }
-    }\r
-    catch (exception&) {\r
-        cleanup();\r
-        throw;\r
-    }\r
-#ifndef _DEBUG\r
-    catch (...) {\r
-        cleanup();\r
-        throw;\r
-    }\r
-#endif\r
-}\r
-\r
-void XMLApplication::cleanup()\r
-{\r
+    }
+    catch (exception&) {
+        cleanup();
+        throw;
+    }
+#ifndef _DEBUG
+    catch (...) {
+        cleanup();
+        throw;
+    }
+#endif
+}
+
+void XMLApplication::cleanup()
+{
     ListenerService* listener=getServiceProvider().getListenerService(false);
     if (listener && SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess) && !SPConfig::getConfig().isEnabled(SPConfig::InProcess)) {
         string addr=string(getId()) + "::getHeaders::Application";
         listener->unregListener(addr.c_str(),this);
     }
-    delete m_unsetLock;\r
-    for_each(m_handlers.begin(),m_handlers.end(),xmltooling::cleanup<Handler>());\r
-#ifndef SHIBSP_LITE\r
-    delete m_partyDefault;\r
-#ifdef HAVE_GOOD_STL\r
-    for_each(m_partyMap.begin(),m_partyMap.end(),cleanup_pair<xstring,PropertySet>());\r
-#else\r
-    for_each(m_partyMap.begin(),m_partyMap.end(),cleanup_pair<const XMLCh*,PropertySet>());\r
-#endif\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
-#endif\r
-}\r
-\r
-short XMLApplication::acceptNode(const DOMNode* node) const\r
-{\r
-    const XMLCh* name=node->getLocalName();\r
-    if (XMLString::equals(name,_Application) ||\r
-        XMLString::equals(name,_Audience) ||\r
-        XMLString::equals(name,_AssertionConsumerService) ||\r
-        XMLString::equals(name,_SingleLogoutService) ||\r
-        XMLString::equals(name,_ManageNameIDService) ||\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,_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
-#ifndef SHIBSP_LITE\r
-\r
-const PropertySet* XMLApplication::getRelyingParty(const EntityDescriptor* provider) const\r
-{\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_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_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_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
-        while (group) {\r
-            if (XMLString::equals(i->first,group->getName()))\r
-                return i->second;\r
-            group=dynamic_cast<const EntitiesDescriptor*>(group->getParent());\r
-        }\r
-    }\r
-#endif\r
-    return m_partyDefault;\r
-}\r
-\r
-#endif\r
-\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 SessionInitiator* XMLApplication::getSessionInitiatorById(const char* id) const\r
-{\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
-\r
-const Handler* XMLApplication::getDefaultAssertionConsumerService() const\r
-{\r
-    if (m_acsDefault) return m_acsDefault;\r
-    return m_base ? m_base->getDefaultAssertionConsumerService() : NULL;\r
-}\r
-\r
-const Handler* XMLApplication::getAssertionConsumerServiceByIndex(unsigned short index) const\r
-{\r
-    map<unsigned int,const Handler*>::const_iterator i=m_acsIndexMap.find(index);\r
-    if (i!=m_acsIndexMap.end()) return i->second;\r
-    return m_base ? m_base->getAssertionConsumerServiceByIndex(index) : NULL;\r
-}\r
-\r
-const vector<const Handler*>& XMLApplication::getAssertionConsumerServicesByBinding(const XMLCh* binding) const\r
-{\r
-#ifdef HAVE_GOOD_STL\r
-    ACSBindingMap::const_iterator i=m_acsBindingMap.find(binding);\r
-#else\r
-    auto_ptr_char temp(binding);\r
-    ACSBindingMap::const_iterator i=m_acsBindingMap.find(temp.get());\r
-#endif\r
-    if (i!=m_acsBindingMap.end())\r
-        return i->second;\r
-    return m_base ? m_base->getAssertionConsumerServicesByBinding(binding) : g_noHandlers;\r
-}\r
-\r
-const Handler* XMLApplication::getHandler(const char* path) const\r
-{\r
-    string wrap(path);\r
-    map<string,const Handler*>::const_iterator i=m_handlerMap.find(wrap.substr(0,wrap.find('?')));\r
-    if (i!=m_handlerMap.end())\r
-        return i->second;\r
-    return m_base ? m_base->getHandler(path) : NULL;\r
-}\r
-\r
-void XMLApplication::clearAttributeHeaders(SPRequest& request) const\r
-{\r
-    if (SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess)) {\r
-        for (vector<string>::const_iterator i = m_unsetHeaders.begin(); i!=m_unsetHeaders.end(); ++i)\r
-            request.clearHeader(i->c_str());\r
-        return;\r
-    }\r
-\r
-    m_unsetLock->rdlock();\r
-    if (m_unsetHeaders.empty()) {\r
-        // No headers yet, so we have to request them from the remote half.\r
-        m_unsetLock->unlock();\r
-        m_unsetLock->wrlock();\r
-        if (m_unsetHeaders.empty()) {\r
-            SharedLock wrlock(m_unsetLock, false);\r
-            string addr=string(getId()) + "::getHeaders::Application";\r
+    delete m_unsetLock;
+    for_each(m_handlers.begin(),m_handlers.end(),xmltooling::cleanup<Handler>());
+#ifndef SHIBSP_LITE
+    delete m_partyDefault;
+#ifdef HAVE_GOOD_STL
+    for_each(m_partyMap.begin(),m_partyMap.end(),cleanup_pair<xstring,PropertySet>());
+#else
+    for_each(m_partyMap.begin(),m_partyMap.end(),cleanup_pair<const XMLCh*,PropertySet>());
+#endif
+    delete m_credResolver;
+    delete m_attrResolver;
+    delete m_attrFilter;
+    delete m_attrExtractor;
+    delete m_trust;
+    delete m_metadata;
+#endif
+}
+
+short XMLApplication::acceptNode(const DOMNode* node) const
+{
+    const XMLCh* name=node->getLocalName();
+    if (XMLString::equals(name,_Application) ||
+        XMLString::equals(name,_Audience) ||
+        XMLString::equals(name,_AssertionConsumerService) ||
+        XMLString::equals(name,_ArtifactResolutionService) ||
+        XMLString::equals(name,_SingleLogoutService) ||
+        XMLString::equals(name,_ManageNameIDService) ||
+        XMLString::equals(name,_SessionInitiator) ||
+        XMLString::equals(name,DefaultRelyingParty) ||
+        XMLString::equals(name,RelyingParty) ||
+        XMLString::equals(name,_MetadataProvider) ||
+        XMLString::equals(name,_TrustEngine) ||
+        XMLString::equals(name,_CredentialResolver) ||
+        XMLString::equals(name,_AttributeFilter) ||
+        XMLString::equals(name,_AttributeExtractor) ||
+        XMLString::equals(name,_AttributeResolver))
+        return FILTER_REJECT;
+
+    return FILTER_ACCEPT;
+}
+
+#ifndef SHIBSP_LITE
+
+const PropertySet* XMLApplication::getRelyingParty(const EntityDescriptor* provider) const
+{
+    if (!m_partyDefault && m_base)
+        return m_base->getRelyingParty(provider);
+    else if (!provider)
+        return m_partyDefault;
+        
+#ifdef HAVE_GOOD_STL
+    map<xstring,PropertySet*>::const_iterator i=m_partyMap.find(provider->getEntityID());
+    if (i!=m_partyMap.end())
+        return i->second;
+    const EntitiesDescriptor* group=dynamic_cast<const EntitiesDescriptor*>(provider->getParent());
+    while (group) {
+        if (group->getName()) {
+            i=m_partyMap.find(group->getName());
+            if (i!=m_partyMap.end())
+                return i->second;
+        }
+        group=dynamic_cast<const EntitiesDescriptor*>(group->getParent());
+    }
+#else
+    map<const XMLCh*,PropertySet*>::const_iterator i=m_partyMap.begin();
+    for (; i!=m_partyMap.end(); i++) {
+        if (XMLString::equals(i->first,provider->getId()))
+            return i->second;
+        const EntitiesDescriptor* group=dynamic_cast<const EntitiesDescriptor*>(provider->getParent());
+        while (group) {
+            if (XMLString::equals(i->first,group->getName()))
+                return i->second;
+            group=dynamic_cast<const EntitiesDescriptor*>(group->getParent());
+        }
+    }
+#endif
+    return m_partyDefault;
+}
+
+#endif
+
+const SessionInitiator* XMLApplication::getDefaultSessionInitiator() const
+{
+    if (m_sessionInitDefault) return m_sessionInitDefault;
+    return m_base ? m_base->getDefaultSessionInitiator() : NULL;
+}
+
+const SessionInitiator* XMLApplication::getSessionInitiatorById(const char* id) const
+{
+    map<string,const SessionInitiator*>::const_iterator i=m_sessionInitMap.find(id);
+    if (i!=m_sessionInitMap.end()) return i->second;
+    return m_base ? m_base->getSessionInitiatorById(id) : NULL;
+}
+
+const Handler* XMLApplication::getDefaultAssertionConsumerService() const
+{
+    if (m_acsDefault) return m_acsDefault;
+    return m_base ? m_base->getDefaultAssertionConsumerService() : NULL;
+}
+
+const Handler* XMLApplication::getAssertionConsumerServiceByIndex(unsigned short index) const
+{
+    map<unsigned int,const Handler*>::const_iterator i=m_acsIndexMap.find(index);
+    if (i!=m_acsIndexMap.end()) return i->second;
+    return m_base ? m_base->getAssertionConsumerServiceByIndex(index) : NULL;
+}
+
+const vector<const Handler*>& XMLApplication::getAssertionConsumerServicesByBinding(const XMLCh* binding) const
+{
+#ifdef HAVE_GOOD_STL
+    ACSBindingMap::const_iterator i=m_acsBindingMap.find(binding);
+#else
+    auto_ptr_char temp(binding);
+    ACSBindingMap::const_iterator i=m_acsBindingMap.find(temp.get());
+#endif
+    if (i!=m_acsBindingMap.end())
+        return i->second;
+    return m_base ? m_base->getAssertionConsumerServicesByBinding(binding) : g_noHandlers;
+}
+
+const Handler* XMLApplication::getHandler(const char* path) const
+{
+    string wrap(path);
+    map<string,const Handler*>::const_iterator i=m_handlerMap.find(wrap.substr(0,wrap.find('?')));
+    if (i!=m_handlerMap.end())
+        return i->second;
+    return m_base ? m_base->getHandler(path) : NULL;
+}
+
+void XMLApplication::clearAttributeHeaders(SPRequest& request) const
+{
+    if (SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess)) {
+        for (vector<string>::const_iterator i = m_unsetHeaders.begin(); i!=m_unsetHeaders.end(); ++i)
+            request.clearHeader(i->c_str());
+        return;
+    }
+
+    m_unsetLock->rdlock();
+    if (m_unsetHeaders.empty()) {
+        // No headers yet, so we have to request them from the remote half.
+        m_unsetLock->unlock();
+        m_unsetLock->wrlock();
+        if (m_unsetHeaders.empty()) {
+            SharedLock wrlock(m_unsetLock, false);
+            string addr=string(getId()) + "::getHeaders::Application";
             DDF out,in = DDF(addr.c_str());
             DDFJanitor jin(in),jout(out);
             out = getServiceProvider().getListenerService()->send(in);
@@ -892,357 +937,357 @@ void XMLApplication::clearAttributeHeaders(SPRequest& request) const
                     header = out.next();
                 }
             }
-        }\r
-        else {\r
-            m_unsetLock->unlock();\r
-        }\r
-        m_unsetLock->rdlock();\r
-    }\r
-\r
-    // Now holding read lock.\r
-    SharedLock unsetLock(m_unsetLock, false);\r
-    for (vector<string>::const_iterator i = m_unsetHeaders.begin(); i!=m_unsetHeaders.end(); ++i)\r
-        request.clearHeader(i->c_str());\r
-}\r
-\r
-short XMLConfigImpl::acceptNode(const DOMNode* node) const\r
-{\r
-    if (!XMLString::equals(node->getNamespaceURI(),shibspconstants::SHIB2SPCONFIG_NS))\r
-        return FILTER_ACCEPT;\r
-    const XMLCh* name=node->getLocalName();\r
-    if (XMLString::equals(name,Applications) ||\r
-        XMLString::equals(name,_ArtifactMap) ||\r
-        XMLString::equals(name,_Extensions) ||\r
-        XMLString::equals(name,Implementation) ||\r
-        XMLString::equals(name,Listener) ||\r
-        XMLString::equals(name,MemoryListener) ||\r
-        XMLString::equals(name,Policy) ||\r
-        XMLString::equals(name,_RequestMapper) ||\r
-        XMLString::equals(name,_ReplayCache) ||\r
-        XMLString::equals(name,_SessionCache) ||\r
-        XMLString::equals(name,_StorageService) ||\r
-        XMLString::equals(name,TCPListener) ||\r
-        XMLString::equals(name,UnixListener))\r
-        return FILTER_REJECT;\r
-\r
-    return FILTER_ACCEPT;\r
-}\r
-\r
-void XMLConfigImpl::doExtensions(const DOMElement* e, const char* label, Category& log)\r
-{\r
-    const DOMElement* exts=XMLHelper::getFirstChildElement(e,_Extensions);\r
-    if (exts) {\r
-        exts=XMLHelper::getFirstChildElement(exts,Library);\r
-        while (exts) {\r
-            auto_ptr_char path(exts->getAttributeNS(NULL,_path));\r
-            try {\r
-                if (path.get()) {\r
-                    XMLToolingConfig::getConfig().load_library(path.get(),(void*)exts);\r
-                    log.debug("loaded %s extension library (%s)", label, path.get());\r
-                }\r
-            }\r
-            catch (exception& e) {\r
-                const XMLCh* fatal=exts->getAttributeNS(NULL,fatal);\r
-                if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {\r
-                    log.fatal("unable to load mandatory %s extension library %s: %s", label, path.get(), e.what());\r
-                    throw;\r
-                }\r
-                else {\r
-                    log.crit("unable to load optional %s extension library %s: %s", label, path.get(), e.what());\r
-                }\r
-            }\r
-            exts=XMLHelper::getNextSiblingElement(exts,Library);\r
-        }\r
-    }\r
-}\r
-\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
-\r
-    try {\r
-        SPConfig& conf=SPConfig::getConfig();\r
-#ifndef SHIBSP_LITE\r
-        SAMLConfig& samlConf=SAMLConfig::getConfig();\r
-#endif\r
-        XMLToolingConfig& xmlConf=XMLToolingConfig::getConfig();\r
-        const DOMElement* SHAR=XMLHelper::getFirstChildElement(e,OutOfProcess);\r
-        const DOMElement* SHIRE=XMLHelper::getFirstChildElement(e,InProcess);\r
-\r
-        // Initialize log4cpp manually in order to redirect log messages as soon as possible.\r
-        if (conf.isEnabled(SPConfig::Logging)) {\r
-            const XMLCh* logconf=NULL;\r
-            if (conf.isEnabled(SPConfig::OutOfProcess))\r
-                logconf=SHAR->getAttributeNS(NULL,logger);\r
-            else if (conf.isEnabled(SPConfig::InProcess))\r
-                logconf=SHIRE->getAttributeNS(NULL,logger);\r
-            if (!logconf || !*logconf)\r
-                logconf=e->getAttributeNS(NULL,logger);\r
-            if (logconf && *logconf) {\r
-                auto_ptr_char logpath(logconf);\r
-                log.debug("loading new logging configuration from (%s), check log destination for status of configuration",logpath.get());\r
-                XMLToolingConfig::getConfig().log_config(logpath.get());\r
-            }\r
-            \r
-#ifndef SHIBSP_LITE\r
-            if (first)\r
-                m_outer->m_tranLog = new TransactionLog();\r
-#endif\r
-        }\r
-        \r
-        // First load any property sets.\r
-        load(e,log,this);\r
-\r
-        const DOMElement* child;\r
-        string plugtype;\r
-\r
-        // Much of the processing can only occur on the first instantiation.\r
-        if (first) {\r
-            // Set clock skew.\r
-            pair<bool,unsigned int> skew=getUnsignedInt("clockSkew");\r
-            if (skew.first)\r
-                xmlConf.clock_skew_secs=skew.second;\r
-\r
-            // Extensions\r
-            doExtensions(e, "global", log);\r
-            if (conf.isEnabled(SPConfig::OutOfProcess))\r
-                doExtensions(SHAR, "out of process", log);\r
-\r
-            if (conf.isEnabled(SPConfig::InProcess))\r
-                doExtensions(SHIRE, "in process", log);\r
-            \r
-            // Instantiate the ListenerService and SessionCache objects.\r
-            if (conf.isEnabled(SPConfig::Listener)) {\r
-                child=XMLHelper::getFirstChildElement(SHAR,UnixListener);\r
-                if (child)\r
-                    plugtype=UNIX_LISTENER_SERVICE;\r
-                else {\r
-                    child=XMLHelper::getFirstChildElement(SHAR,TCPListener);\r
-                    if (child)\r
-                        plugtype=TCP_LISTENER_SERVICE;\r
-                    else {\r
-                        child=XMLHelper::getFirstChildElement(SHAR,MemoryListener);\r
-                        if (child)\r
-                            plugtype=MEMORY_LISTENER_SERVICE;\r
-                        else {\r
-                            child=XMLHelper::getFirstChildElement(SHAR,Listener);\r
-                            if (child) {\r
-                                auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
-                                if (type.get())\r
-                                    plugtype=type.get();\r
-                            }\r
-                        }\r
-                    }\r
-                }\r
-                if (child) {\r
-                    log.info("building ListenerService of type %s...", plugtype.c_str());\r
-                    m_outer->m_listener = conf.ListenerServiceManager.newPlugin(plugtype.c_str(),child);\r
-                }\r
-                else {\r
-                    log.fatal("can't build ListenerService, missing conf:Listener element?");\r
-                    throw ConfigurationException("Can't build ListenerService, missing conf:Listener element?");\r
-                }\r
-            }\r
-\r
+        }
+        else {
+            m_unsetLock->unlock();
+        }
+        m_unsetLock->rdlock();
+    }
+
+    // Now holding read lock.
+    SharedLock unsetLock(m_unsetLock, false);
+    for (vector<string>::const_iterator i = m_unsetHeaders.begin(); i!=m_unsetHeaders.end(); ++i)
+        request.clearHeader(i->c_str());
+}
+
+short XMLConfigImpl::acceptNode(const DOMNode* node) const
+{
+    if (!XMLString::equals(node->getNamespaceURI(),shibspconstants::SHIB2SPCONFIG_NS))
+        return FILTER_ACCEPT;
+    const XMLCh* name=node->getLocalName();
+    if (XMLString::equals(name,Applications) ||
+        XMLString::equals(name,_ArtifactMap) ||
+        XMLString::equals(name,_Extensions) ||
+        XMLString::equals(name,Implementation) ||
+        XMLString::equals(name,Listener) ||
+        XMLString::equals(name,MemoryListener) ||
+        XMLString::equals(name,Policy) ||
+        XMLString::equals(name,_RequestMapper) ||
+        XMLString::equals(name,_ReplayCache) ||
+        XMLString::equals(name,_SessionCache) ||
+        XMLString::equals(name,_StorageService) ||
+        XMLString::equals(name,TCPListener) ||
+        XMLString::equals(name,UnixListener))
+        return FILTER_REJECT;
+
+    return FILTER_ACCEPT;
+}
+
+void XMLConfigImpl::doExtensions(const DOMElement* e, const char* label, Category& log)
+{
+    const DOMElement* exts=XMLHelper::getFirstChildElement(e,_Extensions);
+    if (exts) {
+        exts=XMLHelper::getFirstChildElement(exts,Library);
+        while (exts) {
+            auto_ptr_char path(exts->getAttributeNS(NULL,_path));
+            try {
+                if (path.get()) {
+                    XMLToolingConfig::getConfig().load_library(path.get(),(void*)exts);
+                    log.debug("loaded %s extension library (%s)", label, path.get());
+                }
+            }
+            catch (exception& e) {
+                const XMLCh* fatal=exts->getAttributeNS(NULL,fatal);
+                if (fatal && (*fatal==chLatin_t || *fatal==chDigit_1)) {
+                    log.fatal("unable to load mandatory %s extension library %s: %s", label, path.get(), e.what());
+                    throw;
+                }
+                else {
+                    log.crit("unable to load optional %s extension library %s: %s", label, path.get(), e.what());
+                }
+            }
+            exts=XMLHelper::getNextSiblingElement(exts,Library);
+        }
+    }
+}
+
+XMLConfigImpl::XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer, Category& log)
+    : m_requestMapper(NULL), m_outer(outer), m_document(NULL)
+{
+#ifdef _DEBUG
+    xmltooling::NDC ndc("XMLConfigImpl");
+#endif
+
+    try {
+        SPConfig& conf=SPConfig::getConfig();
+#ifndef SHIBSP_LITE
+        SAMLConfig& samlConf=SAMLConfig::getConfig();
+#endif
+        XMLToolingConfig& xmlConf=XMLToolingConfig::getConfig();
+        const DOMElement* SHAR=XMLHelper::getFirstChildElement(e,OutOfProcess);
+        const DOMElement* SHIRE=XMLHelper::getFirstChildElement(e,InProcess);
+
+        // Initialize log4cpp manually in order to redirect log messages as soon as possible.
+        if (conf.isEnabled(SPConfig::Logging)) {
+            const XMLCh* logconf=NULL;
+            if (conf.isEnabled(SPConfig::OutOfProcess))
+                logconf=SHAR->getAttributeNS(NULL,logger);
+            else if (conf.isEnabled(SPConfig::InProcess))
+                logconf=SHIRE->getAttributeNS(NULL,logger);
+            if (!logconf || !*logconf)
+                logconf=e->getAttributeNS(NULL,logger);
+            if (logconf && *logconf) {
+                auto_ptr_char logpath(logconf);
+                log.debug("loading new logging configuration from (%s), check log destination for status of configuration",logpath.get());
+                XMLToolingConfig::getConfig().log_config(logpath.get());
+            }
+            
+#ifndef SHIBSP_LITE
+            if (first)
+                m_outer->m_tranLog = new TransactionLog();
+#endif
+        }
+        
+        // First load any property sets.
+        load(e,log,this);
+
+        const DOMElement* child;
+        string plugtype;
+
+        // Much of the processing can only occur on the first instantiation.
+        if (first) {
+            // Set clock skew.
+            pair<bool,unsigned int> skew=getUnsignedInt("clockSkew");
+            if (skew.first)
+                xmlConf.clock_skew_secs=skew.second;
+
+            // Extensions
+            doExtensions(e, "global", log);
+            if (conf.isEnabled(SPConfig::OutOfProcess))
+                doExtensions(SHAR, "out of process", log);
+
+            if (conf.isEnabled(SPConfig::InProcess))
+                doExtensions(SHIRE, "in process", log);
+            
+            // Instantiate the ListenerService and SessionCache objects.
+            if (conf.isEnabled(SPConfig::Listener)) {
+                child=XMLHelper::getFirstChildElement(SHAR,UnixListener);
+                if (child)
+                    plugtype=UNIX_LISTENER_SERVICE;
+                else {
+                    child=XMLHelper::getFirstChildElement(SHAR,TCPListener);
+                    if (child)
+                        plugtype=TCP_LISTENER_SERVICE;
+                    else {
+                        child=XMLHelper::getFirstChildElement(SHAR,MemoryListener);
+                        if (child)
+                            plugtype=MEMORY_LISTENER_SERVICE;
+                        else {
+                            child=XMLHelper::getFirstChildElement(SHAR,Listener);
+                            if (child) {
+                                auto_ptr_char type(child->getAttributeNS(NULL,_type));
+                                if (type.get())
+                                    plugtype=type.get();
+                            }
+                        }
+                    }
+                }
+                if (child) {
+                    log.info("building ListenerService of type %s...", plugtype.c_str());
+                    m_outer->m_listener = conf.ListenerServiceManager.newPlugin(plugtype.c_str(),child);
+                }
+                else {
+                    log.fatal("can't build ListenerService, missing conf:Listener element?");
+                    throw ConfigurationException("Can't build ListenerService, missing conf:Listener element?");
+                }
+            }
+
             if (m_outer->m_listener && conf.isEnabled(SPConfig::OutOfProcess) && !conf.isEnabled(SPConfig::InProcess)) {
                 m_outer->m_listener->regListener("set::RelayState",m_outer->m_listener);
                 m_outer->m_listener->regListener("get::RelayState",m_outer->m_listener);
             }
-\r
-            if (conf.isEnabled(SPConfig::Caching)) {\r
-                if (conf.isEnabled(SPConfig::OutOfProcess)) {\r
-#ifndef SHIBSP_LITE\r
-                    // First build any StorageServices.\r
-                    string inmemID;\r
-                    child=XMLHelper::getFirstChildElement(SHAR,_StorageService);\r
-                    while (child) {\r
-                        auto_ptr_char id(child->getAttributeNS(NULL,_id));\r
-                        auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
-                        try {\r
-                            log.info("building StorageService (%s) of type %s...", id.get(), type.get());\r
-                            m_outer->m_storage[id.get()] = xmlConf.StorageServiceManager.newPlugin(type.get(),child);\r
-                            if (!strcmp(type.get(),MEMORY_STORAGE_SERVICE))\r
-                                inmemID = id.get();\r
-                        }\r
-                        catch (exception& ex) {\r
-                            log.crit("failed to instantiate StorageService (%s): %s", id.get(), ex.what());\r
-                        }\r
-                        child=XMLHelper::getNextSiblingElement(child,_StorageService);\r
-                    }\r
-                \r
-                    child=XMLHelper::getFirstChildElement(SHAR,_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...",STORAGESERVICE_SESSION_CACHE);\r
-                        if (inmemID.empty()) {\r
-                            inmemID = "memory";\r
-                            log.info("no StorageServices configured, providing in-memory version for session cache");\r
-                            m_outer->m_storage[inmemID] = xmlConf.StorageServiceManager.newPlugin(MEMORY_STORAGE_SERVICE,NULL);\r
-                        }\r
-                        child = e->getOwnerDocument()->createElementNS(NULL,_SessionCache);\r
-                        auto_ptr_XMLCh ssid(inmemID.c_str());\r
-                        const_cast<DOMElement*>(child)->setAttributeNS(NULL,_StorageService,ssid.get());\r
-                        m_outer->m_sessionCache=conf.SessionCacheManager.newPlugin(STORAGESERVICE_SESSION_CACHE,child);\r
-                    }\r
-\r
-                    // Replay cache.\r
-                    StorageService* replaySS=NULL;\r
-                    child=XMLHelper::getFirstChildElement(SHAR,_ReplayCache);\r
-                    if (child) {\r
-                        auto_ptr_char ssid(child->getAttributeNS(NULL,_StorageService));\r
-                        if (ssid.get() && *ssid.get()) {\r
-                            if (m_outer->m_storage.count(ssid.get()))\r
-                                replaySS = m_outer->m_storage[ssid.get()];\r
-                            if (replaySS)\r
-                                log.info("building ReplayCache on top of StorageService (%s)...", ssid.get());\r
-                            else\r
-                                log.crit("unable to locate StorageService (%s) in configuration", ssid.get());\r
-                        }\r
-                    }\r
-                    if (!replaySS) {\r
-                        log.info("building ReplayCache using in-memory StorageService...");\r
-                        if (inmemID.empty()) {\r
-                            inmemID = "memory";\r
-                            log.info("no StorageServices configured, providing in-memory version for legacy config");\r
-                            m_outer->m_storage[inmemID] = xmlConf.StorageServiceManager.newPlugin(MEMORY_STORAGE_SERVICE,NULL);\r
-                        }\r
-                        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
-#endif\r
-                }\r
-                else {\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
-        // Back to the fully dynamic stuff...next up is the RequestMapper.\r
-        if (conf.isEnabled(SPConfig::RequestMapping)) {\r
-            child=XMLHelper::getFirstChildElement(SHIRE,_RequestMapper);\r
-            if (child) {\r
-                auto_ptr_char type(child->getAttributeNS(NULL,_type));\r
-                log.info("building RequestMapper of type %s...",type.get());\r
-                m_requestMapper=conf.RequestMapperManager.newPlugin(type.get(),child);\r
-            }\r
-        }\r
-        \r
-#ifndef SHIBSP_LITE\r
-        // Load security policies.\r
-        child = XMLHelper::getLastChildElement(e,SecurityPolicies);\r
-        if (child) {\r
-            PolicyNodeFilter filter;\r
-            child = XMLHelper::getFirstChildElement(child,Policy);\r
-            while (child) {\r
-                auto_ptr_char id(child->getAttributeNS(NULL,_id));\r
-                pair< PropertySet*,vector<const SecurityPolicyRule*> >& rules = m_policyMap[id.get()];\r
-                rules.first = NULL;\r
-                auto_ptr<DOMPropertySet> settings(new DOMPropertySet());\r
-                settings->load(child, log, &filter);\r
-                rules.first = settings.release();\r
-                const DOMElement* rule = XMLHelper::getFirstChildElement(child,Rule);\r
-                while (rule) {\r
-                    auto_ptr_char type(rule->getAttributeNS(NULL,_type));\r
-                    try {\r
-                        rules.second.push_back(samlConf.SecurityPolicyRuleManager.newPlugin(type.get(),rule));\r
-                    }\r
-                    catch (exception& ex) {\r
-                        log.crit("error instantiating policy rule (%s) in policy (%s): %s", type.get(), id.get(), ex.what());\r
-                    }\r
-                    rule = XMLHelper::getNextSiblingElement(rule,Rule);\r
-                }\r
-                child = XMLHelper::getNextSiblingElement(child,Policy);\r
-            }\r
-        }\r
-#endif\r
-\r
-        // Load the default application. This actually has a fixed ID of "default". ;-)\r
-        child=XMLHelper::getLastChildElement(e,Applications);\r
-        if (!child) {\r
-            log.fatal("can't build default Application object, missing conf:Applications element?");\r
-            throw ConfigurationException("can't build default Application object, missing conf:Applications element?");\r
-        }\r
-        XMLApplication* defapp=new XMLApplication(m_outer,child);\r
-        m_appmap[defapp->getId()]=defapp;\r
-        \r
-        // Load any overrides.\r
-        child = XMLHelper::getFirstChildElement(child,_Application);\r
-        while (child) {\r
-            auto_ptr<XMLApplication> iapp(new XMLApplication(m_outer,child,defapp));\r
-            if (m_appmap.count(iapp->getId()))\r
-                log.crit("found conf:Application element with duplicate id attribute (%s), skipping it", iapp->getId());\r
-            else\r
-                m_appmap[iapp->getId()]=iapp.release();\r
-\r
-            child = XMLHelper::getNextSiblingElement(child,_Application);\r
-        }\r
-    }\r
-    catch (exception&) {\r
-        this->~XMLConfigImpl();\r
-        throw;\r
-    }\r
-#ifndef _DEBUG\r
-    catch (...) {\r
-        this->~XMLConfigImpl();\r
-        throw;\r
-    }\r
-#endif\r
-}\r
-\r
-XMLConfigImpl::~XMLConfigImpl()\r
-{\r
-    for_each(m_appmap.begin(),m_appmap.end(),cleanup_pair<string,Application>());\r
-#ifndef SHIBSP_LITE\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
-    }\r
-#endif\r
-    delete m_requestMapper;\r
-    if (m_document)\r
-        m_document->release();\r
-}\r
-\r
-void XMLConfig::receive(DDF& in, ostream& out)\r
-{\r
-#ifndef SHIBSP_LITE\r
-    if (!strcmp(in.name(), "get::RelayState")) {\r
-        const char* id = in["id"].string();\r
-        const char* key = in["key"].string();\r
-        if (!id || !key)\r
-            throw ListenerException("Required parameters missing for RelayState recovery.");\r
-\r
-        string relayState;\r
+
+            if (conf.isEnabled(SPConfig::Caching)) {
+                if (conf.isEnabled(SPConfig::OutOfProcess)) {
+#ifndef SHIBSP_LITE
+                    // First build any StorageServices.
+                    string inmemID;
+                    child=XMLHelper::getFirstChildElement(SHAR,_StorageService);
+                    while (child) {
+                        auto_ptr_char id(child->getAttributeNS(NULL,_id));
+                        auto_ptr_char type(child->getAttributeNS(NULL,_type));
+                        try {
+                            log.info("building StorageService (%s) of type %s...", id.get(), type.get());
+                            m_outer->m_storage[id.get()] = xmlConf.StorageServiceManager.newPlugin(type.get(),child);
+                            if (!strcmp(type.get(),MEMORY_STORAGE_SERVICE))
+                                inmemID = id.get();
+                        }
+                        catch (exception& ex) {
+                            log.crit("failed to instantiate StorageService (%s): %s", id.get(), ex.what());
+                        }
+                        child=XMLHelper::getNextSiblingElement(child,_StorageService);
+                    }
+                
+                    child=XMLHelper::getFirstChildElement(SHAR,_SessionCache);
+                    if (child) {
+                        auto_ptr_char type(child->getAttributeNS(NULL,_type));
+                        log.info("building SessionCache of type %s...",type.get());
+                        m_outer->m_sessionCache=conf.SessionCacheManager.newPlugin(type.get(),child);
+                    }
+                    else {
+                        log.warn("SessionCache unspecified, building SessionCache of type %s...",STORAGESERVICE_SESSION_CACHE);
+                        if (inmemID.empty()) {
+                            inmemID = "memory";
+                            log.info("no StorageServices configured, providing in-memory version for session cache");
+                            m_outer->m_storage[inmemID] = xmlConf.StorageServiceManager.newPlugin(MEMORY_STORAGE_SERVICE,NULL);
+                        }
+                        child = e->getOwnerDocument()->createElementNS(NULL,_SessionCache);
+                        auto_ptr_XMLCh ssid(inmemID.c_str());
+                        const_cast<DOMElement*>(child)->setAttributeNS(NULL,_StorageService,ssid.get());
+                        m_outer->m_sessionCache=conf.SessionCacheManager.newPlugin(STORAGESERVICE_SESSION_CACHE,child);
+                    }
+
+                    // Replay cache.
+                    StorageService* replaySS=NULL;
+                    child=XMLHelper::getFirstChildElement(SHAR,_ReplayCache);
+                    if (child) {
+                        auto_ptr_char ssid(child->getAttributeNS(NULL,_StorageService));
+                        if (ssid.get() && *ssid.get()) {
+                            if (m_outer->m_storage.count(ssid.get()))
+                                replaySS = m_outer->m_storage[ssid.get()];
+                            if (replaySS)
+                                log.info("building ReplayCache on top of StorageService (%s)...", ssid.get());
+                            else
+                                log.crit("unable to locate StorageService (%s) in configuration", ssid.get());
+                        }
+                    }
+                    if (!replaySS) {
+                        log.info("building ReplayCache using in-memory StorageService...");
+                        if (inmemID.empty()) {
+                            inmemID = "memory";
+                            log.info("no StorageServices configured, providing in-memory version for legacy config");
+                            m_outer->m_storage[inmemID] = xmlConf.StorageServiceManager.newPlugin(MEMORY_STORAGE_SERVICE,NULL);
+                        }
+                        replaySS = m_outer->m_storage[inmemID];
+                    }
+                    xmlConf.setReplayCache(new ReplayCache(replaySS));
+                    
+                    // ArtifactMap
+                    child=XMLHelper::getFirstChildElement(SHAR,_ArtifactMap);
+                    if (child) {
+                        auto_ptr_char ssid(child->getAttributeNS(NULL,_StorageService));
+                        if (ssid.get() && *ssid.get() && m_outer->m_storage.count(ssid.get())) {
+                            log.info("building ArtifactMap on top of StorageService (%s)...", ssid.get());
+                            samlConf.setArtifactMap(new ArtifactMap(child, m_outer->m_storage[ssid.get()]));
+                        }
+                    }
+                    if (samlConf.getArtifactMap()==NULL) {
+                        log.info("building in-memory ArtifactMap...");
+                        samlConf.setArtifactMap(new ArtifactMap(child));
+                    }
+#endif
+                }
+                else {
+                    child=XMLHelper::getFirstChildElement(SHIRE,_SessionCache);
+                    if (child) {
+                        auto_ptr_char type(child->getAttributeNS(NULL,_type));
+                        log.info("building SessionCache of type %s...",type.get());
+                        m_outer->m_sessionCache=conf.SessionCacheManager.newPlugin(type.get(),child);
+                    }
+                    else {
+                        log.warn("SessionCache unspecified, building SessionCache of type %s...",REMOTED_SESSION_CACHE);
+                        m_outer->m_sessionCache=conf.SessionCacheManager.newPlugin(REMOTED_SESSION_CACHE,child);
+                    }
+                }
+            }
+        } // end of first-time-only stuff
+        
+        // Back to the fully dynamic stuff...next up is the RequestMapper.
+        if (conf.isEnabled(SPConfig::RequestMapping)) {
+            child=XMLHelper::getFirstChildElement(SHIRE,_RequestMapper);
+            if (child) {
+                auto_ptr_char type(child->getAttributeNS(NULL,_type));
+                log.info("building RequestMapper of type %s...",type.get());
+                m_requestMapper=conf.RequestMapperManager.newPlugin(type.get(),child);
+            }
+        }
+        
+#ifndef SHIBSP_LITE
+        // Load security policies.
+        child = XMLHelper::getLastChildElement(e,SecurityPolicies);
+        if (child) {
+            PolicyNodeFilter filter;
+            child = XMLHelper::getFirstChildElement(child,Policy);
+            while (child) {
+                auto_ptr_char id(child->getAttributeNS(NULL,_id));
+                pair< PropertySet*,vector<const SecurityPolicyRule*> >& rules = m_policyMap[id.get()];
+                rules.first = NULL;
+                auto_ptr<DOMPropertySet> settings(new DOMPropertySet());
+                settings->load(child, log, &filter);
+                rules.first = settings.release();
+                const DOMElement* rule = XMLHelper::getFirstChildElement(child,Rule);
+                while (rule) {
+                    auto_ptr_char type(rule->getAttributeNS(NULL,_type));
+                    try {
+                        rules.second.push_back(samlConf.SecurityPolicyRuleManager.newPlugin(type.get(),rule));
+                    }
+                    catch (exception& ex) {
+                        log.crit("error instantiating policy rule (%s) in policy (%s): %s", type.get(), id.get(), ex.what());
+                    }
+                    rule = XMLHelper::getNextSiblingElement(rule,Rule);
+                }
+                child = XMLHelper::getNextSiblingElement(child,Policy);
+            }
+        }
+#endif
+
+        // Load the default application. This actually has a fixed ID of "default". ;-)
+        child=XMLHelper::getLastChildElement(e,Applications);
+        if (!child) {
+            log.fatal("can't build default Application object, missing conf:Applications element?");
+            throw ConfigurationException("can't build default Application object, missing conf:Applications element?");
+        }
+        XMLApplication* defapp=new XMLApplication(m_outer,child);
+        m_appmap[defapp->getId()]=defapp;
+        
+        // Load any overrides.
+        child = XMLHelper::getFirstChildElement(child,_Application);
+        while (child) {
+            auto_ptr<XMLApplication> iapp(new XMLApplication(m_outer,child,defapp));
+            if (m_appmap.count(iapp->getId()))
+                log.crit("found conf:Application element with duplicate id attribute (%s), skipping it", iapp->getId());
+            else
+                m_appmap[iapp->getId()]=iapp.release();
+
+            child = XMLHelper::getNextSiblingElement(child,_Application);
+        }
+    }
+    catch (exception&) {
+        this->~XMLConfigImpl();
+        throw;
+    }
+#ifndef _DEBUG
+    catch (...) {
+        this->~XMLConfigImpl();
+        throw;
+    }
+#endif
+}
+
+XMLConfigImpl::~XMLConfigImpl()
+{
+    for_each(m_appmap.begin(),m_appmap.end(),cleanup_pair<string,Application>());
+#ifndef SHIBSP_LITE
+    for (map< string,pair<PropertySet*,vector<const SecurityPolicyRule*> > >::iterator i=m_policyMap.begin(); i!=m_policyMap.end(); ++i) {
+        delete i->second.first;
+        for_each(i->second.second.begin(), i->second.second.end(), xmltooling::cleanup<SecurityPolicyRule>());
+    }
+#endif
+    delete m_requestMapper;
+    if (m_document)
+        m_document->release();
+}
+
+void XMLConfig::receive(DDF& in, ostream& out)
+{
+#ifndef SHIBSP_LITE
+    if (!strcmp(in.name(), "get::RelayState")) {
+        const char* id = in["id"].string();
+        const char* key = in["key"].string();
+        if (!id || !key)
+            throw ListenerException("Required parameters missing for RelayState recovery.");
+
+        string relayState;
         StorageService* storage = getStorageService(id);
         if (storage) {
             if (storage->readString("RelayState",key,&relayState)>0) {
@@ -1260,14 +1305,14 @@ void XMLConfig::receive(DDF& in, ostream& out)
         DDF ret=DDF(NULL).string(relayState.c_str());
         DDFJanitor jret(ret);
         out << ret;
-    }\r
-    else if (!strcmp(in.name(), "set::RelayState")) {\r
-        const char* id = in["id"].string();\r
-        const char* value = in["value"].string();\r
-        if (!id || !value)\r
-            throw ListenerException("Required parameters missing for RelayState creation.");\r
-\r
-        string rsKey;\r
+    }
+    else if (!strcmp(in.name(), "set::RelayState")) {
+        const char* id = in["id"].string();
+        const char* value = in["value"].string();
+        if (!id || !value)
+            throw ListenerException("Required parameters missing for RelayState creation.");
+
+        string rsKey;
         StorageService* storage = getStorageService(id);
         if (storage) {
             SAMLConfig::getConfig().generateRandomBytes(rsKey,20);
@@ -1284,25 +1329,25 @@ void XMLConfig::receive(DDF& in, ostream& out)
         DDF ret=DDF(NULL).string(rsKey.c_str());
         DDFJanitor jret(ret);
         out << ret;
-    }\r
-#endif\r
-}\r
-\r
-pair<bool,DOMElement*> XMLConfig::load()\r
-{\r
-    // Load from source using base class.\r
-    pair<bool,DOMElement*> raw = ReloadableXMLFile::load();\r
-    \r
-    // 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,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
-\r
-    delete m_impl;\r
-    m_impl = impl;\r
-\r
-    return make_pair(false,(DOMElement*)NULL);\r
-}\r
+    }
+#endif
+}
+
+pair<bool,DOMElement*> XMLConfig::load()
+{
+    // Load from source using base class.
+    pair<bool,DOMElement*> raw = ReloadableXMLFile::load();
+    
+    // If we own it, wrap it.
+    XercesJanitor<DOMDocument> docjanitor(raw.first ? raw.second->getOwnerDocument() : NULL);
+
+    XMLConfigImpl* impl = new XMLConfigImpl(raw.second,(m_impl==NULL),this,m_log);
+    
+    // If we held the document, transfer it to the impl. If we didn't, it's a no-op.
+    impl->setDocument(docjanitor.release());
+
+    delete m_impl;
+    m_impl = impl;
+
+    return make_pair(false,(DOMElement*)NULL);
+}