Add method to read all properties.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Fri, 19 Oct 2007 02:28:55 +0000 (02:28 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Fri, 19 Oct 2007 02:28:55 +0000 (02:28 +0000)
Strip down RequestMap to HTTPRequest interface.
Remove unneeded inheritance code in RequestMap.

git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2540 cb58f699-b61c-0410-a6fe-9272a202ed29

apache/mod_apache.cpp
nsapi_shib/nsapi_shib.cpp
shibsp/RequestMapper.h
shibsp/impl/XMLRequestMapper.cpp
shibsp/impl/XMLServiceProvider.cpp
shibsp/util/DOMPropertySet.cpp
shibsp/util/DOMPropertySet.h
shibsp/util/PropertySet.h

index ef42915..2be0df1 100644 (file)
@@ -681,7 +681,7 @@ public:
     ~ApacheRequestMapper() { delete m_mapper; delete m_htaccess; delete m_staKey; delete m_propsKey; }
     Lockable* lock() { return m_mapper->lock(); }
     void unlock() { m_staKey->setData(NULL); m_propsKey->setData(NULL); m_mapper->unlock(); }
-    Settings getSettings(const SPRequest& request) const;
+    Settings getSettings(const HTTPRequest& request) const;
     
     const PropertySet* getParent() const { return NULL; }
     void setParent(const PropertySet*) {}
@@ -690,6 +690,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;
+    void getAll(map<string,const char*>& properties) const;
     const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:2.0:native:sp:config") const;
     const xercesc::DOMElement* getElement() const;
 
@@ -713,7 +714,7 @@ ApacheRequestMapper::ApacheRequestMapper(const xercesc::DOMElement* e) : m_mappe
     m_propsKey=ThreadKey::create(NULL);
 }
 
-RequestMapper::Settings ApacheRequestMapper::getSettings(const SPRequest& request) const
+RequestMapper::Settings ApacheRequestMapper::getSettings(const HTTPRequest& request) const
 {
     Settings s=m_mapper->getSettings(request);
     m_staKey->setData((void*)dynamic_cast<const ShibTargetApache*>(&request));
@@ -810,6 +811,34 @@ pair<bool,int> ApacheRequestMapper::getInt(const char* name, const char* ns) con
     return s ? s->getInt(name,ns) : pair<bool,int>(false,0);
 }
 
+void ApacheRequestMapper::getAll(map<string,const char*>& properties) const
+{
+    const ShibTargetApache* sta=reinterpret_cast<const ShibTargetApache*>(m_staKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
+
+    if (s)
+        s->getAll(properties);
+
+    const char* auth_type=ap_auth_type(sta->m_req);
+    if (auth_type) {
+        // Check for Basic Hijack
+        if (!strcasecmp(auth_type, "basic") && sta->m_dc->bBasicHijack == 1)
+            auth_type = "shibboleth";
+        properties["authType"] = auth_type;
+    }
+
+    if (sta->m_dc->szApplicationId)
+        properties["applicationId"] = sta->m_dc->szApplicationId;
+    if (sta->m_dc->szRequireWith)
+        properties["requireSessionWith"] = sta->m_dc->szRequireWith;
+    if (sta->m_dc->szRedirectToSSL)
+        properties["redirectToSSL"] = sta->m_dc->szRedirectToSSL;
+    if (sta->m_dc->bRequireSession != 0)
+        properties["requireSession"] = (sta->m_dc->bRequireSession==1) ? "true" : "false";
+    if (sta->m_dc->bExportAssertion != 0)
+        properties["exportAssertion"] = (sta->m_dc->bExportAssertion==1) ? "true" : "false";
+}
+
 const PropertySet* ApacheRequestMapper::getPropertySet(const char* name, const char* ns) const
 {
     const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
index 100da45..6c8618e 100644 (file)
@@ -462,7 +462,7 @@ public:
     ~SunRequestMapper() { delete m_mapper; delete m_stKey; delete m_propsKey; }
     Lockable* lock() { return m_mapper->lock(); }
     void unlock() { m_stKey->setData(NULL); m_propsKey->setData(NULL); m_mapper->unlock(); }
-    Settings getSettings(const SPRequest& request) const;
+    Settings getSettings(const HTTPRequest& request) const;
     
     const PropertySet* getParent() const { return NULL; }
     void setParent(const PropertySet*) {}
@@ -471,6 +471,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;
+    void getAll(map<string,const char*>& properties) const;
     const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:2.0:native:sp:config") const;
     const xercesc::DOMElement* getElement() const;
 
@@ -492,7 +493,7 @@ SunRequestMapper::SunRequestMapper(const xercesc::DOMElement* e) : m_mapper(NULL
     m_propsKey=ThreadKey::create(NULL);
 }
 
-RequestMapper::Settings SunRequestMapper::getSettings(const SPRequest& request) const
+RequestMapper::Settings SunRequestMapper::getSettings(const HTTPRequest& request) const
 {
     Settings s=m_mapper->getSettings(request);
     m_stKey->setData((void*)dynamic_cast<const ShibTargetNSAPI*>(&request));
@@ -562,6 +563,23 @@ pair<bool,int> SunRequestMapper::getInt(const char* name, const char* ns) const
     return s ? s->getInt(name,ns) : pair<bool,int>(false,0);
 }
 
+void SunRequestMapper::getAll(map<string,const char*>& properties) const
+{
+    const ShibTargetNSAPI* stn=reinterpret_cast<const ShibTargetNSAPI*>(m_stKey->getData());
+    const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
+    if (s)
+        s->getAll(properties);
+    properties["authType"] = "shibboleth";
+    const pb_entry* entry;
+    for (int i=0; i<stn->m_pb->hsize; ++i) {
+        entry = stn->m_pb->ht[i];
+        while (entry) {
+            properties[entry->param->name] = entry->param->value;
+            entry = entry->next;
+        }
+    }
+}
+
 const PropertySet* SunRequestMapper::getPropertySet(const char* name, const char* ns) const
 {
     const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
index e3bae59..646cbdd 100644 (file)
 
 #include <shibsp/base.h>
 #include <xmltooling/Lockable.h>
+#include <xmltooling/io/HTTPRequest.h>
 
 namespace shibsp {
 
     class SHIBSP_API AccessControl;
     class SHIBSP_API PropertySet;
-    class SHIBSP_API SPRequest;
 
     /**
      * Interface to a request mapping plugin
@@ -55,7 +55,7 @@ namespace shibsp {
          * @param request   SP request
          * @return configuration settings and effective AccessControl plugin, if any
          */        
-        virtual Settings getSettings(const SPRequest& request) const=0;
+        virtual Settings getSettings(const xmltooling::HTTPRequest& request) const=0;
     };
 
     /**
index 62da247..1f2174b 100644 (file)
@@ -57,25 +57,17 @@ namespace shibsp {
     class Override : public DOMPropertySet, public DOMNodeFilter\r
     {\r
     public:\r
-        Override() : m_base(NULL), m_acl(NULL) {}\r
+        Override() : m_acl(NULL) {}\r
         Override(const DOMElement* e, Category& log, const Override* base=NULL);\r
         ~Override();\r
 \r
-        // PropertySet\r
-        pair<bool,bool> getBool(const char* name, const char* ns=NULL) const;\r
-        pair<bool,const char*> getString(const char* name, const char* ns=NULL) const;\r
-        pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const;\r
-        pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const;\r
-        pair<bool,int> getInt(const char* name, const char* ns=NULL) const;\r
-        const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:2.0:native:sp:config") const;\r
-        \r
         // Provides filter to exclude special config elements.\r
         short acceptNode(const DOMNode* node) const {\r
             return FILTER_REJECT;\r
         }\r
 \r
-        const Override* locate(const SPRequest& request) const;\r
-        AccessControl* getAC() const { return (m_acl ? m_acl : (m_base ? m_base->getAC() : NULL)); }\r
+        const Override* locate(const HTTPRequest& request) const;\r
+        AccessControl* getAC() const { return (m_acl ? m_acl : (getParent() ? dynamic_cast<const Override*>(getParent())->getAC() : NULL)); }\r
         \r
     protected:\r
         void loadACL(const DOMElement* e, Category& log);\r
@@ -85,7 +77,6 @@ namespace shibsp {
         vector< pair< pair<string,RegularExpression*>,Override*> > m_queries;\r
     \r
     private:\r
-        const Override* m_base;\r
         AccessControl* m_acl;\r
     };\r
 \r
@@ -103,7 +94,7 @@ namespace shibsp {
             m_document = doc;\r
         }\r
     \r
-        const Override* findOverride(const char* vhost, const SPRequest& request) const;\r
+        const Override* findOverride(const char* vhost, const HTTPRequest& request) const;\r
 \r
     private:    \r
         map<string,Override*> m_extras;\r
@@ -126,7 +117,7 @@ namespace shibsp {
             delete m_impl;\r
         }\r
 \r
-        Settings getSettings(const SPRequest& request) const;\r
+        Settings getSettings(const HTTPRequest& request) const;\r
 \r
     protected:\r
         pair<bool,DOMElement*> load();\r
@@ -196,11 +187,12 @@ void Override::loadACL(const DOMElement* e, Category& log)
     }\r
 }\r
 \r
-Override::Override(const DOMElement* e, Category& log, const Override* base) : m_base(base), m_acl(NULL)\r
+Override::Override(const DOMElement* e, Category& log, const Override* base) : m_acl(NULL)\r
 {\r
     try {\r
         // Load the property set.\r
         load(e,log,this);\r
+        setParent(base);\r
         \r
         // Load any AccessControl provider.\r
         loadACL(e,log);\r
@@ -358,55 +350,7 @@ Override::~Override()
     }\r
 }\r
 \r
-pair<bool,bool> Override::getBool(const char* name, const char* ns) const\r
-{\r
-    pair<bool,bool> ret=DOMPropertySet::getBool(name,ns);\r
-    if (ret.first)\r
-        return ret;\r
-    return m_base ? m_base->getBool(name,ns) : ret;\r
-}\r
-\r
-pair<bool,const char*> Override::getString(const char* name, const char* ns) const\r
-{\r
-    pair<bool,const char*> ret=DOMPropertySet::getString(name,ns);\r
-    if (ret.first)\r
-        return ret;\r
-    return m_base ? m_base->getString(name,ns) : ret;\r
-}\r
-\r
-pair<bool,const XMLCh*> Override::getXMLString(const char* name, const char* ns) const\r
-{\r
-    pair<bool,const XMLCh*> ret=DOMPropertySet::getXMLString(name,ns);\r
-    if (ret.first)\r
-        return ret;\r
-    return m_base ? m_base->getXMLString(name,ns) : ret;\r
-}\r
-\r
-pair<bool,unsigned int> Override::getUnsignedInt(const char* name, const char* ns) const\r
-{\r
-    pair<bool,unsigned int> ret=DOMPropertySet::getUnsignedInt(name,ns);\r
-    if (ret.first)\r
-        return ret;\r
-    return m_base ? m_base->getUnsignedInt(name,ns) : ret;\r
-}\r
-\r
-pair<bool,int> Override::getInt(const char* name, const char* ns) const\r
-{\r
-    pair<bool,int> ret=DOMPropertySet::getInt(name,ns);\r
-    if (ret.first)\r
-        return ret;\r
-    return m_base ? m_base->getInt(name,ns) : ret;\r
-}\r
-\r
-const PropertySet* Override::getPropertySet(const char* name, const char* ns) const\r
-{\r
-    const PropertySet* ret=DOMPropertySet::getPropertySet(name,ns);\r
-    if (ret || !m_base)\r
-        return ret;\r
-    return m_base->getPropertySet(name,ns);\r
-}\r
-\r
-const Override* Override::locate(const SPRequest& request) const\r
+const Override* Override::locate(const HTTPRequest& request) const\r
 {\r
     // This function is confusing because it's *not* recursive.\r
     // The whole path is tokenized and mapped in a loop, so the\r
@@ -651,7 +595,7 @@ XMLRequestMapperImpl::XMLRequestMapperImpl(const DOMElement* e, Category& log) :
     }\r
 }\r
 \r
-const Override* XMLRequestMapperImpl::findOverride(const char* vhost, const SPRequest& request) const\r
+const Override* XMLRequestMapperImpl::findOverride(const char* vhost, const HTTPRequest& request) const\r
 {\r
     const Override* o=NULL;\r
     map<string,Override*>::const_iterator i=m_map.find(vhost);\r
@@ -691,7 +635,7 @@ pair<bool,DOMElement*> XMLRequestMapper::load()
     return make_pair(false,(DOMElement*)NULL);\r
 }\r
 \r
-RequestMapper::Settings XMLRequestMapper::getSettings(const SPRequest& request) const\r
+RequestMapper::Settings XMLRequestMapper::getSettings(const HTTPRequest& request) const\r
 {\r
     ostringstream vhost;\r
     vhost << request.getScheme() << "://" << request.getHostname() << ':' << request.getPort();\r
index 0694abf..36f1f89 100644 (file)
@@ -282,6 +282,7 @@ namespace {
         pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const {return m_impl->getXMLString(name,ns);}
         pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const {return m_impl->getUnsignedInt(name,ns);}
         pair<bool,int> getInt(const char* name, const char* ns=NULL) const {return m_impl->getInt(name,ns);}
+        void getAll(map<string,const char*>& properties) const {return m_impl->getAll(properties);}
         const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:2.0:native:sp:config") const {return m_impl->getPropertySet(name,ns);}
         const DOMElement* getElement() const {return m_impl->getElement();}
 
index a4096c8..05f2ee0 100644 (file)
@@ -207,6 +207,14 @@ pair<bool,int> DOMPropertySet::getInt(const char* name, const char* ns) const
     return pair<bool,int>(false,0);
 }
 
+void DOMPropertySet::getAll(std::map<std::string,const char*>& properties) const
+{
+    if (m_parent)
+        m_parent->getAll(properties);
+    for (map< string,pair<char*,const XMLCh*> >::const_iterator i = m_map.begin(); i != m_map.end(); ++i)
+        properties[i->first] = i->second.first;
+}
+
 const PropertySet* DOMPropertySet::getPropertySet(const char* name, const char* ns) const
 {
     map<string,DOMPropertySet*>::const_iterator i;
index b94a703..ca9cfbb 100644 (file)
@@ -51,6 +51,7 @@ namespace shibsp {
         std::pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const;
         std::pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const;
         std::pair<bool,int> getInt(const char* name, const char* ns=NULL) const;
+        void getAll(std::map<std::string,const char*>& properties) const;
         const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:2.0:native:sp:config") const;
 
         const xercesc::DOMElement* getElement() const {
index eb0f242..7313c4a 100644 (file)
@@ -24,6 +24,7 @@
 #define __shibsp_propset_h__
 
 #include <shibsp/base.h>
+#include <map>
 #include <xercesc/dom/DOM.hpp>
 
 namespace shibsp {
@@ -99,6 +100,13 @@ namespace shibsp {
         virtual std::pair<bool,int> getInt(const char* name, const char* ns=NULL) const=0;
 
         /**
+         * Returns a map of all known properties in string form.
+         *
+         * @param properties    map to populate
+         */
+        virtual void getAll(std::map<std::string,const char*>& properties) const=0;
+
+        /**
          * Returns a nested property set.
          * 
          * @param name  nested property set name