Starting to refactor session cache, eliminated IConfig class.
[shibboleth/cpp-sp.git] / shib-target / shib-config.cpp
index 80360b6..064c61a 100644 (file)
@@ -24,9 +24,7 @@
 
 #include "internal.h"
 #include <shibsp/SPConfig.h>
-#include <shibsp/SPConstants.h>
 #include <xmltooling/XMLToolingConfig.h>
-#include <xmltooling/util/NDC.h>
 
 #include <log4cpp/OstreamAppender.hh>
 
@@ -38,6 +36,7 @@ using namespace log4cpp;
 using namespace std;
 
 using xmltooling::XMLToolingConfig;
+using xmltooling::PluginManager;
 
 namespace {
     STConfig g_Config;
@@ -50,13 +49,12 @@ PlugManager::Factory UnixListenerFactory;
 #endif
 PlugManager::Factory TCPListenerFactory;
 //PlugManager::Factory MemoryListenerFactory;
-PlugManager::Factory MemoryCacheFactory;
-PlugManager::Factory XMLRequestMapFactory;
-PlugManager::Factory ShibSessionInitiatorFactory;
-PlugManager::Factory SAML1POSTFactory;
-PlugManager::Factory SAML1ArtifactFactory;
-PlugManager::Factory ShibLogoutFactory;
-//PlugManager::Factory htaccessFactory;
+
+PluginManager<SessionCache,const DOMElement*>::Factory MemoryCacheFactory;
+PluginManager<Handler,const DOMElement*>::Factory ShibSessionInitiatorFactory;
+PluginManager<Handler,const DOMElement*>::Factory SAML1POSTFactory;
+PluginManager<Handler,const DOMElement*>::Factory SAML1ArtifactFactory;
+PluginManager<Handler,const DOMElement*>::Factory ShibLogoutFactory;
 
 ShibTargetConfig& ShibTargetConfig::getConfig()
 {
@@ -68,7 +66,7 @@ bool STConfig::init(const char* schemadir)
 #ifdef _DEBUG
     xmltooling::NDC ndc("init");
 #endif
-    Category& log = Category::getInstance("shibtarget.Config");
+    Category& log = Category::getInstance(SHIBT_LOGCAT".Config");
 
     if (!schemadir) {
         log.fatal("XML schema directory not supplied");
@@ -80,8 +78,8 @@ bool STConfig::init(const char* schemadir)
     SAMLConfig& samlConf=SAMLConfig::getConfig();
     if (schemadir)
         samlConf.schema_dir = schemadir;
-    if (!samlConf.init() || !SPConfig::getConfig().init(NULL)) {
-        log.fatal("failed to initialize SP library");
+    if (!samlConf.init()) {
+        log.fatal("failed to initialize OpenSAML1 library");
         return false;
     }
 
@@ -91,25 +89,24 @@ bool STConfig::init(const char* schemadir)
         samlConf.term();
         return false;
     }
+    
+    SPConfig& conf=SPConfig::getConfig();
+    if (!SPConfig::getConfig().init(NULL)) {
+        log.fatal("Failed to initialize SP library");
+        shibConf.term();
+        samlConf.term();
+        return false;
+    }
 
     // Register built-in plugin types.
+    conf.ServiceProviderManager.registerFactory(XML_SERVICE_PROVIDER, XMLServiceProviderFactory);
 
-    samlConf.getPlugMgr().regFactory(shibtarget::XML::MemorySessionCacheType,&MemoryCacheFactory);
-    samlConf.getPlugMgr().regFactory(shibtarget::XML::LegacyRequestMapType,&XMLRequestMapFactory);
-    samlConf.getPlugMgr().regFactory(shibtarget::XML::XMLRequestMapType,&XMLRequestMapFactory);
-    samlConf.getPlugMgr().regFactory(shibtarget::XML::NativeRequestMapType,&XMLRequestMapFactory);
+    conf.SessionInitiatorManager.registerFactory(shibspconstants::SHIB1_SESSIONINIT_PROFILE_URI,&ShibSessionInitiatorFactory);
+    conf.AssertionConsumerServiceManager.registerFactory(samlconstants::SAML1_PROFILE_BROWSER_POST,&SAML1POSTFactory);
+    conf.AssertionConsumerServiceManager.registerFactory(samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT,&SAML1ArtifactFactory);
+    conf.SingleLogoutServiceManager.registerFactory(shibspconstants::SHIB1_LOGOUT_PROFILE_URI,&ShibLogoutFactory);
     
-    auto_ptr_char temp1(shibspconstants::SHIB1_SESSIONINIT_PROFILE_URI);
-    samlConf.getPlugMgr().regFactory(temp1.get(),&ShibSessionInitiatorFactory);
-    samlConf.getPlugMgr().regFactory(samlconstants::SAML1_PROFILE_BROWSER_POST,&SAML1POSTFactory);
-    samlConf.getPlugMgr().regFactory(samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT,&SAML1ArtifactFactory);
-    auto_ptr_char temp4(shibspconstants::SHIB1_LOGOUT_PROFILE_URI);
-    samlConf.getPlugMgr().regFactory(temp4.get(),&ShibLogoutFactory);
-    
-    saml::XML::registerSchema(shibtarget::XML::SHIBTARGET_NS,shibtarget::XML::SHIBTARGET_SCHEMA_ID,NULL,false);
-    saml::XML::registerSchema(samlconstants::SAML20MD_NS,shibtarget::XML::SAML2META_SCHEMA_ID,NULL,false);
-    saml::XML::registerSchema(samlconstants::SAML20_NS,shibtarget::XML::SAML2ASSERT_SCHEMA_ID,NULL,false);
-    saml::XML::registerSchema(xmlconstants::XMLENC_NS,shibtarget::XML::XMLENC_SCHEMA_ID,NULL,false);
+    conf.SessionCacheManager.registerFactory(MEMORY_SESSIONCACHE,&MemoryCacheFactory);
     
     log.info("finished initializing");
     return true;
@@ -120,7 +117,7 @@ bool STConfig::load(const char* config)
 #ifdef _DEBUG
     xmltooling::NDC ndc("load");
 #endif
-    Category& log = Category::getInstance("shibtarget.Config");
+    Category& log = Category::getInstance(SHIBT_LOGCAT".Config");
 
     if (!config) {
         log.fatal("path to configuration file not supplied");
@@ -130,20 +127,23 @@ bool STConfig::load(const char* config)
 
     try {
         log.info("loading configuration file: %s", config);
-        static const XMLCh uri[] = { chLatin_u, chLatin_r, chLatin_i, chNull };
+        static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h);
         DOMImplementation* impl=DOMImplementationRegistry::getDOMImplementation(NULL);
         DOMDocument* dummydoc=impl->createDocument();
-        DOMElement* dummy = dummydoc->createElementNS(NULL,XML::Literals::ShibbolethTargetConfig);
+        xmltooling::XercesJanitor<DOMDocument> docjanitor(dummydoc);
+        DOMElement* dummy = dummydoc->createElementNS(NULL,path);
+
         auto_ptr_XMLCh src(config);
-        dummy->setAttributeNS(NULL,uri,src.get());
-        m_ini=ShibTargetConfigFactory(dummy);
-        dummydoc->release();
-        m_ini->init();
+        dummy->setAttributeNS(NULL,path,src.get());
+
+        auto_ptr<ServiceProvider> sp(SPConfig::getConfig().ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy));
+        sp->init();
         
-        pair<bool,unsigned int> skew=m_ini->getUnsignedInt("clockSkew");
+        pair<bool,unsigned int> skew=sp->getUnsignedInt("clockSkew");
         SAMLConfig::getConfig().clock_skew_secs=skew.first ? skew.second : 180;
         if (skew.first)
             XMLToolingConfig::getConfig().clock_skew_secs=skew.second;
+        SPConfig::getConfig().setServiceProvider(sp.release());
         
         m_tranLog=new FixedContextCategory(SHIBTRAN_LOGCAT);
         m_tranLog->info("opened transaction log");
@@ -171,15 +171,13 @@ void STConfig::shutdown()
 #ifdef _DEBUG
     xmltooling::NDC ndc("shutdown");
 #endif
-    Category& log = Category::getInstance("shibtarget.Config");
+    Category& log = Category::getInstance(SHIBT_LOGCAT".Config");
     log.info("shutting down the library");
     delete m_tranLogLock;
     m_tranLogLock = NULL;
     //delete m_tranLog; // This is crashing for some reason, but we're shutting down anyway.
-    delete m_ini;
-    m_ini = NULL;
+    SPConfig::getConfig().term();
     ShibConfig::getConfig().term();
     SAMLConfig::getConfig().term();
-    SPConfig::getConfig().term();
     log.info("library shutdown complete");
 }