Next integration phase, metadata and trust conversion.
[shibboleth/cpp-sp.git] / apache / mod_apache.cpp
index dbeb11b..7bf01d2 100644 (file)
@@ -31,6 +31,9 @@
 # define _CRT_SECURE_NO_DEPRECATE 1
 #endif
 
+#include <shibsp/exceptions.h>
+#include <shibsp/SPConfig.h>
+
 // SAML Runtime
 #include <saml/saml.h>
 #include <shib/shib.h>
@@ -65,8 +68,8 @@
 #include <unistd.h>            // for getpid()
 #endif
 
+using namespace shibsp;
 using namespace shibtarget;
-using namespace saml;
 using namespace xmltooling;
 using namespace std;
 
@@ -275,11 +278,11 @@ public:
         return m_body.c_str();
     // Read the posted data
     if (ap_setup_client_block(m_req, REQUEST_CHUNKED_ERROR))
-        throw SAMLException("Apache function (setup_client_block) failed while reading POST request body.");
+        throw saml::SAMLException("Apache function (setup_client_block) failed while reading POST request body.");
     if (!ap_should_client_block(m_req))
-        throw SAMLException("Apache function (should_client_block) failed while reading POST request body.");
+        throw saml::SAMLException("Apache function (should_client_block) failed while reading POST request body.");
     if (m_req->remaining > 1024*1024)
-        throw SAMLException("Blocked POST request body larger than size limit.");
+        throw saml::SAMLException("Blocked POST request body larger than size limit.");
     m_gotBody=true;
     char buff[HUGE_STRING_LEN];
     ap_hard_timeout("[mod_shib] getRequestBody", m_req);
@@ -313,7 +316,7 @@ public:
     const string& msg,
     int code=200,
     const string& content_type="text/html",
-       const Iterator<header_t>& headers=EMPTY(header_t)
+    const saml::Iterator<header_t>& headers=EMPTY(header_t)
     ) {
     m_req->content_type = ap_psprintf(m_req->pool, content_type.c_str());
     while (headers.hasNext()) {
@@ -362,7 +365,7 @@ extern "C" int shib_check_user(request_rec* r)
     // export happened successfully..  this user is ok.
     return OK;
   }
-  catch (SAMLException& e) {
+  catch (saml::SAMLException& e) {
     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_check_user threw an exception: %s", e.what());
     return SERVER_ERROR;
   }
@@ -407,7 +410,7 @@ extern "C" int shib_handler(request_rec* r)
     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "doHandler() did not do anything.");
     return SERVER_ERROR;
   }
-  catch (SAMLException& e) {
+  catch (saml::SAMLException& e) {
     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_handler threw an exception: %s", e.what());
     return SERVER_ERROR;
   }
@@ -444,7 +447,7 @@ extern "C" int shib_auth_checker(request_rec* r)
     // We're all okay.
     return OK;
   }
-  catch (SAMLException& e) {
+  catch (saml::SAMLException& e) {
     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_auth_checker threw an exception: %s", e.what());
     return SERVER_ERROR;
   }
@@ -470,12 +473,12 @@ public:
     ) const;
 };
 
-IPlugIn* htAccessFactory(const DOMElement* e)
+saml::IPlugIn* htAccessFactory(const DOMElement* e)
 {
     return new htAccessControl();
 }
 
-class ApacheRequestMapper : public virtual IRequestMapper, public virtual IPropertySet
+class ApacheRequestMapper : public virtual IRequestMapper, public virtual PropertySet
 {
 public:
     ApacheRequestMapper(const DOMElement* e);
@@ -489,7 +492,7 @@ public:
     pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const;
     pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const;
     pair<bool,int> getInt(const char* name, const char* ns=NULL) const;
-    const IPropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const;
+    const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const;
     const DOMElement* getElement() const;
 
 private:
@@ -499,18 +502,18 @@ private:
     IAccessControl* m_htaccess;
 };
 
-IPlugIn* ApacheRequestMapFactory(const DOMElement* e)
+saml::IPlugIn* ApacheRequestMapFactory(const DOMElement* e)
 {
     return new ApacheRequestMapper(e);
 }
 
 ApacheRequestMapper::ApacheRequestMapper(const DOMElement* e) : m_mapper(NULL), m_staKey(NULL), m_propsKey(NULL), m_htaccess(NULL)
 {
-    IPlugIn* p=SAMLConfig::getConfig().getPlugMgr().newPlugin(shibtarget::XML::XMLRequestMapType,e);
+    saml::IPlugIn* p=saml::SAMLConfig::getConfig().getPlugMgr().newPlugin(shibtarget::XML::XMLRequestMapType,e);
     m_mapper=dynamic_cast<IRequestMapper*>(p);
     if (!m_mapper) {
         delete p;
-        throw UnsupportedExtensionException("Embedded request mapper plugin was not of correct type.");
+        throw saml::UnsupportedExtensionException("Embedded request mapper plugin was not of correct type.");
     }
     m_htaccess=new htAccessControl();
     m_staKey=ThreadKey::create(NULL);
@@ -522,13 +525,13 @@ IRequestMapper::Settings ApacheRequestMapper::getSettings(ShibTarget* st) const
     Settings s=m_mapper->getSettings(st);
     m_staKey->setData(dynamic_cast<ShibTargetApache*>(st));
     m_propsKey->setData((void*)s.first);
-    return pair<const IPropertySet*,IAccessControl*>(this,s.second ? s.second : m_htaccess);
+    return pair<const PropertySet*,IAccessControl*>(this,s.second ? s.second : m_htaccess);
 }
 
 pair<bool,bool> ApacheRequestMapper::getBool(const char* name, const char* ns) const
 {
     ShibTargetApache* sta=reinterpret_cast<ShibTargetApache*>(m_staKey->getData());
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
     if (sta && !ns) {
         // Override Apache-settable boolean properties.
         if (name && !strcmp(name,"requireSession") && sta->m_dc->bRequireSession==1)
@@ -542,7 +545,7 @@ pair<bool,bool> ApacheRequestMapper::getBool(const char* name, const char* ns) c
 pair<bool,const char*> ApacheRequestMapper::getString(const char* name, const char* ns) const
 {
     ShibTargetApache* sta=reinterpret_cast<ShibTargetApache*>(m_staKey->getData());
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
     if (sta && !ns) {
         // Override Apache-settable string properties.
         if (name && !strcmp(name,"authType")) {
@@ -566,14 +569,14 @@ pair<bool,const char*> ApacheRequestMapper::getString(const char* name, const ch
 
 pair<bool,const XMLCh*> ApacheRequestMapper::getXMLString(const char* name, const char* ns) const
 {
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
     return s ? s->getXMLString(name,ns) : pair<bool,const XMLCh*>(false,NULL);
 }
 
 pair<bool,unsigned int> ApacheRequestMapper::getUnsignedInt(const char* name, const char* ns) const
 {
     ShibTargetApache* sta=reinterpret_cast<ShibTargetApache*>(m_staKey->getData());
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
     if (sta && !ns) {
         // Override Apache-settable int properties.
         if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
@@ -585,7 +588,7 @@ pair<bool,unsigned int> ApacheRequestMapper::getUnsignedInt(const char* name, co
 pair<bool,int> ApacheRequestMapper::getInt(const char* name, const char* ns) const
 {
     ShibTargetApache* sta=reinterpret_cast<ShibTargetApache*>(m_staKey->getData());
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
     if (sta && !ns) {
         // Override Apache-settable int properties.
         if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
@@ -594,15 +597,15 @@ pair<bool,int> ApacheRequestMapper::getInt(const char* name, const char* ns) con
     return s ? s->getInt(name,ns) : pair<bool,int>(false,0);
 }
 
-const IPropertySet* ApacheRequestMapper::getPropertySet(const char* name, const char* ns) const
+const PropertySet* ApacheRequestMapper::getPropertySet(const char* name, const char* ns) const
 {
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
     return s ? s->getPropertySet(name,ns) : NULL;
 }
 
 const DOMElement* ApacheRequestMapper::getElement() const
 {
-    const IPropertySet* s=reinterpret_cast<const IPropertySet*>(m_propsKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
     return s ? s->getElement() : NULL;
 }
 
@@ -761,7 +764,7 @@ bool htAccessControl::authorized(
             }
         }
         else {
-            Iterator<shibboleth::IAAP*> provs=st->getApplication()->getAAPProviders();
+            saml::Iterator<shibboleth::IAAP*> provs=st->getApplication()->getAAPProviders();
             shibboleth::AAP wrapper(provs,w);
             if (wrapper.fail()) {
                 st->log(ShibTarget::LogLevelWarn, string("htAccessControl plugin didn't recognize require rule: ") + w);
@@ -797,7 +800,7 @@ bool htAccessControl::authorized(
                             if (i == 0) {
                                 st->log(ShibTarget::LogLevelError, string("htAccessControl plugin found invalid header encoding (") +
                                     vals + "): starts with a semicolon");
-                                throw SAMLException("Invalid information supplied to authorization plugin.");
+                                throw saml::SAMLException("Invalid information supplied to authorization plugin.");
                             }
 
                             if (vals_str.at(i-1) == '\\') {
@@ -929,23 +932,23 @@ 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");
             exit(1);
         }
-        SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::htAccessControlType,&htAccessFactory);
-        SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::NativeRequestMapType,&ApacheRequestMapFactory);
+        saml::SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::htAccessControlType,&htAccessFactory);
+        saml::SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::NativeRequestMapType,&ApacheRequestMapFactory);
         // We hijack the legacy type so that 1.2 config files will load this plugin
-        SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::LegacyRequestMapType,&ApacheRequestMapFactory);
+        saml::SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::LegacyRequestMapType,&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");
@@ -953,8 +956,8 @@ extern "C" void shib_child_init(apr_pool_t* p, server_rec* s)
         }
 
         IConfig* conf=g_Config->getINI();
-        Locker locker(conf);
-        const IPropertySet* props=conf->getPropertySet("Local");
+        saml::Locker locker(conf);
+        const PropertySet* props=conf->getPropertySet("Local");
         if (props) {
             pair<bool,const char*> unsetValue=props->getString("unsetHeaderValue");
             if (unsetValue.first)