Inject logging category into base class.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Fri, 13 Apr 2007 01:18:44 +0000 (01:18 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Fri, 13 Apr 2007 01:18:44 +0000 (01:18 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2220 cb58f699-b61c-0410-a6fe-9272a202ed29

shibsp/attribute/resolver/impl/SimpleAttributeResolver.cpp
shibsp/impl/XMLAccessControl.cpp
shibsp/impl/XMLRequestMapper.cpp
shibsp/impl/XMLServiceProvider.cpp

index 4424921..6cae72c 100644 (file)
@@ -30,8 +30,6 @@
 #include "binding/SOAPClient.h"\r
 #include "util/SPConstants.h"\r
 \r
-\r
-#include <log4cpp/Category.hh>\r
 #include <saml/binding/SecurityPolicy.h>\r
 #include <saml/saml1/binding/SAML1SOAPClient.h>\r
 #include <saml/saml1/core/Assertions.h>\r
@@ -139,7 +137,7 @@ namespace shibsp {
     class SimpleResolverImpl\r
     {\r
     public:\r
-        SimpleResolverImpl(const DOMElement* e);\r
+        SimpleResolverImpl(const DOMElement* e, Category& log);\r
         ~SimpleResolverImpl() {\r
             for_each(m_decoderMap.begin(), m_decoderMap.end(), cleanup_pair<string,AttributeDecoder>());\r
             if (m_document)\r
@@ -169,6 +167,7 @@ namespace shibsp {
         void populateQuery(saml1p::AttributeQuery& query, const string& id) const;\r
         void populateQuery(saml2p::AttributeQuery& query, const string& id) const;\r
 \r
+        Category& m_log;\r
         DOMDocument* m_document;\r
         map<string,AttributeDecoder*> m_decoderMap;\r
 #ifdef HAVE_GOOD_STL\r
@@ -182,7 +181,7 @@ namespace shibsp {
     class SimpleResolver : public AttributeResolver, public ReloadableXMLFile\r
     {\r
     public:\r
-        SimpleResolver(const DOMElement* e) : ReloadableXMLFile(e), m_impl(NULL) {\r
+        SimpleResolver(const DOMElement* e) : ReloadableXMLFile(e, Category::getInstance(SHIBSP_LOGCAT".AttributeResolver")), m_impl(NULL) {\r
             load();\r
         }\r
         ~SimpleResolver() {\r
@@ -234,19 +233,18 @@ namespace shibsp {
     static const XMLCh _type[] =                UNICODE_LITERAL_4(t,y,p,e);\r
 };\r
 \r
-SimpleResolverImpl::SimpleResolverImpl(const DOMElement* e) : m_document(NULL), m_allowQuery(true)\r
+SimpleResolverImpl::SimpleResolverImpl(const DOMElement* e, Category& log) : m_log(log), m_document(NULL), m_allowQuery(true)\r
 {\r
 #ifdef _DEBUG\r
     xmltooling::NDC ndc("SimpleResolverImpl");\r
 #endif\r
-    Category& log=Category::getInstance(SHIBSP_LOGCAT".AttributeResolver");\r
     \r
     if (!XMLHelper::isNodeNamed(e, SIMPLE_NS, _AttributeResolver))\r
         throw ConfigurationException("Simple resolver requires resolver:AttributeResolver at root of configuration.");\r
     \r
     const XMLCh* flag = e->getAttributeNS(NULL,allowQuery);\r
     if (flag && (*flag==chLatin_f || *flag==chDigit_0)) {\r
-        log.info("SAML attribute queries disabled");\r
+        m_log.info("SAML attribute queries disabled");\r
         m_allowQuery = false;\r
     }\r
 \r
@@ -255,11 +253,11 @@ SimpleResolverImpl::SimpleResolverImpl(const DOMElement* e) : m_document(NULL),
         auto_ptr_char id(child->getAttributeNS(NULL, _id));\r
         auto_ptr_char type(child->getAttributeNS(NULL, _type));\r
         try {\r
-            log.info("building AttributeDecoder (%s) of type %s", id.get(), type.get());\r
+            m_log.info("building AttributeDecoder (%s) of type %s", id.get(), type.get());\r
             m_decoderMap[id.get()] = SPConfig::getConfig().AttributeDecoderManager.newPlugin(type.get(), child);\r
         }\r
         catch (exception& ex) {\r
-            log.error("error building AttributeDecoder (%s): %s", id.get(), ex.what());\r
+            m_log.error("error building AttributeDecoder (%s): %s", id.get(), ex.what());\r
         }\r
         child = XMLHelper::getNextSiblingElement(child, SIMPLE_NS, _AttributeDecoder);\r
     }\r
@@ -269,7 +267,7 @@ SimpleResolverImpl::SimpleResolverImpl(const DOMElement* e) : m_document(NULL),
         // Check for missing Name.\r
         const XMLCh* name = child->getAttributeNS(NULL, saml2::Attribute::NAME_ATTRIB_NAME);\r
         if (!name || !*name) {\r
-            log.warn("skipping saml:Attribute declared with no Name");\r
+            m_log.warn("skipping saml:Attribute declared with no Name");\r
             child = XMLHelper::getNextSiblingElement(child, samlconstants::SAML20_NS, saml2::Attribute::LOCAL_NAME);\r
             continue;\r
         }\r
@@ -278,7 +276,7 @@ SimpleResolverImpl::SimpleResolverImpl(const DOMElement* e) : m_document(NULL),
         auto_ptr_char id(child->getAttributeNS(NULL, saml2::Attribute::FRIENDLYNAME_ATTRIB_NAME));\r
         auto_ptr_char d(child->getAttributeNS(SIMPLE_NS, decoderId));\r
         if (!id.get() || !*id.get() || !d.get() || !*d.get() || !(decoder=m_decoderMap[d.get()])) {\r
-            log.warn("skipping saml:Attribute declared with no FriendlyName or resolvable AttributeDecoder");\r
+            m_log.warn("skipping saml:Attribute declared with no FriendlyName or resolvable AttributeDecoder");\r
             child = XMLHelper::getNextSiblingElement(child, samlconstants::SAML20_NS, saml2::Attribute::LOCAL_NAME);\r
             continue;\r
         }\r
@@ -298,17 +296,17 @@ SimpleResolverImpl::SimpleResolverImpl(const DOMElement* e) : m_document(NULL),
         pair<const AttributeDecoder*,string>& decl = m_attrMap[make_pair(n.get(),f.get())];\r
 #endif\r
         if (decl.first) {\r
-            log.warn("skipping duplicate saml:Attribute declaration (same Name and NameFormat)");\r
+            m_log.warn("skipping duplicate saml:Attribute declaration (same Name and NameFormat)");\r
             child = XMLHelper::getNextSiblingElement(child, samlconstants::SAML20_NS, saml2::Attribute::LOCAL_NAME);\r
             continue;\r
         }\r
 \r
-        if (log.isInfoEnabled()) {\r
+        if (m_log.isInfoEnabled()) {\r
 #ifdef HAVE_GOOD_STL\r
             auto_ptr_char n(name);\r
             auto_ptr_char f(format);\r
 #endif\r
-            log.info("creating declaration for Attribute %s%s%s", n.get(), *f.get() ? ", Format/Namespace:" : "", f.get());\r
+            m_log.info("creating declaration for Attribute %s%s%s", n.get(), *f.get() ? ", Format/Namespace:" : "", f.get());\r
         }\r
         \r
         decl.first = decoder;\r
@@ -500,11 +498,10 @@ void SimpleResolverImpl::query(ResolutionContext& ctx, const NameIdentifier& nam
 #ifdef _DEBUG\r
     xmltooling::NDC ndc("query");\r
 #endif\r
-    Category& log=Category::getInstance(SHIBSP_LOGCAT".AttributeResolver");\r
 \r
     const EntityDescriptor* entity = ctx.getEntityDescriptor();\r
     if (!entity) {\r
-        log.debug("no issuer information available, skipping query");\r
+        m_log.debug("no issuer information available, skipping query");\r
         return;\r
     }\r
 \r
@@ -515,7 +512,7 @@ void SimpleResolverImpl::query(ResolutionContext& ctx, const NameIdentifier& nam
         version = 0;\r
     }\r
     if (!AA) {\r
-        log.info("no SAML 1.x AttributeAuthority role found in metadata");\r
+        m_log.info("no SAML 1.x AttributeAuthority role found in metadata");\r
         return;\r
     }\r
 \r
@@ -552,25 +549,25 @@ void SimpleResolverImpl::query(ResolutionContext& ctx, const NameIdentifier& nam
             response = client.receiveSAML();\r
         }\r
         catch (exception& ex) {\r
-            log.error("exception making SAML query: %s", ex.what());\r
+            m_log.error("exception making SAML query: %s", ex.what());\r
             soaper.reset();\r
         }\r
     }\r
 \r
     if (!response) {\r
-        log.error("unable to successfully query for attributes");\r
+        m_log.error("unable to successfully query for attributes");\r
         return;\r
     }\r
 \r
     const vector<saml1::Assertion*>& assertions = const_cast<const saml1p::Response*>(response)->getAssertions();\r
     if (assertions.size()>1)\r
-        log.warn("simple resolver only supports one assertion in the query response");\r
+        m_log.warn("simple resolver only supports one assertion in the query response");\r
 \r
     auto_ptr<saml1p::Response> wrapper(response);\r
     saml1::Assertion* newtoken = assertions.front();\r
 \r
     if (!newtoken->getSignature() && signedAssertions.first && signedAssertions.second) {\r
-        log.error("assertion unsigned, rejecting it based on signedAssertions policy");\r
+        m_log.error("assertion unsigned, rejecting it based on signedAssertions policy");\r
         return;\r
     }\r
 \r
@@ -582,7 +579,7 @@ void SimpleResolverImpl::query(ResolutionContext& ctx, const NameIdentifier& nam
         tokval.validateAssertion(*newtoken);\r
     }\r
     catch (exception& ex) {\r
-        log.error("assertion failed policy/validation: %s", ex.what());\r
+        m_log.error("assertion failed policy/validation: %s", ex.what());\r
     }\r
     newtoken->detach();\r
     wrapper.release();\r
@@ -618,16 +615,15 @@ void SimpleResolverImpl::query(ResolutionContext& ctx, const NameID& nameid, con
 #ifdef _DEBUG\r
     xmltooling::NDC ndc("query");\r
 #endif\r
-    Category& log=Category::getInstance(SHIBSP_LOGCAT".AttributeResolver");\r
 \r
     const EntityDescriptor* entity = ctx.getEntityDescriptor();\r
     if (!entity) {\r
-        log.debug("no issuer information available, skipping query");\r
+        m_log.debug("no issuer information available, skipping query");\r
         return;\r
     }\r
     const AttributeAuthorityDescriptor* AA = entity->getAttributeAuthorityDescriptor(samlconstants::SAML20P_NS);\r
     if (!AA) {\r
-        log.info("no SAML 2 AttributeAuthority role found in metadata");\r
+        m_log.info("no SAML 2 AttributeAuthority role found in metadata");\r
         return;\r
     }\r
 \r
@@ -663,31 +659,31 @@ void SimpleResolverImpl::query(ResolutionContext& ctx, const NameID& nameid, con
             srt = client.receiveSAML();\r
         }\r
         catch (exception& ex) {\r
-            log.error("exception making SAML query: %s", ex.what());\r
+            m_log.error("exception making SAML query: %s", ex.what());\r
             soaper.reset();\r
         }\r
     }\r
 \r
     if (!srt) {\r
-        log.error("unable to successfully query for attributes");\r
+        m_log.error("unable to successfully query for attributes");\r
         return;\r
     }\r
     saml2p::Response* response = dynamic_cast<saml2p::Response*>(srt);\r
     if (!response) {\r
         delete srt;\r
-        log.error("message was not a samlp:Response");\r
+        m_log.error("message was not a samlp:Response");\r
         return;\r
     }\r
 \r
     const vector<saml2::Assertion*>& assertions = const_cast<const saml2p::Response*>(response)->getAssertions();\r
     if (assertions.size()>1)\r
-        log.warn("simple resolver only supports one assertion in the query response");\r
+        m_log.warn("simple resolver only supports one assertion in the query response");\r
 \r
     auto_ptr<saml2p::Response> wrapper(response);\r
     saml2::Assertion* newtoken = assertions.front();\r
 \r
     if (!newtoken->getSignature() && signedAssertions.first && signedAssertions.second) {\r
-        log.error("assertion unsigned, rejecting it based on signedAssertions policy");\r
+        m_log.error("assertion unsigned, rejecting it based on signedAssertions policy");\r
         return;\r
     }\r
 \r
@@ -699,7 +695,7 @@ void SimpleResolverImpl::query(ResolutionContext& ctx, const NameID& nameid, con
         tokval.validateAssertion(*newtoken);\r
     }\r
     catch (exception& ex) {\r
-        log.error("assertion failed policy/validation: %s", ex.what());\r
+        m_log.error("assertion failed policy/validation: %s", ex.what());\r
     }\r
     newtoken->detach();\r
     wrapper.release();\r
@@ -735,9 +731,8 @@ void SimpleResolver::resolveAttributes(ResolutionContext& ctx, const set<string>
 #ifdef _DEBUG\r
     xmltooling::NDC ndc("resolveAttributes");\r
 #endif\r
-    Category& log=Category::getInstance(SHIBSP_LOGCAT".AttributeResolver");\r
     \r
-    log.debug("examining tokens to resolve");\r
+    m_log.debug("examining tokens to resolve");\r
 \r
     bool query = m_impl->m_allowQuery;\r
     const saml1::Assertion* token1;\r
@@ -746,14 +741,14 @@ void SimpleResolver::resolveAttributes(ResolutionContext& ctx, const set<string>
         for (vector<const opensaml::Assertion*>::const_iterator t = ctx.getTokens()->begin(); t!=ctx.getTokens()->end(); ++t) {\r
             token2 = dynamic_cast<const saml2::Assertion*>(*t);\r
             if (token2 && !token2->getAttributeStatements().empty()) {\r
-                log.debug("resolving SAML 2 token with an AttributeStatement");\r
+                m_log.debug("resolving SAML 2 token with an AttributeStatement");\r
                 m_impl->resolve(ctx, token2, attributes);\r
                 query = false;\r
             }\r
             else {\r
                 token1 = dynamic_cast<const saml1::Assertion*>(*t);\r
                 if (token1 && !token1->getAttributeStatements().empty()) {\r
-                    log.debug("resolving SAML 1 token with an AttributeStatement");\r
+                    m_log.debug("resolving SAML 1 token with an AttributeStatement");\r
                     m_impl->resolve(ctx, token1, attributes);\r
                     query = false;\r
                 }\r
@@ -765,15 +760,15 @@ void SimpleResolver::resolveAttributes(ResolutionContext& ctx, const set<string>
         if (token1 && !token1->getAuthenticationStatements().empty()) {\r
             const AuthenticationStatement* statement = token1->getAuthenticationStatements().front();\r
             if (statement && statement->getSubject() && statement->getSubject()->getNameIdentifier()) {\r
-                log.debug("attempting SAML 1.x attribute query");\r
+                m_log.debug("attempting SAML 1.x attribute query");\r
                 return m_impl->query(ctx, *(statement->getSubject()->getNameIdentifier()), attributes);\r
             }\r
         }\r
         else if (token2 && ctx.getNameID()) {\r
-            log.debug("attempting SAML 2.0 attribute query");\r
+            m_log.debug("attempting SAML 2.0 attribute query");\r
             return m_impl->query(ctx, *ctx.getNameID(), attributes);\r
         }\r
-        log.warn("can't attempt attribute query, no identifier in assertion subject");\r
+        m_log.warn("can't attempt attribute query, no identifier in assertion subject");\r
     }\r
 }\r
 \r
@@ -785,7 +780,7 @@ pair<bool,DOMElement*> SimpleResolver::load()
     // If we own it, wrap it.\r
     XercesJanitor<DOMDocument> docjanitor(raw.first ? raw.second->getOwnerDocument() : NULL);\r
 \r
-    SimpleResolverImpl* impl = new SimpleResolverImpl(raw.second);\r
+    SimpleResolverImpl* impl = new SimpleResolverImpl(raw.second, m_log);\r
     \r
     // If we held the document, transfer it to the impl. If we didn't, it's a no-op.\r
     impl->setDocument(docjanitor.release());\r
index 68a9a1d..97222be 100644 (file)
@@ -81,7 +81,8 @@ namespace {
     class XMLAccessControl : public AccessControl, public ReloadableXMLFile\r
     {\r
     public:\r
-        XMLAccessControl(const DOMElement* e) : ReloadableXMLFile(e), m_rootAuthz(NULL) {\r
+        XMLAccessControl(const DOMElement* e)\r
+                : ReloadableXMLFile(e, log4cpp::Category::getInstance(SHIBSP_LOGCAT".AccessControl")), m_rootAuthz(NULL) {\r
             load(); // guarantees an exception or the policy is loaded\r
         }\r
         \r
index 66fd87c..14d0a5d 100644 (file)
@@ -113,8 +113,7 @@ namespace shibsp {
     class XMLRequestMapper : public RequestMapper, public ReloadableXMLFile\r
     {\r
     public:\r
-        XMLRequestMapper(const DOMElement* e)\r
-                : ReloadableXMLFile(e), m_impl(NULL), m_log(Category::getInstance(SHIBSP_LOGCAT".RequestMapper")) {\r
+        XMLRequestMapper(const DOMElement* e) : ReloadableXMLFile(e,Category::getInstance(SHIBSP_LOGCAT".RequestMapper")), m_impl(NULL) {\r
             load();\r
         }\r
 \r
@@ -129,7 +128,6 @@ namespace shibsp {
 \r
     private:\r
         XMLRequestMapperImpl* m_impl;\r
-        Category& m_log;\r
     };\r
 \r
 #if defined (_MSC_VER)\r
index bdf5045..aba398c 100644 (file)
@@ -163,7 +163,7 @@ namespace {
     class SHIBSP_DLLLOCAL XMLConfigImpl : public DOMPropertySet, public DOMNodeFilter\r
     {\r
     public:\r
-        XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer);\r
+        XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer, Category& log);\r
         ~XMLConfigImpl();\r
         \r
         RequestMapper* m_requestMapper;\r
@@ -187,8 +187,8 @@ namespace {
     class SHIBSP_DLLLOCAL XMLConfig : public ServiceProvider, public ReloadableXMLFile\r
     {\r
     public:\r
-        XMLConfig(const DOMElement* e)\r
-            : ReloadableXMLFile(e), m_impl(NULL), m_listener(NULL), m_sessionCache(NULL), m_tranLog(NULL) {\r
+        XMLConfig(const DOMElement* e) : ReloadableXMLFile(e, Category::getInstance(SHIBSP_LOGCAT".Config")),\r
+            m_impl(NULL), m_listener(NULL), m_sessionCache(NULL), m_tranLog(NULL) {\r
         }\r
         \r
         void init() {\r
@@ -758,12 +758,12 @@ void XMLConfigImpl::doExtensions(const DOMElement* e, const char* label, Categor
     }\r
 }\r
 \r
-XMLConfigImpl::XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer) : m_requestMapper(NULL), m_outer(outer), m_document(NULL)\r
+XMLConfigImpl::XMLConfigImpl(const DOMElement* e, bool first, const XMLConfig* outer, Category& log)\r
+    : m_requestMapper(NULL), m_outer(outer), m_document(NULL)\r
 {\r
 #ifdef _DEBUG\r
     xmltooling::NDC ndc("XMLConfigImpl");\r
 #endif\r
-    Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");\r
 \r
     try {\r
         SPConfig& conf=SPConfig::getConfig();\r
@@ -1028,7 +1028,7 @@ pair<bool,DOMElement*> XMLConfig::load()
     // If we own it, wrap it.\r
     XercesJanitor<DOMDocument> docjanitor(raw.first ? raw.second->getOwnerDocument() : NULL);\r
 \r
-    XMLConfigImpl* impl = new XMLConfigImpl(raw.second,(m_impl==NULL),this);\r
+    XMLConfigImpl* impl = new XMLConfigImpl(raw.second,(m_impl==NULL),this,m_log);\r
     \r
     // If we held the document, transfer it to the impl. If we didn't, it's a no-op.\r
     impl->setDocument(docjanitor.release());\r