From: Scott Cantor Date: Tue, 6 Feb 2007 04:02:43 +0000 (+0000) Subject: Move config logic into an "XML" SP plugin, divorce shibd and modules from old libs. X-Git-Tag: 2.0-alpha1~134 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fcpp-sp.git;a=commitdiff_plain;h=da4d21c738d2c15f1fbd876a4bffb8e363b7bacc Move config logic into an "XML" SP plugin, divorce shibd and modules from old libs. --- diff --git a/Shibboleth.sln b/Shibboleth.sln index beabdcc..fdedcf9 100644 --- a/Shibboleth.sln +++ b/Shibboleth.sln @@ -1,36 +1,52 @@ Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "isapi_shib", "isapi_shib\isapi_shib.vcproj", "{87C25D4E-8D19-4513-B0BA-BC668BC2DEE3}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection ProjectSection(ProjectDependencies) = postProject {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} = {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} - {84890110-2190-4AAE-9BDC-58F90DF71E4F} = {84890110-2190-4AAE-9BDC-58F90DF71E4F} - {E6CAB6C8-1D73-4410-970A-52BF9EC57810} = {E6CAB6C8-1D73-4410-970A-52BF9EC57810} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "isapi_shib_gui", "isapi_shib_gui\isapi_shib_gui.vcproj", "{D341DCD8-7DCD-43A2-8559-C07DAB838711}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_shib13", "apache\mod_shib13.vcproj", "{D243B43E-728E-4F32-BDFF-B3A897037C6D}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection ProjectSection(ProjectDependencies) = postProject {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} = {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} - {84890110-2190-4AAE-9BDC-58F90DF71E4F} = {84890110-2190-4AAE-9BDC-58F90DF71E4F} - {E6CAB6C8-1D73-4410-970A-52BF9EC57810} = {E6CAB6C8-1D73-4410-970A-52BF9EC57810} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_shib20", "apache\mod_shib20.vcproj", "{68E9568B-476C-4289-B93C-893432378ADC}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection ProjectSection(ProjectDependencies) = postProject {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} = {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} - {84890110-2190-4AAE-9BDC-58F90DF71E4F} = {84890110-2190-4AAE-9BDC-58F90DF71E4F} - {E6CAB6C8-1D73-4410-970A-52BF9EC57810} = {E6CAB6C8-1D73-4410-970A-52BF9EC57810} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nsapi_shib", "nsapi_shib\nsapi_shib.vcproj", "{1396D80A-8672-4224-9B02-95F3F4207CDB}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection ProjectSection(ProjectDependencies) = postProject - {E6CAB6C8-1D73-4410-970A-52BF9EC57810} = {E6CAB6C8-1D73-4410-970A-52BF9EC57810} {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} = {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} - {84890110-2190-4AAE-9BDC-58F90DF71E4F} = {84890110-2190-4AAE-9BDC-58F90DF71E4F} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "posttest", "posttest\posttest.vcproj", "{16E70C47-789E-43D5-AFDF-964D386C3CB5}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection ProjectSection(ProjectDependencies) = postProject {E6CAB6C8-1D73-4410-970A-52BF9EC57810} = {E6CAB6C8-1D73-4410-970A-52BF9EC57810} {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} = {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} @@ -38,20 +54,35 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "posttest", "posttest\postte EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shar", "shar\shar.vcproj", "{F13141B5-6C87-40BB-8D4E-5CC56EBB4C59}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection ProjectSection(ProjectDependencies) = postProject {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} = {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} - {84890110-2190-4AAE-9BDC-58F90DF71E4F} = {84890110-2190-4AAE-9BDC-58F90DF71E4F} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shib", "shib\shib.vcproj", "{E6CAB6C8-1D73-4410-970A-52BF9EC57810}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shibtarget", "shib-target\shibtarget.vcproj", "{84890110-2190-4AAE-9BDC-58F90DF71E4F}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection ProjectSection(ProjectDependencies) = postProject {E6CAB6C8-1D73-4410-970A-52BF9EC57810} = {E6CAB6C8-1D73-4410-970A-52BF9EC57810} {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} = {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shibtest", "shibtest\shibtest.vcproj", "{67AF22A3-C26E-40BE-B0CA-2ABEE5123763}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection ProjectSection(ProjectDependencies) = postProject {84890110-2190-4AAE-9BDC-58F90DF71E4F} = {84890110-2190-4AAE-9BDC-58F90DF71E4F} {E6CAB6C8-1D73-4410-970A-52BF9EC57810} = {E6CAB6C8-1D73-4410-970A-52BF9EC57810} @@ -59,8 +90,16 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shibtest", "shibtest\shibte EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "siterefresh", "siterefresh\siterefresh.vcproj", "{4D02F36E-D2CD-4FD1-AC50-2941E27BB3FB}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testclient", "shar\testclient.vcproj", "{B3F1E899-86F9-4D3A-8026-B57D1A5B90B1}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection ProjectSection(ProjectDependencies) = postProject {E6CAB6C8-1D73-4410-970A-52BF9EC57810} = {E6CAB6C8-1D73-4410-970A-52BF9EC57810} {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} = {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} @@ -68,21 +107,43 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testclient", "shar\testclie EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_shib22", "apache\mod_shib22.vcproj", "{B44C0852-83B8-4FB2-A86E-097C9C8256D0}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection ProjectSection(ProjectDependencies) = postProject {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} = {81F0F7A6-DC36-46EF-957F-F9E81D4403F6} - {84890110-2190-4AAE-9BDC-58F90DF71E4F} = {84890110-2190-4AAE-9BDC-58F90DF71E4F} - {E6CAB6C8-1D73-4410-970A-52BF9EC57810} = {E6CAB6C8-1D73-4410-970A-52BF9EC57810} EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server Modules", "Server Modules", "{26BA8F84-6E42-41FA-9B13-5D3F4B5B2050}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{96AE4FC9-45EF-4C18-9F3B-EDA439E26E4C}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Utilities", "Utilities", "{FED80230-119E-4B2F-9F53-D2660A5F022B}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "odbc-store", "odbc-store\odbc-store.vcproj", "{666A63A7-983F-4C19-8411-207F24305197}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shibsp", "shibsp\shibsp.vcproj", "{81F0F7A6-DC36-46EF-957F-F9E81D4403F6}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/apache/mod_apache.cpp b/apache/mod_apache.cpp index 5acfaf5..1b4f190 100644 --- a/apache/mod_apache.cpp +++ b/apache/mod_apache.cpp @@ -36,12 +36,15 @@ #include #include #include +#include +#include #include -#include #include +#include #include #include +#include #ifdef WIN32 # include @@ -78,11 +81,12 @@ using namespace std; extern "C" module MODULE_VAR_EXPORT mod_shib; namespace { - char* g_szSHIBConfig = NULL; - char* g_szSchemaDir = NULL; - shibtarget::ShibTargetConfig* g_Config = NULL; + char* g_szSHIBConfig = SHIBSP_CONFIG; + char* g_szSchemaDir = SHIBSP_SCHEMAS; + SPConfig* g_Config = NULL; string g_unsetHeaderValue; static const char* g_UserDataKey = "_shib_check_user_"; + static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h); } /* Apache 2.2.x headers must be accumulated and set in the output filter. @@ -920,7 +924,7 @@ bool htAccessControl::authorized(const SPRequest& request, const Session* sessio extern "C" apr_status_t shib_exit(void* data) { if (g_Config) { - g_Config->shutdown(); + g_Config->term(); g_Config = NULL; } ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,0,NULL,"shib_exit() done"); @@ -977,7 +981,7 @@ extern "C" apr_status_t shib_child_exit(void* data) #endif ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(s),"shib_child_exit(%d) dealing with g_Config..", (int)getpid()); - g_Config->shutdown(); + g_Config->term(); g_Config = NULL; ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(s),"shib_child_exit() done"); @@ -1006,43 +1010,47 @@ extern "C" void shib_child_init(apr_pool_t* p, server_rec* s) exit(1); } + g_Config=&SPConfig::getConfig(); + g_Config->setFeatures( + SPConfig::Caching | + SPConfig::Listener | + SPConfig::Metadata | + SPConfig::RequestMapping | + SPConfig::InProcess | + SPConfig::Logging + ); + if (!g_Config->init(g_szSchemaDir)) { + ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to initialize libraries"); + exit(1); + } + g_Config->AccessControlManager.registerFactory(HT_ACCESS_CONTROL,&htAccessFactory); + g_Config->RequestMapperManager.registerFactory(NATIVE_REQUEST_MAPPER,&ApacheRequestMapFactory); + try { - g_Config=&shibtarget::ShibTargetConfig::getConfig(); - SPConfig::getConfig().setFeatures( - SPConfig::Caching | - SPConfig::Listener | - SPConfig::Metadata | - SPConfig::AAP | - SPConfig::RequestMapping | - SPConfig::InProcess | - SPConfig::Logging - ); - if (!g_Config->init(g_szSchemaDir)) { - ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to initialize libraries"); - exit(1); - } - SPConfig::getConfig().AccessControlManager.registerFactory(HT_ACCESS_CONTROL,&htAccessFactory); - SPConfig::getConfig().RequestMapperManager.registerFactory(NATIVE_REQUEST_MAPPER,&ApacheRequestMapFactory); - - if (!g_Config->load(g_szSHIBConfig)) { - ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to load configuration"); - exit(1); - } - - ServiceProvider* conf=SPConfig::getConfig().getServiceProvider(); - xmltooling::Locker locker(conf); - const PropertySet* props=conf->getPropertySet("Local"); - if (props) { - pair unsetValue=props->getString("unsetHeaderValue"); - if (unsetValue.first) - g_unsetHeaderValue = unsetValue.second; - } + DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument(); + XercesJanitor docjanitor(dummydoc); + DOMElement* dummy = dummydoc->createElementNS(NULL,path); + auto_ptr_XMLCh src(g_szSHIBConfig); + dummy->setAttributeNS(NULL,path,src.get()); + + g_Config->setServiceProvider(g_Config->ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy)); + g_Config->getServiceProvider()->init(); } - catch (...) { - ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to initialize system"); + catch (exception& ex) { + ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),ex.what()); + ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to load configuration"); exit(1); } + ServiceProvider* sp=g_Config->getServiceProvider(); + xmltooling::Locker locker(sp); + const PropertySet* props=sp->getPropertySet("Local"); + if (props) { + pair unsetValue=props->getString("unsetHeaderValue"); + if (unsetValue.first) + g_unsetHeaderValue = unsetValue.second; + } + // Set the cleanup handler apr_pool_cleanup_register(p, NULL, &shib_exit, &shib_child_exit); diff --git a/isapi_shib/isapi_shib.cpp b/isapi_shib/isapi_shib.cpp index d14c932..d67aad2 100644 --- a/isapi_shib/isapi_shib.cpp +++ b/isapi_shib/isapi_shib.cpp @@ -27,10 +27,14 @@ #include #include +#include +#include +#include #include +#include +#include -#include - +#include #include #include #include @@ -40,10 +44,12 @@ using namespace shibsp; using namespace xmltooling; +using namespace xercesc; using namespace std; // globals namespace { + static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h); static const XMLCh name[] = UNICODE_LITERAL_4(n,a,m,e); static const XMLCh port[] = UNICODE_LITERAL_4(p,o,r,t); static const XMLCh sslport[] = UNICODE_LITERAL_7(s,s,l,p,o,r,t); @@ -80,7 +86,7 @@ namespace { }; HINSTANCE g_hinstDLL; - shibtarget::ShibTargetConfig* g_Config = NULL; + SPConfig* g_Config = NULL; map g_Sites; bool g_bNormalizeRequest = true; } @@ -137,65 +143,65 @@ extern "C" BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer) return TRUE; } -#ifndef _DEBUG - try - { -#endif - LPCSTR schemadir=getenv("SHIBSCHEMAS"); - if (!schemadir) - schemadir=SHIB_SCHEMAS; - LPCSTR config=getenv("SHIBCONFIG"); - if (!config) - config=SHIB_CONFIG; - g_Config=&shibtarget::ShibTargetConfig::getConfig(); - SPConfig::getConfig().setFeatures( - SPConfig::Listener | - SPConfig::Caching | - SPConfig::Metadata | - SPConfig::AAP | - SPConfig::RequestMapping | - SPConfig::InProcess | - SPConfig::Logging - ); - if (!g_Config->init(schemadir)) { - g_Config=NULL; - LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, - "Filter startup failed during library initialization, check native log for help."); - return FALSE; - } - else if (!g_Config->load(config)) { - g_Config=NULL; - LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, - "Filter startup failed to load configuration, check native log for help."); - return FALSE; - } - - // Access the implementation-specifics for site mappings. - ServiceProvider* conf=SPConfig::getConfig().getServiceProvider(); - xmltooling::Locker locker(conf); - const PropertySet* props=conf->getPropertySet("Local"); - if (props) { - const DOMElement* impl=XMLHelper::getFirstChildElement(props->getElement(),Implementation); - if (impl && (impl=XMLHelper::getFirstChildElement(impl,ISAPI))) { - const XMLCh* flag=impl->getAttributeNS(NULL,normalizeRequest); - g_bNormalizeRequest=(!flag || !*flag || *flag==chDigit_1 || *flag==chLatin_t); - impl=XMLHelper::getFirstChildElement(impl,Site); - while (impl) { - auto_ptr_char id(impl->getAttributeNS(NULL,id)); - if (id.get()) - g_Sites.insert(pair(id.get(),site_t(impl))); - impl=XMLHelper::getNextSiblingElement(impl,Site); - } - } - } -#ifndef _DEBUG + LPCSTR schemadir=getenv("SHIBSCHEMAS"); + if (!schemadir) + schemadir=SHIBSP_SCHEMAS; + LPCSTR config=getenv("SHIBCONFIG"); + if (!config) + config=SHIBSP_CONFIG; + g_Config=&SPConfig::getConfig(); + g_Config->setFeatures( + SPConfig::Listener | + SPConfig::Caching | + SPConfig::Metadata | + SPConfig::RequestMapping | + SPConfig::InProcess | + SPConfig::Logging + ); + if (!g_Config->init(schemadir)) { + g_Config=NULL; + LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, + "Filter startup failed during library initialization, check native log for help."); + return FALSE; } - catch (...) - { - LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, "Filter startup failed with an exception."); + + try { + DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument(); + XercesJanitor docjanitor(dummydoc); + DOMElement* dummy = dummydoc->createElementNS(NULL,path); + auto_ptr_XMLCh src(config); + dummy->setAttributeNS(NULL,path,src.get()); + + g_Config->setServiceProvider(g_Config->ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy)); + g_Config->getServiceProvider()->init(); + } + catch (exception& ex) { + g_Config->term(); + g_Config=NULL; + LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, ex.what()); + LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, + "Filter startup failed to load configuration, check native log for details."); return FALSE; } -#endif + + // Access the implementation-specifics for site mappings. + ServiceProvider* sp=g_Config->getServiceProvider(); + xmltooling::Locker locker(sp); + const PropertySet* props=sp->getPropertySet("Local"); + if (props) { + const DOMElement* impl=XMLHelper::getFirstChildElement(props->getElement(),Implementation); + if (impl && (impl=XMLHelper::getFirstChildElement(impl,ISAPI))) { + const XMLCh* flag=impl->getAttributeNS(NULL,normalizeRequest); + g_bNormalizeRequest=(!flag || !*flag || *flag==chDigit_1 || *flag==chLatin_t); + impl=XMLHelper::getFirstChildElement(impl,Site); + while (impl) { + auto_ptr_char id(impl->getAttributeNS(NULL,id)); + if (id.get()) + g_Sites.insert(pair(id.get(),site_t(impl))); + impl=XMLHelper::getNextSiblingElement(impl,Site); + } + } + } pVer->dwFilterVersion=HTTP_FILTER_REVISION; strncpy(pVer->lpszFilterDesc,"Shibboleth ISAPI Filter",SF_MAX_FILTER_DESC_LEN); @@ -211,7 +217,7 @@ extern "C" BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer) extern "C" BOOL WINAPI TerminateFilter(DWORD) { if (g_Config) - g_Config->shutdown(); + g_Config->term(); g_Config = NULL; LogEvent(NULL, EVENTLOG_INFORMATION_TYPE, 7701, NULL, "Filter shut down..."); return TRUE; @@ -497,8 +503,8 @@ public: } // The filter never processes the POST, so stub these methods. - const char* getQueryString() const { throw runtime_error("getQueryString not implemented"); } - const char* getRequestBody() const { throw runtime_error("getRequestBody not implemented"); } + const char* getQueryString() const { throw IOException("getQueryString not implemented"); } + const char* getRequestBody() const { throw IOException("getRequestBody not implemented"); } }; DWORD WriteClientError(PHTTP_FILTER_CONTEXT pfc, const char* msg) @@ -756,7 +762,7 @@ public: DWORD buflen=8192; BOOL ret = m_lpECB->ReadClient(m_lpECB->ConnID, buf, &buflen); if (!ret || !buflen) - throw saml::SAMLException("Error reading POST request body from browser."); + throw IOException("Error reading POST request body from browser."); m_body.append(buf, buflen); datalen-=buflen; } diff --git a/nsapi_shib/nsapi_shib.cpp b/nsapi_shib/nsapi_shib.cpp index 1b3891f..9e35a83 100644 --- a/nsapi_shib/nsapi_shib.cpp +++ b/nsapi_shib/nsapi_shib.cpp @@ -34,10 +34,12 @@ #include #include #include +#include +#include #include #include - -#include +#include +#include #include #include @@ -66,10 +68,12 @@ using namespace std; if (IO_ERROR==net_write(sn->csd,str,strlen(str))) return REQ_EXIT namespace { - shibtarget::ShibTargetConfig* g_Config=NULL; + SPConfig* g_Config=NULL; string g_ServerName; string g_ServerScheme; string g_unsetHeaderValue; + + static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h); } PluginManager::Factory SunRequestMapFactory; @@ -77,7 +81,7 @@ PluginManager::Factory SunRequestMapFactory; extern "C" NSAPI_PUBLIC void nsapi_shib_exit(void*) { if (g_Config) - g_Config->shutdown(); + g_Config->term(); g_Config = NULL; } @@ -109,61 +113,60 @@ extern "C" NSAPI_PUBLIC int nsapi_shib_init(pblock* pb, ::Session* sn, Request* log_error(LOG_INFORM,"nsapi_shib_init",sn,rq,"nsapi_shib loaded for host (%s)",g_ServerName.c_str()); -#ifndef _DEBUG - try { -#endif - const char* schemadir=pblock_findval("shib-schemas",pb); - if (!schemadir) - schemadir=getenv("SHIBSCHEMAS"); - if (!schemadir) - schemadir=SHIB_SCHEMAS; - const char* config=pblock_findval("shib-config",pb); - if (!config) - config=getenv("SHIBCONFIG"); - if (!config) - config=SHIB_CONFIG; - g_Config=&shibtarget::ShibTargetConfig::getConfig(); - SPConfig::getConfig().setFeatures( - SPConfig::Listener | - SPConfig::Caching | - SPConfig::Metadata | - SPConfig::AAP | - SPConfig::RequestMapping | - SPConfig::InProcess | - SPConfig::Logging - ); - if (!g_Config->init(schemadir)) { - g_Config=NULL; - pblock_nvinsert("error","unable to initialize Shibboleth libraries",pb); - return REQ_ABORTED; - } - - SPConfig::getConfig().RequestMapperManager.registerFactory(XML_REQUEST_MAPPER,&SunRequestMapFactory); - - if (!g_Config->load(config)) { - g_Config=NULL; - pblock_nvinsert("error","unable to initialize load Shibboleth configuration",pb); - return REQ_ABORTED; - } + const char* schemadir=pblock_findval("shib-schemas",pb); + if (!schemadir) + schemadir=getenv("SHIBSCHEMAS"); + if (!schemadir) + schemadir=SHIBSP_SCHEMAS; + const char* config=pblock_findval("shib-config",pb); + if (!config) + config=getenv("SHIBCONFIG"); + if (!config) + config=SHIBSP_CONFIG; + g_Config=&SPConfig::getConfig(); + g_Config->setFeatures( + SPConfig::Listener | + SPConfig::Caching | + SPConfig::Metadata | + SPConfig::RequestMapping | + SPConfig::InProcess | + SPConfig::Logging + ); + if (!g_Config->init(schemadir)) { + g_Config=NULL; + pblock_nvinsert("error","unable to initialize Shibboleth libraries",pb); + return REQ_ABORTED; + } - daemon_atrestart(nsapi_shib_exit,NULL); + g_Config->RequestMapperManager.registerFactory(XML_REQUEST_MAPPER,&SunRequestMapFactory); - ServiceProvider* conf=SPConfig::getConfig().getServiceProvider(); - Locker locker(conf); - const PropertySet* props=conf->getPropertySet("Local"); - if (props) { - pair unsetValue=props->getString("unsetHeaderValue"); - if (unsetValue.first) - g_unsetHeaderValue = unsetValue.second; - } -#ifndef _DEBUG + try { + DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument(); + XercesJanitor docjanitor(dummydoc); + DOMElement* dummy = dummydoc->createElementNS(NULL,path); + auto_ptr_XMLCh src(config); + dummy->setAttributeNS(NULL,path,src.get()); + + g_Config->setServiceProvider(g_Config->ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy)); + g_Config->getServiceProvider()->init(); } - catch (...) { + catch (exception& ex) { + pblock_nvinsert("error",ex.what(),pb); + g_Config->term(); g_Config=NULL; - pblock_nvinsert("error","caught exception, unable to initialize Shibboleth libraries",pb); return REQ_ABORTED; } -#endif + + daemon_atrestart(nsapi_shib_exit,NULL); + + ServiceProvider* sp=g_Config->getServiceProvider(); + Locker locker(sp); + const PropertySet* props=sp->getPropertySet("Local"); + if (props) { + pair unsetValue=props->getString("unsetHeaderValue"); + if (unsetValue.first) + g_unsetHeaderValue = unsetValue.second; + } return REQ_PROCEED; } diff --git a/shar/shar.cpp b/shar/shar.cpp index edcbc7c..48ac4c4 100644 --- a/shar/shar.cpp +++ b/shar/shar.cpp @@ -35,7 +35,6 @@ # define _CRT_SECURE_NO_DEPRECATE 1 #endif -#include #include #ifdef HAVE_UNISTD_H @@ -46,12 +45,15 @@ #include #include #include +#include +#include +#include +#include +#include using namespace shibsp; -using namespace shibtarget; -using namespace shibboleth; -using namespace saml; using namespace log4cpp; +using namespace xmltooling; using namespace std; bool shibd_shutdown = false; @@ -102,17 +104,17 @@ int MyAllocHook(int nAllocType, void *pvData, int real_main(int preinit) { - ShibTargetConfig& conf=ShibTargetConfig::getConfig(); + SPConfig& conf=SPConfig::getConfig(); if (preinit) { - // initialize the shib-target library - SPConfig::getConfig().setFeatures( + // Initialize the SP library. + conf.setFeatures( SPConfig::Listener | SPConfig::Caching | SPConfig::Metadata | SPConfig::Trust | SPConfig::Credentials | - SPConfig::AAP | + SPConfig::AttributeResolver | SPConfig::OutOfProcess | (shar_checkonly ? (SPConfig::InProcess | SPConfig::RequestMapping) : SPConfig::Logging) ); @@ -121,11 +123,29 @@ int real_main(int preinit) if (!shar_schemadir) shar_schemadir=getenv("SHIBSCHEMAS"); if (!shar_schemadir) - shar_schemadir=SHIB_SCHEMAS; + shar_schemadir=SHIBSP_SCHEMAS; if (!shar_config) - shar_config=SHIB_CONFIG; - if (!conf.init(shar_schemadir) || !conf.load(shar_config)) { + shar_config=SHIBSP_CONFIG; + if (!conf.init(shar_schemadir)) { fprintf(stderr, "configuration is invalid, see console for specific problems\n"); + return -1; + } + + try { + fprintf(stderr, "loading configuration file: %s\n", shar_config); + static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h); + DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument(); + XercesJanitor docjanitor(dummydoc); + DOMElement* dummy = dummydoc->createElementNS(NULL,path); + auto_ptr_XMLCh src(shar_config); + dummy->setAttributeNS(NULL,path,src.get()); + + conf.setServiceProvider(conf.ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy)); + conf.getServiceProvider()->init(); + } + catch (exception& ex) { + fprintf(stderr, "caught exception while loading configuration: %s\n", ex.what()); + conf.term(); return -2; } @@ -143,13 +163,13 @@ int real_main(int preinit) if (!shar_checkonly) { // Run the listener. - if (!SPConfig::getConfig().getServiceProvider()->getListenerService()->run(&shibd_shutdown)) { + if (!conf.getServiceProvider()->getListenerService()->run(&shibd_shutdown)) { fprintf(stderr, "listener failed to enter listen loop\n"); return -3; } } - conf.shutdown(); + conf.term(); } return 0; } @@ -244,24 +264,42 @@ int main(int argc, char *argv[]) if (!shar_schemadir) shar_schemadir=getenv("SHIBSCHEMAS"); if (!shar_schemadir) - shar_schemadir=SHIB_SCHEMAS; + shar_schemadir=SHIBSP_SCHEMAS; if (!shar_config) - shar_config=SHIB_CONFIG; + shar_config=SHIBSP_CONFIG; // initialize the shib-target library - ShibTargetConfig& conf=ShibTargetConfig::getConfig(); - SPConfig::getConfig().setFeatures( + SPConfig& conf=SPConfig::getConfig(); + conf.setFeatures( SPConfig::Listener | SPConfig::Caching | SPConfig::Metadata | SPConfig::Trust | SPConfig::Credentials | - SPConfig::AAP | + SPConfig::AttributeResolver | SPConfig::OutOfProcess | (shar_checkonly ? (SPConfig::InProcess | SPConfig::RequestMapping) : SPConfig::Logging) ); - if (!conf.init(shar_schemadir) || !conf.load(shar_config)) { + if (!conf.init(shar_schemadir)) { fprintf(stderr, "configuration is invalid, check console for specific problems\n"); + return -1; + } + + try { + fprintf(stderr, "loading configuration file: %s\n", shar_config); + static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h); + DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument(); + XercesJanitor docjanitor(dummydoc); + DOMElement* dummy = dummydoc->createElementNS(NULL,path); + auto_ptr_XMLCh src(shar_config); + dummy->setAttributeNS(NULL,path,src.get()); + + conf.setServiceProvider(conf.ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy)); + conf.getServiceProvider()->init(); + } + catch (exception& ex) { + fprintf(stderr, "caught exception while loading configuration: %s\n", ex.what()); + conf.term(); return -2; } @@ -281,13 +319,13 @@ int main(int argc, char *argv[]) } // Run the listener - if (!SPConfig::getConfig().getServiceProvider()->getListenerService()->run(&shibd_shutdown)) { + if (!conf.getServiceProvider()->getListenerService()->run(&shibd_shutdown)) { fprintf(stderr, "listener failed to enter listen loop\n"); return -3; } } - conf.shutdown(); + conf.term(); if (pidfile) unlink(pidfile); return 0; diff --git a/shib-target/shib-config.cpp b/shib-target/shib-config.cpp index edaab90..382c91f 100644 --- a/shib-target/shib-config.cpp +++ b/shib-target/shib-config.cpp @@ -138,8 +138,6 @@ bool STConfig::load(const char* config) pair 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); diff --git a/shib-target/shib-ini.cpp b/shib-target/shib-ini.cpp index 8f328d3..edf5908 100644 --- a/shib-target/shib-ini.cpp +++ b/shib-target/shib-ini.cpp @@ -452,7 +452,7 @@ XMLApplication::XMLApplication( // Always include our own providerId as an audience. m_audiences.push_back(getXMLString("providerId").second); - if (conf.isEnabled(SPConfig::AAP)) { + if (conf.isEnabled(SPConfig::AttributeResolver)) { child = XMLHelper::getFirstChildElement(e,AAPProvider); while (child) { // TODO: some kind of compatibility @@ -819,7 +819,8 @@ const Handler* XMLApplication::getHandler(const char* path) const short XMLConfigImpl::acceptNode(const DOMNode* node) const { - if (!XMLString::equals(node->getNamespaceURI(),shibspconstants::SHIB1SPCONFIG_NS)) + if (!XMLString::equals(node->getNamespaceURI(),shibspconstants::SHIB1SPCONFIG_NS) && + !XMLString::equals(node->getNamespaceURI(),shibspconstants::SHIB2SPCONFIG_NS)) return FILTER_ACCEPT; const XMLCh* name=node->getLocalName(); if (XMLString::equals(name,Applications) || @@ -880,7 +881,6 @@ XMLConfigImpl::XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* o try { SPConfig& conf=SPConfig::getConfig(); - SAMLConfig& shibConf=SAMLConfig::getConfig(); XMLToolingConfig& xmlConf=XMLToolingConfig::getConfig(); const DOMElement* SHAR=XMLHelper::getFirstChildElement(e,OutOfProcess); if (!SHAR) @@ -919,6 +919,10 @@ XMLConfigImpl::XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* o // Much of the processing can only occur on the first instantiation. if (first) { + // Set clock skew. + pair skew=getUnsignedInt("clockSkew"); + if (skew.first) + xmlConf.clock_skew_secs=skew.second; // Extensions doExtensions(e, "global", log); @@ -1091,34 +1095,6 @@ XMLConfigImpl::XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* o } } - // Now we load any attribute factories - child = XMLHelper::getFirstChildElement(e,AttributeFactory); - while (child) { - xmltooling::auto_ptr_char type(child->getAttributeNS(NULL,_type)); - log.info("building Attribute factory of type %s...",type.get()); - try { - IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),child); - if (plugin) { - IAttributeFactory* fact=dynamic_cast(plugin); - if (fact) { - m_attrFactories.push_back(fact); - ShibConfig::getConfig().regAttributeMapping( - child->getAttributeNS(NULL,opensaml::saml1::Attribute::ATTRIBUTENAME_ATTRIB_NAME), fact - ); - } - else { - delete plugin; - log.crit("plugin was not an Attribute factory"); - } - } - } - catch (exception& ex) { - log.crit("error building Attribute factory: %s", ex.what()); - } - - child = XMLHelper::getNextSiblingElement(child,AttributeFactory); - } - // Load the default application. This actually has a fixed ID of "default". ;-) child=XMLHelper::getFirstChildElement(e,Applications); if (!child) { diff --git a/shibsp/Makefile.am b/shibsp/Makefile.am index 899e045..33b0e17 100644 --- a/shibsp/Makefile.am +++ b/shibsp/Makefile.am @@ -72,6 +72,7 @@ libshibsp_la_SOURCES = \ impl/StorageServiceSessionCache.cpp \ impl/XMLAccessControl.cpp \ impl/XMLRequestMapper.cpp \ + impl/XMLServiceProvider.cpp \ metadata/MetadataExtImpl.cpp \ metadata/MetadataExtSchemaValidators.cpp \ remoting/impl/ddf.cpp \ diff --git a/shibsp/SPConfig.h b/shibsp/SPConfig.h index 3418808..70b46c2 100644 --- a/shibsp/SPConfig.h +++ b/shibsp/SPConfig.h @@ -70,7 +70,7 @@ namespace shibsp { Metadata = 4, Trust = 8, Credentials = 16, - AAP = 32, + AttributeResolver = 32, RequestMapping = 64, OutOfProcess = 128, InProcess = 256, diff --git a/shibsp/ServiceProvider.cpp b/shibsp/ServiceProvider.cpp index 377d138..ff97ad2 100644 --- a/shibsp/ServiceProvider.cpp +++ b/shibsp/ServiceProvider.cpp @@ -46,7 +46,7 @@ using namespace xmltooling; using namespace std; namespace shibsp { - //SHIBSP_DLLLOCAL PluginManager::Factory XMLServiceProviderFactory; + SHIBSP_DLLLOCAL PluginManager::Factory XMLServiceProviderFactory; long SHIBSP_DLLLOCAL sendError( SPRequest& request, const Application* app, const char* page, TemplateParameters& tp, const XMLToolingException* ex=NULL @@ -110,7 +110,7 @@ namespace shibsp { void SHIBSP_API shibsp::registerServiceProviders() { - //SPConfig::getConfig().ServiceProviderManager.registerFactory(XML_SERVICE_PROVIDER, XMLServiceProviderFactory); + SPConfig::getConfig().ServiceProviderManager.registerFactory(XML_SERVICE_PROVIDER, XMLServiceProviderFactory); } pair ServiceProvider::doAuthentication(SPRequest& request, bool handler) const diff --git a/shibsp/impl/XMLServiceProvider.cpp b/shibsp/impl/XMLServiceProvider.cpp new file mode 100644 index 0000000..4267ccd --- /dev/null +++ b/shibsp/impl/XMLServiceProvider.cpp @@ -0,0 +1,1081 @@ +/* + * 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 "Handler.h" +#include "RequestMapper.h" +#include "ServiceProvider.h" +#include "SessionCache.h" +#include "SPConfig.h" +#include "SPRequest.h" +#include "TransactionLog.h" +#include "attribute/Attribute.h" +#include "remoting/ListenerService.h" +#include "security/PKIXTrustEngine.h" +#include "util/DOMPropertySet.h" +#include "util/SPConstants.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace shibsp; +using namespace opensaml::saml1; +using namespace opensaml::saml2md; +using namespace opensaml; +using namespace xmltooling; +using namespace log4cpp; +using namespace std; +using xmlsignature::CredentialResolver; + +namespace shibsp { + +#if defined (_MSC_VER) + #pragma warning( push ) + #pragma warning( disable : 4250 ) +#endif + + static vector g_noHandlers; + + // Application configuration wrapper + class SHIBSP_DLLLOCAL XMLApplication : public virtual Application, public DOMPropertySet, public DOMNodeFilter + { + public: + XMLApplication(const ServiceProvider*, const DOMElement* e, const XMLApplication* base=NULL); + ~XMLApplication() { cleanup(); } + + // PropertySet + pair getBool(const char* name, const char* ns=NULL) const; + pair getString(const char* name, const char* ns=NULL) const; + pair getXMLString(const char* name, const char* ns=NULL) const; + pair getUnsignedInt(const char* name, const char* ns=NULL) const; + pair getInt(const char* name, const char* ns=NULL) const; + const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const; + + // Application + const char* getId() const {return getString("id").second;} + const char* getHash() const {return m_hash.c_str();} + MetadataProvider* getMetadataProvider() const; + TrustEngine* getTrustEngine() const; + const vector& getAudiences() const; + const PropertySet* getCredentialUse(const EntityDescriptor* provider) const; + + const Handler* getDefaultSessionInitiator() const; + const Handler* getSessionInitiatorById(const char* id) const; + const Handler* getDefaultAssertionConsumerService() const; + const Handler* getAssertionConsumerServiceByIndex(unsigned short index) const; + const vector& getAssertionConsumerServicesByBinding(const XMLCh* binding) const; + const Handler* getHandler(const char* path) const; + + // 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; + MetadataProvider* m_metadata; + TrustEngine* m_trust; + vector m_audiences; + + // manage handler objects + vector m_handlers; + + // maps location (path info) to applicable handlers + map m_handlerMap; + + // maps unique indexes to consumer services + map 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 > ACSBindingMap; +#else + typedef map > ACSBindingMap; +#endif + ACSBindingMap m_acsBindingMap; + + // maps unique ID strings to session initiators + map m_sessionInitMap; + + // pointer to default session initiator + const Handler* m_sessionInitDefault; + + DOMPropertySet* m_credDefault; +#ifdef HAVE_GOOD_STL + map m_credMap; +#else + map m_credMap; +#endif + }; + + // 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); + ~XMLConfigImpl(); + + RequestMapper* m_requestMapper; + map m_appmap; + map m_credResolverMap; + + // 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: + XMLConfig(const DOMElement* e) + : ReloadableXMLFile(e), m_impl(NULL), m_listener(NULL), m_sessionCache(NULL) { + } + + void init() { + load(); + } + + ~XMLConfig() { + delete m_impl; + delete m_sessionCache; + delete m_listener; + delete m_tranLog; + XMLToolingConfig::getConfig().setReplayCache(NULL); + for_each(m_storage.begin(), m_storage.end(), cleanup_pair()); + } + + // PropertySet + pair getBool(const char* name, const char* ns=NULL) const {return m_impl->getBool(name,ns);} + pair getString(const char* name, const char* ns=NULL) const {return m_impl->getString(name,ns);} + pair getXMLString(const char* name, const char* ns=NULL) const {return m_impl->getXMLString(name,ns);} + pair getUnsignedInt(const char* name, const char* ns=NULL) const {return m_impl->getUnsignedInt(name,ns);} + pair 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:target:config:1.0") const {return m_impl->getPropertySet(name,ns);} + const DOMElement* getElement() const {return m_impl->getElement();} + + // ServiceProvider + TransactionLog* getTransactionLog() const { + if (m_tranLog) + return m_tranLog; + throw ConfigurationException("No TransactionLog available."); + } + + StorageService* getStorageService(const char* id) const { + if (id) { + map::const_iterator i=m_storage.find(id); + if (i!=m_storage.end()) + return i->second; + } + return NULL; + } + + 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::const_iterator i=m_impl->m_appmap.find(applicationId); + return (i!=m_impl->m_appmap.end()) ? i->second : NULL; + } + + CredentialResolver* getCredentialResolver(const char* id) const { + if (id) { + map::const_iterator i=m_impl->m_credResolverMap.find(id); + if (i!=m_impl->m_credResolverMap.end()) + return i->second; + } + return NULL; + } + + protected: + pair load(); + + private: + friend class XMLConfigImpl; + XMLConfigImpl* m_impl; + mutable ListenerService* m_listener; + mutable SessionCache* m_sessionCache; + mutable TransactionLog* m_tranLog; + mutable map m_storage; + }; + +#if defined (_MSC_VER) + #pragma warning( pop ) +#endif + + ServiceProvider* XMLServiceProviderFactory(const DOMElement* const & e) + { + return new XMLConfig(e); + } + + static const XMLCh AAPProvider[] = UNICODE_LITERAL_11(A,A,P,P,r,o,v,i,d,e,r); + 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 AttributeFactory[] = UNICODE_LITERAL_16(A,t,t,r,i,b,u,t,e,F,a,c,t,o,r,y); + static const XMLCh Credentials[] = UNICODE_LITERAL_11(C,r,e,d,e,n,t,i,a,l,s); + static const XMLCh CredentialsProvider[] = UNICODE_LITERAL_19(C,r,e,d,e,n,t,i,a,l,s,P,r,o,v,i,d,e,r); + static const XMLCh CredentialUse[] = UNICODE_LITERAL_13(C,r,e,d,e,n,t,i,a,l,U,s,e); + static const XMLCh DiagnosticService[] = UNICODE_LITERAL_17(D,i,a,g,n,o,s,t,i,c,S,e,r,v,i,c,e); + static const XMLCh fatal[] = UNICODE_LITERAL_5(f,a,t,a,l); + static const XMLCh FileResolver[] = UNICODE_LITERAL_12(F,i,l,e,R,e,s,o,l,v,e,r); + static const XMLCh Global[] = UNICODE_LITERAL_6(G,l,o,b,a,l); + 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 Local[] = UNICODE_LITERAL_5(L,o,c,a,l); + static const XMLCh logger[] = UNICODE_LITERAL_6(l,o,g,g,e,r); + static const XMLCh MemoryListener[] = UNICODE_LITERAL_14(M,e,m,o,r,y,L,i,s,t,e,n,e,r); + static const XMLCh MemorySessionCache[] = UNICODE_LITERAL_18(M,e,m,o,r,y,S,e,s,s,i,o,n,C,a,c,h,e); + 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 RequestMapProvider[] = UNICODE_LITERAL_18(R,e,q,u,e,s,t,M,a,p,P,r,o,v,i,d,e,r); + 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 _StorageService[] = UNICODE_LITERAL_14(S,t,o,r,a,g,e,S,e,r,v,i,c,e); + static const XMLCh OutOfProcess[] = UNICODE_LITERAL_12(O,u,t,O,f,P,r,o,c,e,s,s); + static const XMLCh TCPListener[] = UNICODE_LITERAL_11(T,C,P,L,i,s,t,e,n,e,r); + static const XMLCh TrustProvider[] = UNICODE_LITERAL_13(T,r,u,s,t,P,r,o,v,i,d,e,r); + static const XMLCh UnixListener[] = UNICODE_LITERAL_12(U,n,i,x,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 _path[] = UNICODE_LITERAL_4(p,a,t,h); + static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e); +}; + +XMLApplication::XMLApplication( + const ServiceProvider* sp, + const DOMElement* e, + const XMLApplication* base + ) : m_sp(sp), m_base(base), m_metadata(NULL), m_trust(NULL), + m_credDefault(NULL), m_sessionInitDefault(NULL), m_acsDefault(NULL) +{ +#ifdef _DEBUG + xmltooling::NDC ndc("XMLApplication"); +#endif + Category& log=Category::getInstance(SHIBSP_LOGCAT".Application"); + + try { + // First load any property sets. + map root_remap; + root_remap["shire"]="session"; + root_remap["shireURL"]="handlerURL"; + root_remap["shireSSL"]="handlerSSL"; + load(e,log,this,&root_remap); + + const PropertySet* propcheck=getPropertySet("Errors"); + if (propcheck && !propcheck->getString("session").first) + throw ConfigurationException(" element requires 'session' (or deprecated 'shire') attribute"); + propcheck=getPropertySet("Sessions"); + if (propcheck && !propcheck->getString("handlerURL").first) + throw ConfigurationException(" element requires 'handlerURL' (or deprecated 'shireURL') attribute"); + + SPConfig& conf=SPConfig::getConfig(); + SAMLConfig& samlConf=SAMLConfig::getConfig(); + XMLToolingConfig& xmlConf=XMLToolingConfig::getConfig(); + + m_hash=getId(); + m_hash+=getString("providerId").second; + m_hash=samlConf.hashSHA1(m_hash.c_str(), true); + + // Process handlers. + Handler* handler=NULL; + bool hardACS=false, hardSessionInit=false; + const DOMElement* child = XMLHelper::getFirstChildElement(propcheck->getElement()); + while (child) { + xmltooling::auto_ptr_char bindprop(child->getAttributeNS(NULL,EndpointType::BINDING_ATTRIB_NAME)); + if (!bindprop.get() || !*(bindprop.get())) { + log.warn("md:AssertionConsumerService element has no Binding attribute, skipping it..."); + child = XMLHelper::getNextSiblingElement(child); + continue; + } + + 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 (XMLHelper::isNodeNamed(child,samlconstants::SAML20MD_NS,AssertionConsumerService::LOCAL_NAME)) { + handler=conf.AssertionConsumerServiceManager.newPlugin(bindprop.get(),child); + // 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 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)) { + handler=conf.SessionInitiatorManager.newPlugin(bindprop.get(),child); + pair si_id=handler->getString("id"); + if (si_id.first && si_id.second) + m_sessionInitMap[si_id.second]=handler; + if (!hardSessionInit) { + pair defprop=handler->getBool("isDefault"); + if (defprop.first) { + if (defprop.second) { + hardSessionInit=true; + m_sessionInitDefault=handler; + } + } + else if (!m_sessionInitDefault) + m_sessionInitDefault=handler; + } + } + else if (XMLHelper::isNodeNamed(child,samlconstants::SAML20MD_NS,SingleLogoutService::LOCAL_NAME)) { + handler=conf.SingleLogoutServiceManager.newPlugin(bindprop.get(),child); + } + else if (XMLHelper::isNodeNamed(child,samlconstants::SAML20MD_NS,ManageNameIDService::LOCAL_NAME)) { + handler=conf.ManageNameIDServiceManager.newPlugin(bindprop.get(),child); + } + else { + handler=conf.HandlerManager.newPlugin(bindprop.get(),child); + } + + // Save off the objects after giving the property set to the handler for its use. + m_handlers.push_back(handler); + + // Insert into location map. + pair 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); + } + + // If no handlers defined at the root, assume a legacy configuration. + if (!m_base && m_handlers.empty()) { + try { + // A legacy config installs a SAML POST handler at the root handler location. + // We use the Sessions element itself as the PropertySet. + Handler* h1=conf.SessionInitiatorManager.newPlugin( + shibspconstants::SHIB1_SESSIONINIT_PROFILE_URI,propcheck->getElement() + ); + m_handlers.push_back(h1); + m_sessionInitDefault=h1; + + Handler* h2=conf.AssertionConsumerServiceManager.newPlugin( + samlconstants::SAML1_PROFILE_BROWSER_POST,propcheck->getElement() + ); + m_handlers.push_back(h2); + m_handlerMap[""] = h2; + m_acsDefault=h2; + } + catch (exception& ex) { + log.crit("error installing legacy handler configuration: %s", ex.what()); + } + } + + DOMNodeList* nlist=e->getElementsByTagNameNS(samlconstants::SAML1_NS,Audience::LOCAL_NAME); + for (XMLSize_t i=0; nlist && igetLength(); 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 providerId as an audience. + m_audiences.push_back(getXMLString("providerId").second); + + if (conf.isEnabled(SPConfig::AttributeResolver)) { + child = XMLHelper::getFirstChildElement(e,AAPProvider); + while (child) { + // TODO: some kind of compatibility + child = XMLHelper::getNextSiblingElement(child,AAPProvider); + } + } + + if (conf.isEnabled(SPConfig::Metadata)) { + vector os2providers; + child = XMLHelper::getFirstChildElement(e,_MetadataProvider); + while (child) { + xmltooling::auto_ptr_char type(child->getAttributeNS(NULL,_type)); + log.info("building metadata provider of type %s...",type.get()); + try { + auto_ptr mp(samlConf.MetadataProviderManager.newPlugin(type.get(),child)); + mp->init(); + os2providers.push_back(mp.release()); + } + catch (exception& ex) { + log.crit("error building/initializing metadata provider: %s", ex.what()); + } + + child = XMLHelper::getNextSiblingElement(child,_MetadataProvider); + } + + if (os2providers.size()==1) + m_metadata=os2providers.front(); + else if (os2providers.size()>1) { + try { + m_metadata = samlConf.MetadataProviderManager.newPlugin(CHAINING_METADATA_PROVIDER,NULL); + ChainingMetadataProvider* chainMeta = dynamic_cast(m_metadata); + while (!os2providers.empty()) { + chainMeta->addMetadataProvider(os2providers.back()); + os2providers.pop_back(); + } + } + catch (exception& ex) { + log.crit("error building chaining metadata provider wrapper: %s",ex.what()); + for_each(os2providers.begin(), os2providers.end(), xmltooling::cleanup()); + } + } + } + + if (conf.isEnabled(SPConfig::Trust)) { + ChainingTrustEngine* chainTrust = NULL; + child = XMLHelper::getFirstChildElement(e,TrustProvider); + while (child) { + xmltooling::auto_ptr_char type(child->getAttributeNS(NULL,_type)); + log.info("building trust provider of type %s...",type.get()); + try { + if (!m_trust) { + // For compatibility with old engine types, we're assuming a Shib engine is likely, + // which requires chaining, so we'll build that regardless. + m_trust = xmlConf.TrustEngineManager.newPlugin(CHAINING_TRUSTENGINE,NULL); + chainTrust = dynamic_cast(m_trust); + } + if (!strcmp(type.get(),"edu.internet2.middleware.shibboleth.common.provider.ShibbolethTrust")) { + chainTrust->addTrustEngine(xmlConf.TrustEngineManager.newPlugin(EXPLICIT_KEY_TRUSTENGINE,child)); + chainTrust->addTrustEngine(xmlConf.TrustEngineManager.newPlugin(SHIBBOLETH_PKIX_TRUSTENGINE,child)); + } + else if (!strcmp(type.get(),"edu.internet2.middleware.shibboleth.common.provider.BasicTrust")) { + chainTrust->addTrustEngine(xmlConf.TrustEngineManager.newPlugin(EXPLICIT_KEY_TRUSTENGINE,child)); + } + else { + chainTrust->addTrustEngine(xmlConf.TrustEngineManager.newPlugin(type.get(),child)); + } + } + catch (exception& ex) { + log.crit("error building trust provider: %s",ex.what()); + } + + child = XMLHelper::getNextSiblingElement(child,TrustProvider); + } + } + + // Finally, load credential mappings. + child = XMLHelper::getFirstChildElement(e,CredentialUse); + if (child) { + m_credDefault=new DOMPropertySet(); + m_credDefault->load(child,log,this); + child = XMLHelper::getFirstChildElement(child,RelyingParty); + while (child) { + DOMPropertySet* rp=new DOMPropertySet(); + rp->load(child,log,this); + m_credMap[child->getAttributeNS(NULL,opensaml::saml2::Attribute::NAME_ATTRIB_NAME)]=rp; + child = XMLHelper::getNextSiblingElement(child,RelyingParty); + } + } + + if (conf.isEnabled(SPConfig::OutOfProcess)) { + // Really finally, build local browser profile and binding objects. + // TODO: may need some bits here... + } + } + catch (exception&) { + cleanup(); + throw; + } +#ifndef _DEBUG + catch (...) { + cleanup(); + throw; + } +#endif +} + +void XMLApplication::cleanup() +{ + for_each(m_handlers.begin(),m_handlers.end(),xmltooling::cleanup()); + + delete m_credDefault; +#ifdef HAVE_GOOD_STL + for_each(m_credMap.begin(),m_credMap.end(),cleanup_pair()); +#else + for_each(m_credMap.begin(),m_credMap.end(),cleanup_pair()); +#endif + + delete m_trust; + delete m_metadata; +} + +short XMLApplication::acceptNode(const DOMNode* node) const +{ + if (XMLHelper::isNodeNamed(node,samlconstants::SAML1_NS,AttributeDesignator::LOCAL_NAME)) + return FILTER_REJECT; + else if (XMLHelper::isNodeNamed(node,samlconstants::SAML20_NS,opensaml::saml1::Attribute::LOCAL_NAME)) + return FILTER_REJECT; + else if (XMLHelper::isNodeNamed(node,samlconstants::SAML1_NS,Audience::LOCAL_NAME)) + return FILTER_REJECT; + const XMLCh* name=node->getLocalName(); + if (XMLString::equals(name,_Application) || + XMLString::equals(name,AssertionConsumerService::LOCAL_NAME) || + XMLString::equals(name,SingleLogoutService::LOCAL_NAME) || + XMLString::equals(name,DiagnosticService) || + XMLString::equals(name,SessionInitiator) || + XMLString::equals(name,AAPProvider) || + XMLString::equals(name,CredentialUse) || + XMLString::equals(name,RelyingParty) || + XMLString::equals(name,_MetadataProvider) || + XMLString::equals(name,TrustProvider)) + return FILTER_REJECT; + + return FILTER_ACCEPT; +} + +pair XMLApplication::getBool(const char* name, const char* ns) const +{ + pair ret=DOMPropertySet::getBool(name,ns); + if (ret.first) + return ret; + return m_base ? m_base->getBool(name,ns) : ret; +} + +pair XMLApplication::getString(const char* name, const char* ns) const +{ + pair ret=DOMPropertySet::getString(name,ns); + if (ret.first) + return ret; + return m_base ? m_base->getString(name,ns) : ret; +} + +pair XMLApplication::getXMLString(const char* name, const char* ns) const +{ + pair ret=DOMPropertySet::getXMLString(name,ns); + if (ret.first) + return ret; + return m_base ? m_base->getXMLString(name,ns) : ret; +} + +pair XMLApplication::getUnsignedInt(const char* name, const char* ns) const +{ + pair ret=DOMPropertySet::getUnsignedInt(name,ns); + if (ret.first) + return ret; + return m_base ? m_base->getUnsignedInt(name,ns) : ret; +} + +pair XMLApplication::getInt(const char* name, const char* ns) const +{ + pair ret=DOMPropertySet::getInt(name,ns); + if (ret.first) + return ret; + return m_base ? m_base->getInt(name,ns) : ret; +} + +const PropertySet* XMLApplication::getPropertySet(const char* name, const char* ns) const +{ + const PropertySet* ret=DOMPropertySet::getPropertySet(name,ns); + if (ret || !m_base) + return ret; + return m_base->getPropertySet(name,ns); +} + +MetadataProvider* XMLApplication::getMetadataProvider() const +{ + return (!m_metadata && m_base) ? m_base->getMetadataProvider() : m_metadata; +} + +TrustEngine* XMLApplication::getTrustEngine() const +{ + return (!m_trust && m_base) ? m_base->getTrustEngine() : m_trust; +} + +const vector& XMLApplication::getAudiences() const +{ + return (m_audiences.empty() && m_base) ? m_base->getAudiences() : m_audiences; +} + +const PropertySet* XMLApplication::getCredentialUse(const EntityDescriptor* provider) const +{ + if (!m_credDefault && m_base) + return m_base->getCredentialUse(provider); + +#ifdef HAVE_GOOD_STL + map::const_iterator i=m_credMap.find(provider->getEntityID()); + if (i!=m_credMap.end()) + return i->second; + const EntitiesDescriptor* group=dynamic_cast(provider->getParent()); + while (group) { + if (group->getName()) { + i=m_credMap.find(group->getName()); + if (i!=m_credMap.end()) + return i->second; + } + group=dynamic_cast(group->getParent()); + } +#else + map::const_iterator i=m_credMap.begin(); + for (; i!=m_credMap.end(); i++) { + if (XMLString::equals(i->first,provider->getId())) + return i->second; + const EntitiesDescriptor* group=dynamic_cast(provider->getParent()); + while (group) { + if (XMLString::equals(i->first,group->getName())) + return i->second; + group=dynamic_cast(group->getParent()); + } + } +#endif + return m_credDefault; +} + +const Handler* XMLApplication::getDefaultSessionInitiator() const +{ + if (m_sessionInitDefault) return m_sessionInitDefault; + return m_base ? m_base->getDefaultSessionInitiator() : NULL; +} + +const Handler* XMLApplication::getSessionInitiatorById(const char* id) const +{ + map::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::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& XMLApplication::getAssertionConsumerServicesByBinding(const XMLCh* binding) const +{ +#ifdef HAVE_GOOD_STL + ACSBindingMap::const_iterator i=m_acsBindingMap.find(binding); +#else + xmltooling::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::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; +} + +short XMLConfigImpl::acceptNode(const DOMNode* node) const +{ + if (!XMLString::equals(node->getNamespaceURI(),shibspconstants::SHIB1SPCONFIG_NS) && + !XMLString::equals(node->getNamespaceURI(),shibspconstants::SHIB2SPCONFIG_NS)) + return FILTER_ACCEPT; + const XMLCh* name=node->getLocalName(); + if (XMLString::equals(name,Applications) || + XMLString::equals(name,AttributeFactory) || + XMLString::equals(name,Credentials) || + XMLString::equals(name,CredentialsProvider) || + XMLString::equals(name,Extensions::LOCAL_NAME) || + XMLString::equals(name,Implementation) || + XMLString::equals(name,Listener) || + XMLString::equals(name,MemoryListener) || + XMLString::equals(name,MemorySessionCache) || + XMLString::equals(name,RequestMapProvider) || + 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::LOCAL_NAME); + if (exts) { + exts=XMLHelper::getFirstChildElement(exts,Library); + while (exts) { + xmltooling::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) : m_outer(outer), m_document(NULL), m_requestMapper(NULL) +{ +#ifdef _DEBUG + xmltooling::NDC ndc("XMLConfigImpl"); +#endif + Category& log=Category::getInstance(SHIBSP_LOGCAT".Config"); + + try { + SPConfig& conf=SPConfig::getConfig(); + XMLToolingConfig& xmlConf=XMLToolingConfig::getConfig(); + const DOMElement* SHAR=XMLHelper::getFirstChildElement(e,OutOfProcess); + if (!SHAR) + SHAR=XMLHelper::getFirstChildElement(e,Global); + const DOMElement* SHIRE=XMLHelper::getFirstChildElement(e,InProcess); + if (!SHIRE) + SHIRE=XMLHelper::getFirstChildElement(e,Local); + + // 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) { + xmltooling::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()); + } + + if (first) + m_outer->m_tranLog = new TransactionLog(); + } + + // First load any property sets. + map root_remap; + root_remap["Global"]="OutOfProcess"; + root_remap["Local"]="InProcess"; + load(e,log,this,&root_remap); + + const DOMElement* child; + string plugtype; + + // Much of the processing can only occur on the first instantiation. + if (first) { + // Set clock skew. + pair 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) { + xmltooling::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 (conf.isEnabled(SPConfig::Caching)) { + // TODO: This code's a mess, due to a very bad config layout for the caches... + // Needs rework with the new config file. + const DOMElement* container=conf.isEnabled(SPConfig::OutOfProcess) ? SHAR : SHIRE; + + // First build any StorageServices. + string inmemID; + child=XMLHelper::getFirstChildElement(container,_StorageService); + while (child) { + xmltooling::auto_ptr_char id(child->getAttributeNS(NULL,Id)); + xmltooling::auto_ptr_char type(child->getAttributeNS(NULL,_type)); + if (id.get() && type.get()) { + 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(container,_StorageService); + } + + child=XMLHelper::getFirstChildElement(container,_SessionCache); + if (child) { + xmltooling::auto_ptr_char type(child->getAttributeNS(NULL,_type)); + log.info("building Session Cache of type %s...",type.get()); + m_outer->m_sessionCache=conf.SessionCacheManager.newPlugin(type.get(),child); + } + else if (conf.isEnabled(SPConfig::OutOfProcess)) { + log.warn("custom SessionCache unspecified or no longer supported, building SessionCache of type %s...",STORAGESERVICE_SESSION_CACHE); + 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); + } + child = container->getOwnerDocument()->createElementNS(NULL,_SessionCache); + xmltooling::auto_ptr_XMLCh ssid(inmemID.c_str()); + const_cast(child)->setAttributeNS(NULL,_StorageService,ssid.get()); + m_outer->m_sessionCache=conf.SessionCacheManager.newPlugin(STORAGESERVICE_SESSION_CACHE,child); + } + else { + log.warn("custom SessionCache unspecified or no longer supported, building SessionCache of type %s...",REMOTED_SESSION_CACHE); + m_outer->m_sessionCache=conf.SessionCacheManager.newPlugin(REMOTED_SESSION_CACHE,NULL); + } + + // Replay cache. + StorageService* replaySS=NULL; + child=XMLHelper::getFirstChildElement(container,_ReplayCache); + if (child) { + xmltooling::auto_ptr_char ssid(child->getAttributeNS(NULL,_StorageService)); + if (ssid.get() && *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)); + } + } // 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,RequestMapProvider); + if (child) { + xmltooling::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); + } + else { + log.fatal("can't build RequestMapper, missing conf:RequestMapProvider element?"); + throw ConfigurationException("can't build RequestMapper, missing conf:RequestMapProvider element?"); + } + } + + // Now we load the credentials map. + if (conf.isEnabled(SPConfig::Credentials)) { + // Old format was to wrap it in a CredentialsProvider plugin, we're inlining that... + child = XMLHelper::getFirstChildElement(e,CredentialsProvider); + child = XMLHelper::getFirstChildElement(child ? child : e,Credentials); + if (child) { + // Step down and process resolvers. + child=XMLHelper::getFirstChildElement(child); + while (child) { + xmltooling::auto_ptr_char id(child->getAttributeNS(NULL,Id)); + if (!id.get() || !*(id.get())) { + log.warn("skipping CredentialsResolver with no Id attribute"); + child = XMLHelper::getNextSiblingElement(child); + continue; + } + + if (XMLString::equals(child->getLocalName(),FileResolver)) + plugtype=FILESYSTEM_CREDENTIAL_RESOLVER; + else { + xmltooling::auto_ptr_char c(child->getAttributeNS(NULL,_type)); + plugtype=c.get(); + } + + if (!plugtype.empty()) { + try { + CredentialResolver* cr= + XMLToolingConfig::getConfig().CredentialResolverManager.newPlugin(plugtype.c_str(),child); + m_credResolverMap[id.get()] = cr; + } + catch (exception& ex) { + log.crit("failed to instantiate CredentialResolver (%s): %s", id.get(), ex.what()); + } + } + else { + log.error("unknown type of CredentialResolver with Id (%s)", id.get()); + } + + child = XMLHelper::getNextSiblingElement(child); + } + } + } + + // Load the default application. This actually has a fixed ID of "default". ;-) + child=XMLHelper::getFirstChildElement(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 iapp(new XMLApplication(m_outer,child,defapp)); + if (m_appmap.find(iapp->getId())!=m_appmap.end()) + 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()); + for_each(m_credResolverMap.begin(),m_credResolverMap.end(),cleanup_pair()); + delete m_requestMapper; + if (m_document) + m_document->release(); +} + +pair XMLConfig::load() +{ + // Load from source using base class. + pair raw = ReloadableXMLFile::load(); + + // If we own it, wrap it. + XercesJanitor docjanitor(raw.first ? raw.second->getOwnerDocument() : NULL); + + XMLConfigImpl* impl = new XMLConfigImpl(raw.second,(m_impl==NULL),this); + + // 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); +} diff --git a/shibsp/remoting/impl/SocketListener.cpp b/shibsp/remoting/impl/SocketListener.cpp index 8d94983..95a887f 100644 --- a/shibsp/remoting/impl/SocketListener.cpp +++ b/shibsp/remoting/impl/SocketListener.cpp @@ -180,6 +180,7 @@ bool SocketListener::run(bool* shutdown) #ifdef _DEBUG NDC ndc("run"); #endif + log->info("listener service starting"); // Save flag to monitor for shutdown request. m_shutdown=shutdown; diff --git a/shibsp/shibsp.vcproj b/shibsp/shibsp.vcproj index 3ac525b..2642f23 100644 --- a/shibsp/shibsp.vcproj +++ b/shibsp/shibsp.vcproj @@ -295,6 +295,10 @@ RelativePath=".\impl\XMLRequestMapper.cpp" > + +