Adjust logging categories.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Sun, 25 Nov 2007 22:28:49 +0000 (22:28 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Sun, 25 Nov 2007 22:28:49 +0000 (22:28 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2634 cb58f699-b61c-0410-a6fe-9272a202ed29

apache/mod_apache.cpp
fastcgi/shibauthorizer.cpp
fastcgi/shibresponder.cpp
isapi_shib/isapi_shib.cpp
nsapi_shib/nsapi_shib.cpp
shibsp/AbstractSPRequest.cpp
shibsp/AbstractSPRequest.h
shibsp/ServiceProvider.cpp
shibsp/base.h

index cbd7c2e..421a7ec 100644 (file)
@@ -309,7 +309,7 @@ public:
   shib_server_config* m_sc;
   shib_request_config* m_rc;
 
-  ShibTargetApache(request_rec* req, bool handler) : m_handler(handler), m_gotBody(false) {
+  ShibTargetApache(request_rec* req, bool handler) : AbstractSPRequest(SHIBSP_LOGCAT".Apache"), m_handler(handler), m_gotBody(false) {
     m_sc = (shib_server_config*)ap_get_module_config(req->server->module_config, &mod_shib);
     m_dc = (shib_dir_config*)ap_get_module_config(req->per_dir_config, &mod_shib);
     m_rc = (shib_request_config*)ap_get_module_config(req->request_config, &mod_shib);
index 8fdaf3f..f0fd99e 100644 (file)
@@ -67,7 +67,8 @@ class ShibTargetFCGIAuth : public AbstractSPRequest
 public:\r
     map<string,string> m_request_headers;\r
 \r
-    ShibTargetFCGIAuth(FCGX_Request* req, const char* scheme=NULL, const char* hostname=NULL, int port=0) : m_req(req) {\r
+    ShibTargetFCGIAuth(FCGX_Request* req, const char* scheme=NULL, const char* hostname=NULL, int port=0)\r
+            : AbstractSPRequest(SHIBSP_LOGCAT".FastCGI"), m_req(req) {\r
         const char* server_name_str = hostname;\r
         if (!server_name_str || !*server_name_str)\r
             server_name_str = FCGX_GetParam("SERVER_NAME", req->envp);\r
index 247eb7c..940ebe3 100644 (file)
@@ -68,7 +68,7 @@ class ShibTargetFCGI : public AbstractSPRequest
 \r
 public:\r
     ShibTargetFCGI(FCGX_Request* req, char* post_data, const char* scheme=NULL, const char* hostname=NULL, int port=0)\r
-        : m_req(req), m_body(post_data) {\r
+        : AbstractSPRequest(SHIBSP_LOGCAT".FastCGI"), m_req(req), m_body(post_data) {\r
 \r
         const char* server_name_str = hostname;\r
         if (!server_name_str || !*server_name_str)\r
index f608c72..d286c4b 100644 (file)
@@ -360,7 +360,7 @@ class ShibTargetIsapiF : public AbstractSPRequest
 
 public:
   ShibTargetIsapiF(PHTTP_FILTER_CONTEXT pfc, PHTTP_FILTER_PREPROC_HEADERS pn, const site_t& site)
-      : m_pfc(pfc), m_pn(pn), m_allhttp(4096) {
+      : AbstractSPRequest(SHIBSP_LOGCAT".ISAPI"), m_pfc(pfc), m_pn(pn), m_allhttp(4096) {
 
     // URL path always come from IIS.
     dynabuf var(256);
@@ -640,7 +640,8 @@ class ShibTargetIsapiE : public AbstractSPRequest
   mutable string m_remote_addr,m_remote_user;
   
 public:
-  ShibTargetIsapiE(LPEXTENSION_CONTROL_BLOCK lpECB, const site_t& site) : m_lpECB(lpECB), m_gotBody(false) {
+  ShibTargetIsapiE(LPEXTENSION_CONTROL_BLOCK lpECB, const site_t& site)
+      : AbstractSPRequest(SHIBSP_LOGCAT".ISAPI"), m_lpECB(lpECB), m_gotBody(false) {
     dynabuf ssl(5);
     GetServerVariable(lpECB,"HTTPS",ssl,5);
     bool SSL=(ssl=="on" || ssl=="ON");
index 13497db..b8f88bc 100644 (file)
@@ -192,7 +192,7 @@ class ShibTargetNSAPI : public AbstractSPRequest
   set<string> m_allhttp;
 
 public:
-  ShibTargetNSAPI(pblock* pb, ::Session* sn, Request* rq) : m_gotBody(false) {
+  ShibTargetNSAPI(pblock* pb, ::Session* sn, Request* rq) : AbstractSPRequest(SHIBSP_LOGCAT".NSAPI"), m_gotBody(false) {
     m_pb = pb;
     m_sn = sn;
     m_rq = rq;
index bdceb28..cb2d3eb 100644 (file)
@@ -31,9 +31,9 @@ using namespace opensaml;
 using namespace xmltooling;
 using namespace std;
 
-AbstractSPRequest::AbstractSPRequest()
+AbstractSPRequest::AbstractSPRequest(const char* category)
     : m_sp(NULL), m_mapper(NULL), m_app(NULL), m_sessionTried(false), m_session(NULL),
-        m_log(&Category::getInstance(SHIBSP_LOGCAT".SPRequest")), m_parser(NULL)
+        m_log(&Category::getInstance(category)), m_parser(NULL)
 {
     m_sp=SPConfig::getConfig().getServiceProvider();
     m_sp->lock();
index f1b64b1..7b710b0 100644 (file)
@@ -40,7 +40,12 @@ namespace shibsp {
     class SHIBSP_API AbstractSPRequest : public virtual SPRequest
     {
     protected:
-        AbstractSPRequest();
+        /**
+         * Constructor.
+         *
+         * @param category  logging category to use
+         */
+        AbstractSPRequest(const char* category);
         
         /**
          * Stores a normalized request URI to ensure it contains no %-encoded characters
index e441e3c..18b43f1 100644 (file)
 #include <xmltooling/util/XMLHelper.h>
 
 using namespace shibsp;
+using namespace xmltooling::logging;
 using namespace xmltooling;
 using namespace std;
 
 namespace shibsp {
     SHIBSP_DLLLOCAL PluginManager<ServiceProvider,string,const DOMElement*>::Factory XMLServiceProviderFactory;
 
-    long SHIBSP_DLLLOCAL sendError(SPRequest& request, const Application* app, const char* page, TemplateParameters& tp, bool mayRedirect=true)
+    long SHIBSP_DLLLOCAL sendError(
+        Category& log, SPRequest& request, const Application* app, const char* page, TemplateParameters& tp, bool mayRedirect=true
+        )
     {
         // The properties we need can be set in the RequestMap, or the Errors element.
         bool mderror = dynamic_cast<const opensaml::saml2md::MetadataException*>(tp.getRichException())!=NULL;
@@ -66,7 +69,7 @@ namespace shibsp {
                 redirectErrors = settings.first->getString("redirectErrors");
         }
         catch (exception& ex) {
-            request.log(SPRequest::SPError, ex.what());
+            log.error(ex.what());
         }
 
         if (mayRedirect) {
@@ -105,8 +108,7 @@ namespace shibsp {
             return request.sendResponse(msg, HTTPResponse::XMLTOOLING_HTTP_STATUS_UNAUTHORIZED);
         }
     
-        string errstr = string("sendError could not process error template (") + page + ")";
-        request.log(SPRequest::SPError, errstr);
+        log.error("sendError could not process error template (%s)", page);
         istringstream msg("Internal Server Error. Please contact the site administrator.");
         return request.sendError(msg);
     }
@@ -135,6 +137,7 @@ pair<bool,long> ServiceProvider::doAuthentication(SPRequest& request, bool handl
 #ifdef _DEBUG
     xmltooling::NDC ndc("doAuthentication");
 #endif
+    Category& log = Category::getInstance(SHIBSP_LOGCAT".ServiceProvider");
 
     const Application* app=NULL;
     string targetURL = request.getRequestURL();
@@ -163,7 +166,7 @@ pair<bool,long> ServiceProvider::doAuthentication(SPRequest& request, bool handl
                 else {
                     TemplateParameters tp;
                     tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
-                    return make_pair(true,sendError(request, app, "ssl", tp, false));
+                    return make_pair(true,sendError(log, request, app, "ssl", tp, false));
                 }
             }
         }
@@ -205,7 +208,7 @@ pair<bool,long> ServiceProvider::doAuthentication(SPRequest& request, bool handl
             session = request.getSession();
         }
         catch (exception& e) {
-            request.log(SPRequest::SPWarn, string("error during session lookup: ") + e.what());
+            log.warn("error during session lookup: %s", e.what());
             // If it's not a retryable session failure, we throw to the outer handler for reporting.
             if (dynamic_cast<opensaml::RetryableProfileException*>(&e)==NULL)
                 throw;
@@ -220,11 +223,11 @@ pair<bool,long> ServiceProvider::doAuthentication(SPRequest& request, bool handl
             const Handler* initiator=NULL;
             if (requireSessionWith.first) {
                 initiator=app->getSessionInitiatorById(requireSessionWith.second);
-                if (!initiator)
+                if (!initiator) {
                     throw ConfigurationException(
-                        "No session initiator found with id ($1), check requireSessionWith command.",
-                        params(1,requireSessionWith.second)
+                        "No session initiator found with id ($1), check requireSessionWith command.", params(1,requireSessionWith.second)
                         );
+                }
             }
             else {
                 initiator=app->getDefaultSessionInitiator();
@@ -237,13 +240,13 @@ pair<bool,long> ServiceProvider::doAuthentication(SPRequest& request, bool handl
 
         // We're done.  Everything is okay.  Nothing to report.  Nothing to do..
         // Let the caller decide how to proceed.
-        request.log(SPRequest::SPDebug, "doAuthentication succeeded");
+        log.debug("doAuthentication succeeded");
         return make_pair(false,0L);
     }
     catch (exception& e) {
         TemplateParameters tp(&e);
         tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
-        return make_pair(true,sendError(request, app, "session", tp));
+        return make_pair(true,sendError(log, request, app, "session", tp));
     }
 }
 
@@ -252,6 +255,7 @@ pair<bool,long> ServiceProvider::doAuthorization(SPRequest& request) const
 #ifdef _DEBUG
     xmltooling::NDC ndc("doAuthorization");
 #endif
+    Category& log = Category::getInstance(SHIBSP_LOGCAT".ServiceProvider");
 
     const Application* app=NULL;
     string targetURL = request.getRequestURL();
@@ -283,21 +287,21 @@ pair<bool,long> ServiceProvider::doAuthorization(SPRequest& request) const
                 session = request.getSession(false);
             }
             catch (exception& e) {
-                request.log(SPRequest::SPWarn, string("unable to obtain session to pass to access control provider: ") + e.what());
+                log.warn("unable to obtain session to pass to access control provider: %s", e.what());
             }
        
             Locker acllock(settings.second);
             switch (settings.second->authorized(request,session)) {
                 case AccessControl::shib_acl_true:
-                    request.log(SPRequest::SPDebug, "access control provider granted access");
+                    log.debug("access control provider granted access");
                     return make_pair(true,request.returnOK());
 
                 case AccessControl::shib_acl_false:
                 {
-                    request.log(SPRequest::SPWarn, "access control provider denied access");
+                    log.warn("access control provider denied access");
                     TemplateParameters tp;
                     tp.m_map["requestURL"] = targetURL;
-                    return make_pair(true,sendError(request, app, "access", tp, false));
+                    return make_pair(true,sendError(log, request, app, "access", tp, false));
                 }
 
                 default:
@@ -312,7 +316,7 @@ pair<bool,long> ServiceProvider::doAuthorization(SPRequest& request) const
     catch (exception& e) {
         TemplateParameters tp(&e);
         tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
-        return make_pair(true,sendError(request, app, "access", tp));
+        return make_pair(true,sendError(log, request, app, "access", tp));
     }
 }
 
@@ -321,6 +325,7 @@ pair<bool,long> ServiceProvider::doExport(SPRequest& request, bool requireSessio
 #ifdef _DEBUG
     xmltooling::NDC ndc("doExport");
 #endif
+    Category& log = Category::getInstance(SHIBSP_LOGCAT".ServiceProvider");
 
     const Application* app=NULL;
     string targetURL = request.getRequestURL();
@@ -334,7 +339,7 @@ pair<bool,long> ServiceProvider::doExport(SPRequest& request, bool requireSessio
             session = request.getSession(false);
         }
         catch (exception& e) {
-            request.log(SPRequest::SPWarn, string("unable to obtain session to export to request: ") +  e.what());
+            log.warn("unable to obtain session to export to request: %s", e.what());
                // If we have to have a session, then this is a fatal error.
                if (requireSession)
                        throw;
@@ -373,7 +378,7 @@ pair<bool,long> ServiceProvider::doExport(SPRequest& request, bool requireSessio
             const PropertySet* sessions=app->getPropertySet("Sessions");
             pair<bool,const char*> exportLocation = sessions ? sessions->getString("exportLocation") : pair<bool,const char*>(false,NULL);
             if (!exportLocation.first)
-                request.log(SPRequest::SPWarn, "can't export assertions without an exportLocation Sessions property");
+                log.warn("can't export assertions without an exportLocation Sessions property");
             else {
                 const URLEncoder* encoder = XMLToolingConfig::getConfig().getURLEncoder();
                 string exportName = "Shib-Assertion-00";
@@ -434,7 +439,7 @@ pair<bool,long> ServiceProvider::doExport(SPRequest& request, bool requireSessio
     catch (exception& e) {
         TemplateParameters tp(&e);
         tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
-        return make_pair(true,sendError(request, app, "session", tp));
+        return make_pair(true,sendError(log, request, app, "session", tp));
     }
 }
 
@@ -443,6 +448,7 @@ pair<bool,long> ServiceProvider::doHandler(SPRequest& request) const
 #ifdef _DEBUG
     xmltooling::NDC ndc("doHandler");
 #endif
+    Category& log = Category::getInstance(SHIBSP_LOGCAT".ServiceProvider");
 
     const Application* app=NULL;
     string targetURL = request.getRequestURL();
@@ -487,6 +493,6 @@ pair<bool,long> ServiceProvider::doHandler(SPRequest& request) const
     catch (exception& e) {
         TemplateParameters tp(&e);
         tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
-        return make_pair(true,sendError(request, app, "session", tp));
+        return make_pair(true,sendError(log, request, app, "session", tp));
     }
 }
index 00ecd2d..648fce4 100644 (file)
@@ -91,7 +91,7 @@
 /**
  * Logging category for Service Provider functions.
  */
-#define SHIBSP_LOGCAT "Shibboleth.SP"
+#define SHIBSP_LOGCAT "Shibboleth"
 
 /**
  * Logging category for Service Provider auditing.