From e38e24a6f2730b1a0b30b300d573a0f1c811dd1f Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Fri, 22 Dec 2006 04:01:37 +0000 Subject: [PATCH] Starting migration to new SP library --- .gitignore | 1 + Shibboleth.sln | 16 ++++- apache/mod_apache.cpp | 18 ++--- apache/mod_shib13.vcproj | 4 -- isapi_shib/isapi_shib.cpp | 18 ++--- nsapi_shib/nsapi_shib.cpp | 18 ++--- shar/shar.cpp | 44 ++++++------ shar/test-client.cpp | 8 ++- shib-target/SocketListener.cpp | 6 +- shib-target/XMLRequestMapper.cpp | 2 +- shib-target/internal.h | 4 -- shib-target/shib-ccache.cpp | 18 ++--- shib-target/shib-config.cpp | 39 +++-------- shib-target/shib-handlers.cpp | 13 ++-- shib-target/shib-ini.cpp | 64 +++++++++--------- shib-target/shib-target.h | 32 +-------- shibsp/.gitignore | 1 + shibsp/Makefile.am | 39 +++++++++++ shibsp/SPConfig.cpp | 105 +++++++++++++++++++++++++++++ shibsp/SPConfig.h | 136 ++++++++++++++++++++++++++++++++++++++ shibsp/base.h | 96 +++++++++++++++++++++++++++ shibsp/exceptions.h | 36 ++++++++++ shibsp/internal.h | 61 +++++++++++++++++ shibsp/paths.h.in | 36 ++++++++++ shibsp/shibsp.vcproj | 28 +++++++- shibsp/version.h | 74 +++++++++++++++++++++ test/posttest.cpp | 21 +++--- test/shibtest.cpp | 24 ++++--- xmlproviders/CredResolvers.cpp | 2 +- xmlproviders/XMLAAP.cpp | 4 +- xmlproviders/XMLAccessControl.cpp | 2 +- xmlproviders/XMLCredentials.cpp | 2 +- xmlproviders/XMLMetadata.cpp | 24 +++---- xmlproviders/XMLTrust.cpp | 6 +- 34 files changed, 792 insertions(+), 210 deletions(-) create mode 100644 shibsp/Makefile.am create mode 100644 shibsp/SPConfig.cpp create mode 100644 shibsp/SPConfig.h create mode 100644 shibsp/base.h create mode 100644 shibsp/exceptions.h create mode 100644 shibsp/internal.h create mode 100644 shibsp/paths.h.in create mode 100644 shibsp/version.h diff --git a/.gitignore b/.gitignore index d42d662..ae58d81 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ /shibboleth.spec /.settings /*.suo +/Debug diff --git a/Shibboleth.sln b/Shibboleth.sln index b22cf89..eb94c38 100644 --- a/Shibboleth.sln +++ b/Shibboleth.sln @@ -2,6 +2,7 @@ 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(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 @@ -10,30 +11,35 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "isapi_shib_gui", "isapi_shi EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_shib13", "apache\mod_shib13.vcproj", "{D243B43E-728E-4F32-BDFF-B3A897037C6D}" 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(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(ProjectDependencies) = postProject - {84890110-2190-4AAE-9BDC-58F90DF71E4F} = {84890110-2190-4AAE-9BDC-58F90DF71E4F} {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(ProjectDependencies) = postProject - {84890110-2190-4AAE-9BDC-58F90DF71E4F} = {84890110-2190-4AAE-9BDC-58F90DF71E4F} {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}") = "shar", "shar\shar.vcproj", "{F13141B5-6C87-40BB-8D4E-5CC56EBB4C59}" 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 @@ -49,10 +55,12 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shibtarget", "shib-target\shibtarget.vcproj", "{84890110-2190-4AAE-9BDC-58F90DF71E4F}" 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(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 @@ -61,8 +69,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "siterefresh", "siterefresh\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testclient", "shar\testclient.vcproj", "{B3F1E899-86F9-4D3A-8026-B57D1A5B90B1}" ProjectSection(ProjectDependencies) = postProject - {84890110-2190-4AAE-9BDC-58F90DF71E4F} = {84890110-2190-4AAE-9BDC-58F90DF71E4F} {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}") = "xmlproviders", "xmlproviders\xmlproviders.vcproj", "{68E46D06-6B91-4C59-A700-78DD4D4C420B}" @@ -79,6 +88,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "odbc_ccache", "odbc_ccache\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_shib22", "apache\mod_shib22.vcproj", "{B44C0852-83B8-4FB2-A86E-097C9C8256D0}" 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 diff --git a/apache/mod_apache.cpp b/apache/mod_apache.cpp index dbeb11b..955afd6 100644 --- a/apache/mod_apache.cpp +++ b/apache/mod_apache.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #ifdef WIN32 @@ -65,6 +66,7 @@ #include // for getpid() #endif +using namespace shibsp; using namespace shibtarget; using namespace saml; using namespace xmltooling; @@ -929,14 +931,14 @@ extern "C" void shib_child_init(apr_pool_t* p, server_rec* s) try { g_Config=&ShibTargetConfig::getConfig(); - g_Config->setFeatures( - ShibTargetConfig::Caching | - ShibTargetConfig::Listener | - ShibTargetConfig::Metadata | - ShibTargetConfig::AAP | - ShibTargetConfig::RequestMapper | - ShibTargetConfig::InProcess | - ShibTargetConfig::Logging + SPConfig::getConfig().setFeatures( + SPConfig::Caching | + SPConfig::Listener | + SPConfig::Metadata | + SPConfig::AAP | + SPConfig::RequestMapper | + 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"); diff --git a/apache/mod_shib13.vcproj b/apache/mod_shib13.vcproj index 5b8ccfa..8a0f87c 100644 --- a/apache/mod_shib13.vcproj +++ b/apache/mod_shib13.vcproj @@ -214,10 +214,6 @@ - - diff --git a/isapi_shib/isapi_shib.cpp b/isapi_shib/isapi_shib.cpp index 0074ea6..74684b6 100644 --- a/isapi_shib/isapi_shib.cpp +++ b/isapi_shib/isapi_shib.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -39,6 +40,7 @@ #include #include +using namespace shibsp; using namespace shibtarget; using namespace saml; using namespace xmltooling; @@ -154,14 +156,14 @@ extern "C" BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer) if (!config) config=SHIB_CONFIG; g_Config=&ShibTargetConfig::getConfig(); - g_Config->setFeatures( - ShibTargetConfig::Listener | - ShibTargetConfig::Caching | - ShibTargetConfig::Metadata | - ShibTargetConfig::AAP | - ShibTargetConfig::RequestMapper | - ShibTargetConfig::InProcess | - ShibTargetConfig::Logging + SPConfig::getConfig().setFeatures( + SPConfig::Listener | + SPConfig::Caching | + SPConfig::Metadata | + SPConfig::AAP | + SPConfig::RequestMapper | + SPConfig::InProcess | + SPConfig::Logging ); if (!g_Config->init(schemadir)) { g_Config=NULL; diff --git a/nsapi_shib/nsapi_shib.cpp b/nsapi_shib/nsapi_shib.cpp index 34580d0..aa0ff5a 100644 --- a/nsapi_shib/nsapi_shib.cpp +++ b/nsapi_shib/nsapi_shib.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -57,6 +58,7 @@ extern "C" #include } +using namespace shibsp; using namespace shibtarget; using namespace saml; using namespace xmltooling; @@ -123,14 +125,14 @@ extern "C" NSAPI_PUBLIC int nsapi_shib_init(pblock* pb, Session* sn, Request* rq if (!config) config=SHIB_CONFIG; g_Config=&ShibTargetConfig::getConfig(); - g_Config->setFeatures( - ShibTargetConfig::Listener | - ShibTargetConfig::Caching | - ShibTargetConfig::Metadata | - ShibTargetConfig::AAP | - ShibTargetConfig::RequestMapper | - ShibTargetConfig::InProcess | - ShibTargetConfig::Logging + SPConfig::getConfig().setFeatures( + SPConfig::Listener | + SPConfig::Caching | + SPConfig::Metadata | + SPConfig::AAP | + SPConfig::RequestMapper | + SPConfig::InProcess | + SPConfig::Logging ); if (!g_Config->init(schemadir)) { g_Config=NULL; diff --git a/shar/shar.cpp b/shar/shar.cpp index 521e459..0fde514 100644 --- a/shar/shar.cpp +++ b/shar/shar.cpp @@ -36,6 +36,7 @@ #endif #include +#include #ifdef HAVE_UNISTD_H #include @@ -46,11 +47,12 @@ #include #include -using namespace std; -using namespace saml; -using namespace shibboleth; +using namespace shibsp; using namespace shibtarget; +using namespace shibboleth; +using namespace saml; using namespace log4cpp; +using namespace std; bool shibd_shutdown = false; const char* shar_config = NULL; @@ -104,15 +106,15 @@ int real_main(int preinit) if (preinit) { // initialize the shib-target library - conf.setFeatures( - ShibTargetConfig::Listener | - ShibTargetConfig::Caching | - ShibTargetConfig::Metadata | - ShibTargetConfig::Trust | - ShibTargetConfig::Credentials | - ShibTargetConfig::AAP | - ShibTargetConfig::OutOfProcess | - (shar_checkonly ? (ShibTargetConfig::InProcess | ShibTargetConfig::RequestMapper) : ShibTargetConfig::Logging) + SPConfig::getConfig().setFeatures( + SPConfig::Listener | + SPConfig::Caching | + SPConfig::Metadata | + SPConfig::Trust | + SPConfig::Credentials | + SPConfig::AAP | + SPConfig::OutOfProcess | + (shar_checkonly ? (SPConfig::InProcess | SPConfig::RequestMapper) : SPConfig::Logging) ); if (!shar_config) shar_config=getenv("SHIBCONFIG"); @@ -248,15 +250,15 @@ int main(int argc, char *argv[]) // initialize the shib-target library ShibTargetConfig& conf=ShibTargetConfig::getConfig(); - conf.setFeatures( - ShibTargetConfig::Listener | - ShibTargetConfig::Caching | - ShibTargetConfig::Metadata | - ShibTargetConfig::Trust | - ShibTargetConfig::Credentials | - ShibTargetConfig::AAP | - ShibTargetConfig::OutOfProcess | - (shar_checkonly ? (ShibTargetConfig::InProcess | ShibTargetConfig::RequestMapper) : ShibTargetConfig::Logging) + SPConfig::getConfig().setFeatures( + SPConfig::Listener | + SPConfig::Caching | + SPConfig::Metadata | + SPConfig::Trust | + SPConfig::Credentials | + SPConfig::AAP | + SPConfig::OutOfProcess | + (shar_checkonly ? (SPConfig::InProcess | SPConfig::RequestMapper) : SPConfig::Logging) ); if (!conf.init(shar_schemadir) || !conf.load(shar_config)) { fprintf(stderr, "configuration is invalid, check console for specific problems\n"); diff --git a/shar/test-client.cpp b/shar/test-client.cpp index eb8d9d6..c22b912 100644 --- a/shar/test-client.cpp +++ b/shar/test-client.cpp @@ -20,11 +20,13 @@ #endif #include +#include #include -using namespace std; -using namespace saml; +using namespace shibsp; using namespace shibtarget; +using namespace saml; +using namespace std; int main (int argc, char *argv[]) { @@ -36,7 +38,7 @@ int main (int argc, char *argv[]) schemadir=SHIB_SCHEMAS; ShibTargetConfig& conf=ShibTargetConfig::getConfig(); - conf.setFeatures(ShibTargetConfig::Listener | ShibTargetConfig::InProcess); + SPConfig::getConfig().setFeatures(SPConfig::Listener | SPConfig::InProcess); if (!conf.init(schemadir) || !conf.load(config)) return -10; diff --git a/shib-target/SocketListener.cpp b/shib-target/SocketListener.cpp index 715d852..df0046d 100644 --- a/shib-target/SocketListener.cpp +++ b/shib-target/SocketListener.cpp @@ -24,11 +24,13 @@ #include #include +#include #ifdef HAVE_UNISTD_H # include #endif +using namespace shibsp; using namespace shibtarget; using namespace saml; using namespace xmltooling; @@ -153,11 +155,11 @@ SocketListener::SocketListener(const DOMElement* e) : log(&Category::getInstance m_shutdown(NULL), m_child_lock(NULL), m_child_wait(NULL), m_socketpool(NULL), m_socket((ShibSocket)0) { // Are we a client? - if (ShibTargetConfig::getConfig().isEnabled(ShibTargetConfig::InProcess)) { + if (SPConfig::getConfig().isEnabled(SPConfig::InProcess)) { m_socketpool=new SocketPool(*log,this); } // Are we a server? - if (ShibTargetConfig::getConfig().isEnabled(ShibTargetConfig::OutOfProcess)) { + if (SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess)) { m_child_lock = Mutex::create(); m_child_wait = CondWait::create(); } diff --git a/shib-target/XMLRequestMapper.cpp b/shib-target/XMLRequestMapper.cpp index 849f445..c12fa29 100644 --- a/shib-target/XMLRequestMapper.cpp +++ b/shib-target/XMLRequestMapper.cpp @@ -242,7 +242,7 @@ Override::Override(const DOMElement* e, Category& log, const Override* base) : m Override::~Override() { delete m_acl; - for_each(m_map.begin(),m_map.end(),cleanup_pair()); + for_each(m_map.begin(),m_map.end(),xmltooling::cleanup_pair()); } pair Override::getBool(const char* name, const char* ns) const diff --git a/shib-target/internal.h b/shib-target/internal.h index 337ddba..e68ed96 100644 --- a/shib-target/internal.h +++ b/shib-target/internal.h @@ -49,10 +49,6 @@ #define SHIBT_LOGCAT "shibtarget" #define SHIBTRAN_LOGCAT "Shibboleth-TRANSACTION" -// Controls default logging level of console tools and other situations -// where full shibboleth.xml-based logging isn't used. -#define SHIB_LOGGING "WARN" - namespace shibtarget { // Generic class, which handles the IPropertySet configuration interface. // Most of the basic configuration details are exposed via this interface. diff --git a/shib-target/shib-ccache.cpp b/shib-target/shib-ccache.cpp index a763f1e..1cea2d1 100644 --- a/shib-target/shib-ccache.cpp +++ b/shib-target/shib-ccache.cpp @@ -27,6 +27,7 @@ #endif #include +#include #include #include @@ -37,6 +38,7 @@ #include #endif +using namespace shibsp; using namespace shibtarget; using namespace shibboleth; using namespace saml; @@ -425,7 +427,7 @@ MemorySessionCacheEntry::MemorySessionCacheEntry( // Save actual objects only if we're running inprocess. The subject needs to be // owned by the entry, so we'll defer creation of a cloned copy. - if (ShibTargetConfig::getConfig().isEnabled(ShibTargetConfig::InProcess)) { + if (SPConfig::getConfig().isEnabled(SPConfig::InProcess)) { if (m_obj["tokens.filtered"].isstring()) m_pFiltered=filtered.release(); } @@ -504,7 +506,7 @@ MemorySessionCacheEntry::MemorySessionCacheEntry( m_obj.addmember("tokens.filtered").string(fstr.c_str()); // Save actual objects only if we're running inprocess. - if (ShibTargetConfig::getConfig().isEnabled(ShibTargetConfig::InProcess)) { + if (SPConfig::getConfig().isEnabled(SPConfig::InProcess)) { m_pUnfiltered=unfiltered.release(); if (m_obj["tokens.filtered"].isstring()) m_pFiltered=filtered.release(); @@ -680,7 +682,7 @@ void MemorySessionCacheEntry::populate(const IApplication* application, const IE m_obj.addmember("tokens.filtered").string(fstr.c_str()); // Save actual objects only if we're running inprocess. - if (ShibTargetConfig::getConfig().isEnabled(ShibTargetConfig::InProcess)) { + if (SPConfig::getConfig().isEnabled(SPConfig::InProcess)) { m_pUnfiltered=respFromSink.release(); if (m_obj["tokens.filtered"].isstring()) m_pFiltered=filteredFromSink.release(); @@ -735,7 +737,7 @@ void MemorySessionCacheEntry::populate(const IApplication* application, const IE m_responseExpiration=calculateExpiration(*new_responses.second); // Save actual objects only if we're running inprocess. - if (ShibTargetConfig::getConfig().isEnabled(ShibTargetConfig::InProcess)) { + if (SPConfig::getConfig().isEnabled(SPConfig::InProcess)) { m_pUnfiltered=r1.release(); if (m_obj["tokens.filtered"].isstring()) m_pFiltered=r2.release(); @@ -1060,7 +1062,7 @@ MemorySessionCache::MemorySessionCache(const DOMElement* e) // Register for remoted messages. IListener* listener=ShibTargetConfig::getConfig().getINI()->getListener(); - if (listener && ShibTargetConfig::getConfig().isEnabled(ShibTargetConfig::OutOfProcess)) { + if (listener && SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess)) { restoreInsert=listener->regListener("SessionCache::insert",this); restoreFind=listener->regListener("SessionCache::find",this); restoreRemove=listener->regListener("SessionCache::remove",this); @@ -1082,13 +1084,13 @@ MemorySessionCache::~MemorySessionCache() // Unregister remoted messages. IListener* listener=ShibTargetConfig::getConfig().getINI()->getListener(); - if (listener && ShibTargetConfig::getConfig().isEnabled(ShibTargetConfig::OutOfProcess)) { + if (listener && SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess)) { listener->unregListener("SessionCache::insert",this,restoreInsert); listener->unregListener("SessionCache::find",this,restoreFind); listener->unregListener("SessionCache::remove",this,restoreRemove); } - for_each(m_hashtable.begin(),m_hashtable.end(),shibtarget::cleanup_pair()); + for_each(m_hashtable.begin(),m_hashtable.end(),xmltooling::cleanup_pair()); delete m_lock; delete shutdown_wait; } @@ -1575,7 +1577,7 @@ void* MemorySessionCache::cleanup_fcn(void* cache_p) IPlugIn* MemoryCacheFactory(const DOMElement* e) { // If this is a long-lived process, we return the "real" cache. - if (ShibTargetConfig::getConfig().isEnabled(ShibTargetConfig::OutOfProcess)) + if (SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess)) return new MemorySessionCache(e); // Otherwise, we return a stubbed front-end that remotes calls to the real cache. return new StubCache(e); diff --git a/shib-target/shib-config.cpp b/shib-target/shib-config.cpp index bd04094..8f82e9e 100644 --- a/shib-target/shib-config.cpp +++ b/shib-target/shib-config.cpp @@ -23,21 +23,20 @@ */ #include "internal.h" -#include #include +#include #include #include -#include #include +using namespace shibsp; using namespace shibtarget; using namespace shibboleth; using namespace saml; using namespace log4cpp; using namespace std; -using xmltooling::TemplateEngine; using xmltooling::XMLToolingConfig; namespace { @@ -69,12 +68,6 @@ ShibTargetConfig& ShibTargetConfig::getConfig() bool STConfig::init(const char* schemadir) { - // Chain this to XMLTooling for now... - const char* loglevel=getenv("SHIB_LOGGING"); - if (!loglevel) - loglevel = SHIB_LOGGING; - XMLToolingConfig::getConfig().log_config(loglevel); - #ifdef _DEBUG xmltooling::NDC ndc("init"); #endif @@ -90,30 +83,14 @@ bool STConfig::init(const char* schemadir) SAMLConfig& samlConf=SAMLConfig::getConfig(); if (schemadir) samlConf.schema_dir = schemadir; - try { - if (!samlConf.init() || !opensaml::SAMLConfig::getConfig().init()) { - log.fatal("Failed to initialize SAML Library"); - return false; - } - } - catch (...) { - log.fatal("Died initializing SAML Library"); + if (!samlConf.init() || !SPConfig::getConfig().init(NULL)) { + log.fatal("failed to initialize SP library"); return false; } - XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine()); - XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp"); - ShibConfig& shibConf=ShibConfig::getConfig(); - try { - if (!shibConf.init()) { - log.fatal("Failed to initialize Shib library"); - samlConf.term(); - return false; - } - } - catch (...) { - log.fatal("Died initializing Shib library."); + if (!shibConf.init()) { + log.fatal("Failed to initialize Shib library"); samlConf.term(); return false; } @@ -175,7 +152,7 @@ bool STConfig::load(const char* config) pair skew=m_ini->getUnsignedInt("clockSkew"); SAMLConfig::getConfig().clock_skew_secs=skew.first ? skew.second : 180; if (skew.first) - xmltooling::XMLToolingConfig::getConfig().clock_skew_secs=skew.second; + XMLToolingConfig::getConfig().clock_skew_secs=skew.second; m_tranLog=new FixedContextCategory(SHIBTRAN_LOGCAT); m_tranLog->info("opened transaction log"); @@ -211,7 +188,7 @@ void STConfig::shutdown() delete m_ini; m_ini = NULL; ShibConfig::getConfig().term(); - opensaml::SAMLConfig::getConfig().term(); SAMLConfig::getConfig().term(); + SPConfig::getConfig().term(); log.info("library shutdown complete"); } diff --git a/shib-target/shib-handlers.cpp b/shib-target/shib-handlers.cpp index afe59e3..5d752b3 100644 --- a/shib-target/shib-handlers.cpp +++ b/shib-target/shib-handlers.cpp @@ -22,18 +22,21 @@ */ #include "internal.h" + #include #include +#include #ifdef HAVE_UNISTD_H # include #endif -using namespace std; -using namespace saml; -using namespace shibboleth; +using namespace shibsp; using namespace shibtarget; +using namespace shibboleth; +using namespace saml; using namespace log4cpp; +using namespace std; using opensaml::CommonDomainCookie; @@ -234,7 +237,7 @@ SAML1Consumer::SAML1Consumer(const DOMElement* e) m_address += "::SAML1Consumer::run"; // Register for remoted messages. - if (ShibTargetConfig::getConfig().isEnabled(ShibTargetConfig::OutOfProcess)) { + if (SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess)) { IListener* listener=ShibTargetConfig::getConfig().getINI()->getListener(); if (listener) listener->regListener(m_address.c_str(),this); @@ -246,7 +249,7 @@ SAML1Consumer::SAML1Consumer(const DOMElement* e) SAML1Consumer::~SAML1Consumer() { IListener* listener=ShibTargetConfig::getConfig().getINI()->getListener(); - if (listener && ShibTargetConfig::getConfig().isEnabled(ShibTargetConfig::OutOfProcess)) + if (listener && SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess)) listener->unregListener(m_address.c_str(),this); counter--; } diff --git a/shib-target/shib-ini.cpp b/shib-target/shib-ini.cpp index 1c487cc..06f8207 100644 --- a/shib-target/shib-ini.cpp +++ b/shib-target/shib-ini.cpp @@ -22,17 +22,19 @@ #include "internal.h" +#include #include #include #include #include #include -using namespace std; -using namespace saml; -using namespace shibboleth; +using namespace shibsp; using namespace shibtarget; +using namespace shibboleth; +using namespace saml; using namespace log4cpp; +using namespace std; namespace shibtarget { @@ -211,7 +213,7 @@ XMLPropertySet::~XMLPropertySet() { for (map >::iterator i=m_map.begin(); i!=m_map.end(); i++) XMLString::release(&(i->second.first)); - for_each(m_nested.begin(),m_nested.end(),shibtarget::cleanup_pair()); + for_each(m_nested.begin(),m_nested.end(),xmltooling::cleanup_pair()); } void XMLPropertySet::load( @@ -418,7 +420,7 @@ XMLApplication::XMLApplication( m_hash+=getString("providerId").second; m_hash=SAMLArtifact::toHex(SAMLArtifactType0001::generateSourceId(m_hash.c_str())); - ShibTargetConfig& conf=ShibTargetConfig::getConfig(); + SPConfig& conf=SPConfig::getConfig(); SAMLConfig& shibConf=SAMLConfig::getConfig(); // Process handlers. @@ -562,7 +564,7 @@ XMLApplication::XMLApplication( // Always include our own providerId as an audience. m_audiences.push_back(getXMLString("providerId").second); - if (conf.isEnabled(ShibTargetConfig::AAP)) { + if (conf.isEnabled(SPConfig::AAP)) { nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(AAPProvider)); for (i=0; nlist && igetLength(); i++) { if (nlist->item(i)->getParentNode()->isSameNode(e)) { @@ -585,7 +587,7 @@ XMLApplication::XMLApplication( } } - if (conf.isEnabled(ShibTargetConfig::Metadata)) { + if (conf.isEnabled(SPConfig::Metadata)) { nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MetadataProvider)); for (i=0; nlist && igetLength(); i++) { if (nlist->item(i)->getParentNode()->isSameNode(e)) { @@ -628,7 +630,7 @@ XMLApplication::XMLApplication( } } - if (conf.isEnabled(ShibTargetConfig::Trust)) { + if (conf.isEnabled(SPConfig::Trust)) { nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(TrustProvider)); for (i=0; nlist && igetLength(); i++) { if (nlist->item(i)->getParentNode()->isSameNode(e)) { @@ -665,7 +667,7 @@ XMLApplication::XMLApplication( } } - if (conf.isEnabled(ShibTargetConfig::OutOfProcess)) { + if (conf.isEnabled(SPConfig::OutOfProcess)) { // Really finally, build local browser profile and binding objects. m_profile=new ShibBrowserProfile( this, @@ -704,18 +706,18 @@ void XMLApplication::cleanup() delete m_bindingHook; delete m_binding; delete m_profile; - for_each(m_handlers.begin(),m_handlers.end(),shibtarget::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(),shibtarget::cleanup_pair()); + for_each(m_credMap.begin(),m_credMap.end(),xmltooling::cleanup_pair()); #else - for_each(m_credMap.begin(),m_credMap.end(),shibtarget::cleanup_pair()); + for_each(m_credMap.begin(),m_credMap.end(),xmltooling::cleanup_pair()); #endif - for_each(m_designators.begin(),m_designators.end(),shibtarget::cleanup()); - for_each(m_aaps.begin(),m_aaps.end(),shibtarget::cleanup()); - for_each(m_metadatas.begin(),m_metadatas.end(),shibtarget::cleanup()); - for_each(m_trusts.begin(),m_trusts.end(),shibtarget::cleanup()); + for_each(m_designators.begin(),m_designators.end(),xmltooling::cleanup()); + for_each(m_aaps.begin(),m_aaps.end(),xmltooling::cleanup()); + for_each(m_metadatas.begin(),m_metadatas.end(),xmltooling::cleanup()); + for_each(m_trusts.begin(),m_trusts.end(),xmltooling::cleanup()); } short XMLApplication::acceptNode(const DOMNode* node) const @@ -1000,7 +1002,7 @@ void XMLConfigImpl::init(bool first) } SAMLConfig& shibConf=SAMLConfig::getConfig(); - ShibTargetConfig& conf=ShibTargetConfig::getConfig(); + SPConfig& conf=SPConfig::getConfig(); const DOMElement* SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(SHAR)); if (!SHAR) SHAR=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Global)); @@ -1013,11 +1015,11 @@ void XMLConfigImpl::init(bool first) SHIRE=saml::XML::getFirstChildElement(ReloadableXMLFileImpl::m_root,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(InProcess)); // Initialize log4cpp manually in order to redirect log messages as soon as possible. - if (conf.isEnabled(ShibTargetConfig::Logging)) { + if (conf.isEnabled(SPConfig::Logging)) { const XMLCh* logger=NULL; - if (conf.isEnabled(ShibTargetConfig::OutOfProcess)) + if (conf.isEnabled(SPConfig::OutOfProcess)) logger=SHAR->getAttributeNS(NULL,SHIBT_L(logger)); - else if (conf.isEnabled(ShibTargetConfig::InProcess)) + else if (conf.isEnabled(SPConfig::InProcess)) logger=SHIRE->getAttributeNS(NULL,SHIBT_L(logger)); if (!logger || !*logger) logger=ReloadableXMLFileImpl::m_root->getAttributeNS(NULL,SHIBT_L(logger)); @@ -1067,7 +1069,7 @@ void XMLConfigImpl::init(bool first) } } - if (conf.isEnabled(ShibTargetConfig::OutOfProcess)) { + if (conf.isEnabled(SPConfig::OutOfProcess)) { exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Extensions)); if (exts) { exts=saml::XML::getFirstChildElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library)); @@ -1091,7 +1093,7 @@ void XMLConfigImpl::init(bool first) } } - if (conf.isEnabled(ShibTargetConfig::InProcess)) { + if (conf.isEnabled(SPConfig::InProcess)) { exts=saml::XML::getFirstChildElement(SHIRE,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Extensions)); if (exts) { exts=saml::XML::getFirstChildElement(exts,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(Library)); @@ -1116,7 +1118,7 @@ void XMLConfigImpl::init(bool first) } // Instantiate the Listener and SessionCache objects. - if (conf.isEnabled(ShibTargetConfig::Listener)) { + if (conf.isEnabled(SPConfig::Listener)) { IPlugIn* plugin=NULL; exts=saml::XML::getFirstChildElement(SHAR,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(UnixListener)); if (exts) { @@ -1154,9 +1156,9 @@ void XMLConfigImpl::init(bool first) } } - if (conf.isEnabled(ShibTargetConfig::Caching)) { + if (conf.isEnabled(SPConfig::Caching)) { IPlugIn* plugin=NULL; - const DOMElement* container=conf.isEnabled(ShibTargetConfig::OutOfProcess) ? SHAR : SHIRE; + const DOMElement* container=conf.isEnabled(SPConfig::OutOfProcess) ? SHAR : SHIRE; exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MemorySessionCache)); if (exts) { log.info("building Session Cache of type %s...",shibtarget::XML::MemorySessionCacheType); @@ -1200,7 +1202,7 @@ void XMLConfigImpl::init(bool first) } // Replay cache. - container=conf.isEnabled(ShibTargetConfig::OutOfProcess) ? SHAR : SHIRE; + container=conf.isEnabled(SPConfig::OutOfProcess) ? SHAR : SHIRE; exts=saml::XML::getFirstChildElement(container,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(ODBCReplayCache)); if (exts) { log.info("building Replay Cache of type %s...",shibtarget::XML::ODBCReplayCacheType); @@ -1230,7 +1232,7 @@ void XMLConfigImpl::init(bool first) } // Back to the fully dynamic stuff...next up is the Request Mapper. - if (conf.isEnabled(ShibTargetConfig::RequestMapper)) { + if (conf.isEnabled(SPConfig::RequestMapper)) { const DOMElement* child=saml::XML::getFirstChildElement(SHIRE,shibtarget::XML::SHIBTARGET_NS,SHIBT_L(RequestMapProvider)); if (child) { auto_ptr_char type(child->getAttributeNS(NULL,SHIBT_L(type))); @@ -1255,7 +1257,7 @@ void XMLConfigImpl::init(bool first) // Now we load any credentials providers. DOMNodeList* nlist; - if (conf.isEnabled(ShibTargetConfig::Credentials)) { + if (conf.isEnabled(SPConfig::Credentials)) { nlist=ReloadableXMLFileImpl::m_root->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(CredentialsProvider)); for (unsigned int i=0; nlist && igetLength(); i++) { auto_ptr_char type(static_cast(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type))); @@ -1341,8 +1343,8 @@ void XMLConfigImpl::init(bool first) XMLConfigImpl::~XMLConfigImpl() { delete m_requestMapper; - for_each(m_appmap.begin(),m_appmap.end(),cleanup_pair()); - for_each(m_creds.begin(),m_creds.end(),cleanup()); + for_each(m_appmap.begin(),m_appmap.end(),xmltooling::cleanup_pair()); + for_each(m_creds.begin(),m_creds.end(),xmltooling::cleanup()); ShibConfig::getConfig().clearAttributeMappings(); - for_each(m_attrFactories.begin(),m_attrFactories.end(),cleanup()); + for_each(m_attrFactories.begin(),m_attrFactories.end(),xmltooling::cleanup()); } diff --git a/shib-target/shib-target.h b/shib-target/shib-target.h index 9cefe6e..a30898d 100644 --- a/shib-target/shib-target.h +++ b/shib-target/shib-target.h @@ -362,36 +362,19 @@ namespace shibtarget { class SHIBTARGET_EXPORTS ShibTargetConfig { public: - ShibTargetConfig() : m_ini(NULL), m_features(0) {} + ShibTargetConfig() : m_ini(NULL) {} virtual ~ShibTargetConfig() {} virtual bool init(const char* schemadir) = 0; virtual bool load(const char* config) = 0; virtual void shutdown() = 0; - enum components_t { - Listener = 1, - Caching = 2, - Metadata = 4, - Trust = 8, - Credentials = 16, - AAP = 32, - RequestMapper = 64, - OutOfProcess = 128, - InProcess = 256, - Logging = 512 - }; - void setFeatures(long enabled) {m_features = enabled;} - bool isEnabled(components_t feature) {return (m_features & feature)>0;} virtual IConfig* getINI() const {return m_ini;} static ShibTargetConfig& getConfig(); protected: IConfig* m_ini; - - private: - unsigned long m_features; }; class ShibTargetPriv; @@ -681,19 +664,6 @@ namespace shibtarget { static const XMLCh UnixListener[]; }; }; - - - // Template cleanup functors for use with for_each algorithm - template struct cleanup - { - void operator()(T* ptr) {delete ptr;} - void operator()(const T* ptr) {delete const_cast(ptr);} - }; - - template struct cleanup_pair - { - void operator()(std::pair p) {delete p.second;} - }; } #endif /* SHIB_TARGET_H */ diff --git a/shibsp/.gitignore b/shibsp/.gitignore index d7a4d4d..157a69d 100644 --- a/shibsp/.gitignore +++ b/shibsp/.gitignore @@ -1 +1,2 @@ /*.user +/Debug diff --git a/shibsp/Makefile.am b/shibsp/Makefile.am new file mode 100644 index 0000000..5e8fc11 --- /dev/null +++ b/shibsp/Makefile.am @@ -0,0 +1,39 @@ +AUTOMAKE_OPTIONS = foreign + +pkgsysconfdir = $(sysconfdir)/@PACKAGE@ +xmldir = $(datadir)/xml + +lib_LTLIBRARIES = libshibsp.la + +libshibspincludedir = $(includedir)/shibsp + +libshibspinclude_HEADERS = \ + base.h \ + exceptions.h \ + paths.h \ + version.h \ + SPConfig.h + +noinst_HEADERS = \ + internal.h + +libshibsp_la_SOURCES = \ + SPConfig.cpp + +# this is different from the project version +# http://sources.redhat.com/autobook/autobook/autobook_91.html +libshibsp_la_LDFLAGS = -version-info 1:0:0 + +paths.h: ${srcdir}/paths.h.in Makefile ${top_builddir}/config.status + rm -f $@.tmp + sed < ${srcdir}/$@.in > $@.tmp \ + -e 's:@-PKGSYSCONFDIR-@:${pkgsysconfdir}:' \ + -e 's:@-XMLDIR-@:${xmldir}:' + cmp -s $@ $@.tmp || mv $@.tmp $@ + rm -f $@.tmp + +install-exec-hook: + for la in $(lib_LTLIBRARIES) ; do rm -f $(DESTDIR)$(libdir)/$$la ; done + +EXTRA_DIST = shibsp.vcproj paths.h.in +BUILT_SOURCES = paths.h diff --git a/shibsp/SPConfig.cpp b/shibsp/SPConfig.cpp new file mode 100644 index 0000000..125c995 --- /dev/null +++ b/shibsp/SPConfig.cpp @@ -0,0 +1,105 @@ + +/* + * Copyright 2001-2006 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. + */ + +/** + * SPConfig.cpp + * + * Library configuration + */ + +#include "internal.h" +#include "exceptions.h" +#include "SPConfig.h" + +#include +#include +#include +#include + +using namespace shibsp; +using namespace opensaml; +using namespace xmltooling; +using namespace log4cpp; + +DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp); +DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp); + +namespace shibsp { + SPInternalConfig g_config; +} + +SPConfig& SPConfig::getConfig() +{ + return g_config; +} + +SPInternalConfig& SPInternalConfig::getInternalConfig() +{ + return g_config; +} + +void SPConfig::setServiceProvider(ServiceProvider* serviceProvider) +{ + //delete m_serviceProvider; + m_serviceProvider = serviceProvider; +} + +bool SPInternalConfig::init(const char* catalog_path) +{ +#ifdef _DEBUG + NDC ndc("init"); +#endif + Category& log=Category::getInstance(SHIBSP_LOGCAT".Config"); + log.debug("library initialization started"); + + const char* loglevel=getenv("SHIBSP_LOGGING"); + if (!loglevel) + loglevel = SHIBSP_LOGGING; + XMLToolingConfig::getConfig().log_config(loglevel); + + if (catalog_path) + XMLToolingConfig::getConfig().catalog_path = catalog_path; + + if (!SAMLConfig::getConfig().init()) { + log.fatal("failed to initialize OpenSAML library"); + return false; + } + + XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine()); + XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp"); + + REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp); + REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp); + + log.info("library initialization complete"); + return true; +} + +void SPInternalConfig::term() +{ +#ifdef _DEBUG + NDC ndc("term"); +#endif + Category& log=Category::getInstance(SHIBSP_LOGCAT".Config"); + log.info("shutting down the library"); + + //delete m_serviceProvider; + m_serviceProvider = NULL; + + SAMLConfig::getConfig().term(); + log.info("library shutdown complete"); +} diff --git a/shibsp/SPConfig.h b/shibsp/SPConfig.h new file mode 100644 index 0000000..44d32cc --- /dev/null +++ b/shibsp/SPConfig.h @@ -0,0 +1,136 @@ +/* + * Copyright 2001-2006 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. + */ + +/** + * @file shibsp/SPConfig.h + * + * Library configuration + */ + +#ifndef __shibsp_config_h__ +#define __shibsp_config_h__ + +#include + +/** + * @namespace shibsp + * Shibboleth Service Provider Library + */ +namespace shibsp { + + class SHIBSP_API ServiceProvider; + + /** + * Singleton object that manages library startup/shutdown. + */ + class SHIBSP_API SPConfig + { + MAKE_NONCOPYABLE(SPConfig); + public: + virtual ~SPConfig() {} + + /** + * Returns the global configuration object for the library. + * + * @return reference to the global library configuration object + */ + static SPConfig& getConfig(); + + /** + * Bitmask values representing subsystems of the library. + */ + enum components_t { + Listener = 1, + Caching = 2, + Metadata = 4, + Trust = 8, + Credentials = 16, + AAP = 32, + RequestMapper = 64, + OutOfProcess = 128, + InProcess = 256, + Logging = 512 + }; + + /** + * Set a bitmask of subsystems to activate. + * + * @param enabled bitmask of component constants + */ + void setFeatures(unsigned long enabled) { + m_features = enabled; + } + + /** + * Test whether a subsystem is enabled. + * + * @param feature subsystem/component to test + * @return true iff feature is enabled + */ + bool isEnabled(components_t feature) { + return (m_features & feature)>0; + } + + /** + * Initializes library + * + * Each process using the library MUST call this function exactly once + * before using any library classes. + * + * @param catalog_path delimited set of schema catalog files to load + * @return true iff initialization was successful + */ + virtual bool init(const char* catalog_path)=0; + + /** + * Shuts down library + * + * Each process using the library SHOULD call this function exactly once + * before terminating itself. + */ + virtual void term()=0; + + /** + * Sets the global ServiceProvider instance. + * This method must be externally synchronized with any code that uses the object. + * Any previously set object is destroyed. + * + * @param serviceProvider new ServiceProvider instance to store + */ + void setServiceProvider(ServiceProvider* serviceProvider); + + /** + * Returns the global ServiceProvider instance. + * + * @return global ServiceProvider or NULL + */ + ServiceProvider* getServiceProvider() const { + return m_serviceProvider; + } + + protected: + SPConfig() : m_serviceProvider(NULL) {} + + /** Global ServiceProvider instance. */ + ServiceProvider* m_serviceProvider; + + private: + unsigned long m_features; + }; + +}; + +#endif /* __shibsp_config_h__ */ diff --git a/shibsp/base.h b/shibsp/base.h new file mode 100644 index 0000000..774d7a1 --- /dev/null +++ b/shibsp/base.h @@ -0,0 +1,96 @@ +/* + * Copyright 2001-2006 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. + */ + +/** + * @file shibsp/base.h + * + * Base header file definitions + * Must be included prior to including any other header + */ + +#ifndef __shibsp_base_h__ +#define __shibsp_base_h__ + +#include + +// Windows and GCC4 Symbol Visibility Macros +#ifdef WIN32 + #define SHIBSP_IMPORT __declspec(dllimport) + #define SHIBSP_EXPORT __declspec(dllexport) + #define SHIBSP_DLLLOCAL + #define SHIBSP_DLLPUBLIC +#else + #define SHIBSP_IMPORT + #ifdef GCC_HASCLASSVISIBILITY + #define SHIBSP_EXPORT __attribute__ ((visibility("default"))) + #define SHIBSP_DLLLOCAL __attribute__ ((visibility("hidden"))) + #define SHIBSP_DLLPUBLIC __attribute__ ((visibility("default"))) + #else + #define SHIBSP_EXPORT + #define SHIBSP_DLLLOCAL + #define SHIBSP_DLLPUBLIC + #endif +#endif + +// Define SHIBSP_API for DLL builds +#ifdef SHIBSP_EXPORTS + #define SHIBSP_API SHIBSP_EXPORT +#else + #define SHIBSP_API SHIBSP_IMPORT +#endif + +// Throwable classes must always be visible on GCC in all binaries +#ifdef WIN32 + #define SHIBSP_EXCEPTIONAPI(api) api +#elif defined(GCC_HASCLASSVISIBILITY) + #define SHIBSP_EXCEPTIONAPI(api) SHIBSP_EXPORT +#else + #define SHIBSP_EXCEPTIONAPI(api) +#endif + +#ifdef WIN32 + +/** + * Default catalog path on Windows. + */ +# define SHIBSP_SCHEMAS "/opt/shibboleth-sp/share/xml/xmltooling/catalog.xml;/opt/shibboleth-sp/share/xml/opensaml/catalog.xml;/opt/shibboleth-sp/share/xml/shibboleth/catalog.xml" + +/** + * Default path to configuration file on Windows. + */ +# define SHIBSP_CONFIG "/opt/shibboleth-sp/etc/shibboleth/shibboleth.xml" + +#else +# include +#endif + +/** + * Logging category for Service Provider functions. + */ +#define SHIBSP_LOGCAT "Shibboleth.SP" + +/** + * Logging category for Service Provider auditing. + */ +#define SHIBSP_TX_LOGCAT "Shibboleth-TRANSACTION" + +/** + * Controls default logging level of console tools and other situations + * where fully-configured logging isn't used. + */ +#define SHIBSP_LOGGING "WARN" + +#endif /* __shibsp_base_h__ */ diff --git a/shibsp/exceptions.h b/shibsp/exceptions.h new file mode 100644 index 0000000..536ec80 --- /dev/null +++ b/shibsp/exceptions.h @@ -0,0 +1,36 @@ +/* + * Copyright 2001-2006 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. + */ + +/** + * @file shibsp/exceptions.h + * + * Exception classes + */ + +#ifndef __shibsp_exceptions_h__ +#define __shibsp_exceptions_h__ + +#include +#include + +namespace shibsp { + + DECL_XMLTOOLING_EXCEPTION(ConfigurationException,SHIBSP_EXCEPTIONAPI(SHIBSP_API),shibsp,xmltooling::XMLToolingException,Exceptions during configuration.); + DECL_XMLTOOLING_EXCEPTION(ListenerException,SHIBSP_EXCEPTIONAPI(SHIBSP_API),shibsp,xmltooling::XMLToolingException,Exceptions during inter-process communication.); + +}; + +#endif /* __shibsp_exceptions_h__ */ diff --git a/shibsp/internal.h b/shibsp/internal.h new file mode 100644 index 0000000..13f2598 --- /dev/null +++ b/shibsp/internal.h @@ -0,0 +1,61 @@ +/* + * Copyright 2001-2005 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. + */ + +/* + * internal.h - internally visible classes + */ + +#ifndef __shibsp_internal_h__ +#define __shibsp_internal_h__ + +#ifdef WIN32 +# define _CRT_SECURE_NO_DEPRECATE 1 +# define _CRT_NONSTDC_NO_DEPRECATE 1 +#endif + +// Export public APIs +#define SHIBSP_EXPORTS + +// eventually we might be able to support autoconf via cygwin... +#if defined (_MSC_VER) || defined(__BORLANDC__) +# include "config_win32.h" +#else +# include "config.h" +#endif + +#include "base.h" +#include "SPConfig.h" + +namespace shibsp { + + /// @cond OFF + class SPInternalConfig : public SPConfig + { + public: + SPInternalConfig() {} + + static SPInternalConfig& getInternalConfig(); + + bool init(const char* catalog_path); + void term(); + + private: + }; + /// @endcond + +}; + +#endif /* __shibsp_internal_h__ */ diff --git a/shibsp/paths.h.in b/shibsp/paths.h.in new file mode 100644 index 0000000..e6cebd3 --- /dev/null +++ b/shibsp/paths.h.in @@ -0,0 +1,36 @@ +/* + * Copyright 2001-2005 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. + */ + +/** + * @file shibsp/paths.h + * + * Default configuration paths. + */ + +#ifndef __shibsp_paths_h__ +#define __shibsp_paths_h__ + +/** + * Default schema catalogs. + */ +#define SHIBSP_SCHEMAS "@-XMLDIR-@/xmltooling/catalog.xml:@-XMLDIR-@/opensaml/catalog.xml:@-XMLDIR-@/shibboleth/catalog.xml" + +/** + * Default location of SP configuration file. + */ +#define SHIBSP_CONFIG "@-PKGSYSCONFDIR-@/shibboleth.xml" + +#endif /* __shibsp_paths_h__ */ diff --git a/shibsp/shibsp.vcproj b/shibsp/shibsp.vcproj index ba8a96d..803a9a2 100644 --- a/shibsp/shibsp.vcproj +++ b/shibsp/shibsp.vcproj @@ -67,7 +67,7 @@ AdditionalLibraryDirectories=""..\..\cpp-opensaml1\saml\Debug";"..\..\cpp-opensaml2\Debug";"..\..\cpp-xmltooling\Debug"" GenerateDebugInformation="true" SubSystem="2" - ImportLibrary="$(TargetDir)$(TargetName)1D.lib" + ImportLibrary="$(TargetDir)$(ProjectName)1D.lib" TargetMachine="1" /> + + + + + + + + + + + + + +// --------------------------------------------------------------------------- +// V E R S I O N S P E C I F I C A T I O N + +/** + * MODIFY THESE NUMERIC VALUES TO COINCIDE WITH OPENSAML VERSION + * AND DO NOT MODIFY ANYTHING ELSE IN THIS VERSION HEADER FILE + */ + +#define SHIBSP_VERSION_MAJOR 1 +#define SHIBSP_VERSION_MINOR 0 +#define SHIBSP_VERSION_REVISION 0 + +/** DO NOT MODIFY BELOW THIS LINE */ + +/** + * MAGIC THAT AUTOMATICALLY GENERATES THE FOLLOWING: + * + * gShibSPVersionStr, gShibSPFullVersionStr, gShibSPMajVersion, gShibSPMinVersion, gShibSPRevision + */ + +// --------------------------------------------------------------------------- +// V E R S I O N I N F O R M A T I O N + +// ShibSP version strings; these particular macros cannot be used for +// conditional compilation as they are not numeric constants + +#define SHIBSP_FULLVERSIONSTR INVK_CAT3_SEP_UNDERSCORE(SHIBSP_VERSION_MAJOR,SHIBSP_VERSION_MINOR,SHIBSP_VERSION_REVISION) +#define SHIBSP_FULLVERSIONDOT INVK_CAT3_SEP_PERIOD(SHIBSP_VERSION_MAJOR,SHIBSP_VERSION_MINOR,SHIBSP_VERSION_REVISION) +#define SHIBSP_FULLVERSIONNUM INVK_CAT3_SEP_NIL(SHIBSP_VERSION_MAJOR,SHIBSP_VERSION_MINOR,SHIBSP_VERSION_REVISION) +#define SHIBSP_VERSIONSTR INVK_CAT2_SEP_UNDERSCORE(SHIBSP_VERSION_MAJOR,SHIBSP_VERSION_MINOR) + +const char* const gShibSPVersionStr = SHIBSP_VERSIONSTR; +const char* const gShibSPFullVersionStr = SHIBSP_FULLVERSIONSTR; +const unsigned int gShibSPMajVersion = SHIBSP_VERSION_MAJOR; +const unsigned int gShibSPMinVersion = SHIBSP_VERSION_MINOR; +const unsigned int gShibSPRevision = SHIBSP_VERSION_REVISION; + +// ShibSP version numeric constants that can be used for conditional +// compilation purposes. + +#define _SHIBSP_VERSION CALC_EXPANDED_FORM (SHIBSP_VERSION_MAJOR,SHIBSP_VERSION_MINOR,SHIBSP_VERSION_REVISION) + +#endif /* __shibsp_version_h__ */ diff --git a/test/posttest.cpp b/test/posttest.cpp index 3ef8143..de8051a 100644 --- a/test/posttest.cpp +++ b/test/posttest.cpp @@ -20,12 +20,15 @@ #endif #include -#include "../shib-target/shib-target.h" +#include -using namespace std; -using namespace saml; -using namespace shibboleth; +#include + +using namespace shibsp; using namespace shibtarget; +using namespace shibboleth; +using namespace saml; +using namespace std; int main(int argc,char* argv[]) { @@ -65,11 +68,11 @@ int main(int argc,char* argv[]) a_param="default"; ShibTargetConfig& conf=ShibTargetConfig::getConfig(); - conf.setFeatures( - ShibTargetConfig::Listener | - ShibTargetConfig::Metadata | - ShibTargetConfig::Trust | - ShibTargetConfig::OutOfProcess + SPConfig::getConfig().setFeatures( + SPConfig::Listener | + SPConfig::Metadata | + SPConfig::Trust | + SPConfig::OutOfProcess ); if (!conf.init(path) || !conf.load(config)) return -10; diff --git a/test/shibtest.cpp b/test/shibtest.cpp index f7eb72e..1c8724f 100644 --- a/test/shibtest.cpp +++ b/test/shibtest.cpp @@ -19,12 +19,14 @@ # define _CRT_SECURE_NO_DEPRECATE 1 #endif -#include "../shib-target/shib-target.h" +#include +#include -using namespace std; -using namespace saml; -using namespace shibboleth; +using namespace shibsp; using namespace shibtarget; +using namespace shibboleth; +using namespace saml; +using namespace std; int main(int argc,char* argv[]) { @@ -67,13 +69,13 @@ int main(int argc,char* argv[]) a_param="default"; ShibTargetConfig& conf=ShibTargetConfig::getConfig(); - conf.setFeatures( - ShibTargetConfig::Metadata | - ShibTargetConfig::Trust | - ShibTargetConfig::Credentials | - ShibTargetConfig::AAP | - ShibTargetConfig::OutOfProcess | - ShibTargetConfig::Caching + SPConfig::getConfig().setFeatures( + SPConfig::Metadata | + SPConfig::Trust | + SPConfig::Credentials | + SPConfig::AAP | + SPConfig::OutOfProcess | + SPConfig::Caching ); if (!conf.init(path) || !conf.load(config)) return -10; diff --git a/xmlproviders/CredResolvers.cpp b/xmlproviders/CredResolvers.cpp index cd1f099..89608d9 100644 --- a/xmlproviders/CredResolvers.cpp +++ b/xmlproviders/CredResolvers.cpp @@ -327,7 +327,7 @@ FileResolver::FileResolver(const DOMElement* e) FileResolver::~FileResolver() { for_each(m_certs.begin(),m_certs.end(),X509_free); - for_each(m_xseccerts.begin(),m_xseccerts.end(),shibtarget::cleanup()); + for_each(m_xseccerts.begin(),m_xseccerts.end(),xmltooling::cleanup()); } void FileResolver::attach(void* ctx) const diff --git a/xmlproviders/XMLAAP.cpp b/xmlproviders/XMLAAP.cpp index a656355..b7c1b93 100644 --- a/xmlproviders/XMLAAP.cpp +++ b/xmlproviders/XMLAAP.cpp @@ -216,9 +216,9 @@ void XMLAAPImpl::init() XMLAAPImpl::~XMLAAPImpl() { #ifdef HAVE_GOOD_STL - for_each(m_attrMap.begin(),m_attrMap.end(),shibtarget::cleanup_pair()); + for_each(m_attrMap.begin(),m_attrMap.end(),xmltooling::cleanup_pair()); #else - for_each(m_attrMap.begin(),m_attrMap.end(),shibtarget::cleanup_pair()); + for_each(m_attrMap.begin(),m_attrMap.end(),xmltooling::cleanup_pair()); #endif } diff --git a/xmlproviders/XMLAccessControl.cpp b/xmlproviders/XMLAccessControl.cpp index 6e451bf..04b466a 100644 --- a/xmlproviders/XMLAccessControl.cpp +++ b/xmlproviders/XMLAccessControl.cpp @@ -212,7 +212,7 @@ Operator::Operator(const DOMElement* e) Operator::~Operator() { - for_each(m_operands.begin(),m_operands.end(),shibtarget::cleanup()); + for_each(m_operands.begin(),m_operands.end(),xmltooling::cleanup()); } bool Operator::authorized(ShibTarget* st, ISessionCacheEntry* entry) const diff --git a/xmlproviders/XMLCredentials.cpp b/xmlproviders/XMLCredentials.cpp index ed91254..7b5ac5f 100644 --- a/xmlproviders/XMLCredentials.cpp +++ b/xmlproviders/XMLCredentials.cpp @@ -146,7 +146,7 @@ void XMLCredentialsImpl::init() XMLCredentialsImpl::~XMLCredentialsImpl() { - for_each(m_resolverMap.begin(),m_resolverMap.end(),shibtarget::cleanup_pair()); + for_each(m_resolverMap.begin(),m_resolverMap.end(),xmltooling::cleanup_pair()); } const ICredResolver* XMLCredentials::lookup(const char* id) const diff --git a/xmlproviders/XMLMetadata.cpp b/xmlproviders/XMLMetadata.cpp index 23afb62..9016456 100644 --- a/xmlproviders/XMLMetadata.cpp +++ b/xmlproviders/XMLMetadata.cpp @@ -598,7 +598,7 @@ XMLMetadataImpl::KeyDescriptor::KeyDescriptor(const DOMElement* e) : m_root(e), XMLMetadataImpl::KeyDescriptor::~KeyDescriptor() { - for_each(m_methods.begin(),m_methods.end(),shibtarget::cleanup()); + for_each(m_methods.begin(),m_methods.end(),xmltooling::cleanup()); delete m_klist; } @@ -643,7 +643,7 @@ XMLMetadataImpl::KeyAuthority::KeyAuthority(const DOMElement* e) : m_depth(1) XMLMetadataImpl::KeyAuthority::~KeyAuthority() { - for_each(m_klists.begin(),m_klists.end(),shibtarget::cleanup()); + for_each(m_klists.begin(),m_klists.end(),xmltooling::cleanup()); } XMLMetadataImpl::Role::Role(const EntityDescriptor* provider, time_t validUntil, const DOMElement* e) @@ -696,8 +696,8 @@ XMLMetadataImpl::Role::~Role() delete m_org; delete m_errorURL; if (m_protocolEnumCopy) XMLString::release(&m_protocolEnumCopy); - for_each(m_keys.begin(),m_keys.end(),shibtarget::cleanup()); - for_each(m_contacts.begin(),m_contacts.end(),shibtarget::cleanup()); + for_each(m_keys.begin(),m_keys.end(),xmltooling::cleanup()); + for_each(m_contacts.begin(),m_contacts.end(),xmltooling::cleanup()); } bool XMLMetadataImpl::Role::hasSupport(const XMLCh* protocol) const @@ -827,7 +827,7 @@ XMLMetadataImpl::IDPRole::IDPRole(const EntityDescriptor* provider, time_t valid XMLMetadataImpl::IDPRole::~IDPRole() { - for_each(m_attrs.begin(),m_attrs.end(),shibtarget::cleanup()); + for_each(m_attrs.begin(),m_attrs.end(),xmltooling::cleanup()); } XMLMetadataImpl::AARole::AARole(const EntityDescriptor* provider, time_t validUntil, const DOMElement* e) @@ -911,7 +911,7 @@ XMLMetadataImpl::AARole::AARole(const EntityDescriptor* provider, time_t validUn XMLMetadataImpl::AARole::~AARole() { - for_each(m_attrs.begin(),m_attrs.end(),shibtarget::cleanup()); + for_each(m_attrs.begin(),m_attrs.end(),xmltooling::cleanup()); } XMLMetadataImpl::EntityDescriptor::EntityDescriptor( @@ -1053,9 +1053,9 @@ const IAttributeAuthorityDescriptor* XMLMetadataImpl::EntityDescriptor::getAttri XMLMetadataImpl::EntityDescriptor::~EntityDescriptor() { delete m_org; - for_each(m_contacts.begin(),m_contacts.end(),shibtarget::cleanup()); - for_each(m_roles.begin(),m_roles.end(),shibtarget::cleanup()); - for_each(m_keyauths.begin(),m_keyauths.end(),shibtarget::cleanup()); + for_each(m_contacts.begin(),m_contacts.end(),xmltooling::cleanup()); + for_each(m_roles.begin(),m_roles.end(),xmltooling::cleanup()); + for_each(m_keyauths.begin(),m_keyauths.end(),xmltooling::cleanup()); } XMLMetadataImpl::EntitiesDescriptor::EntitiesDescriptor( @@ -1114,9 +1114,9 @@ XMLMetadataImpl::EntitiesDescriptor::EntitiesDescriptor( XMLMetadataImpl::EntitiesDescriptor::~EntitiesDescriptor() { - for_each(m_providers.begin(),m_providers.end(),shibtarget::cleanup()); - for_each(m_groups.begin(),m_groups.end(),shibtarget::cleanup()); - for_each(m_keyauths.begin(),m_keyauths.end(),shibtarget::cleanup()); + for_each(m_providers.begin(),m_providers.end(),xmltooling::cleanup()); + for_each(m_groups.begin(),m_groups.end(),xmltooling::cleanup()); + for_each(m_keyauths.begin(),m_keyauths.end(),xmltooling::cleanup()); } void XMLMetadataImpl::init() diff --git a/xmlproviders/XMLTrust.cpp b/xmlproviders/XMLTrust.cpp index 63a36c2..ef697da 100644 --- a/xmlproviders/XMLTrust.cpp +++ b/xmlproviders/XMLTrust.cpp @@ -344,8 +344,8 @@ void XMLTrustImpl::init() XMLTrustImpl::~XMLTrustImpl() { - for_each(m_keyauths.begin(),m_keyauths.end(),shibtarget::cleanup()); - for_each(m_keybinds.begin(),m_keybinds.end(),shibtarget::cleanup()); + for_each(m_keyauths.begin(),m_keyauths.end(),xmltooling::cleanup()); + for_each(m_keybinds.begin(),m_keybinds.end(),xmltooling::cleanup()); } XMLTrust::XMLTrust(const DOMElement* e) : ReloadableXMLFile(e), m_delegate(NULL) @@ -401,7 +401,7 @@ XMLTrust::XMLTrust(const DOMElement* e) : ReloadableXMLFile(e), m_delegate(NULL) XMLTrust::~XMLTrust() { delete m_delegate; - for_each(m_resolvers.begin(),m_resolvers.end(),shibtarget::cleanup()); + for_each(m_resolvers.begin(),m_resolvers.end(),xmltooling::cleanup()); } static int error_callback(int ok, X509_STORE_CTX* ctx) -- 2.1.4