Convert logging to log4shib via compile time switch.
[shibboleth/opensaml2.git] / saml / saml1 / binding / impl / SAML1MessageRule.cpp
index 397cbde..665b912 100644 (file)
 #include "saml2/metadata/MetadataProvider.h"
 #include "util/SAMLConstants.h"
 
-#include <log4cpp/Category.hh>
+#include <xmltooling/logging.h>
 
 using namespace opensaml::saml2md;
 using namespace opensaml::saml1p;
 using namespace opensaml;
+using namespace xmltooling::logging;
 using namespace xmltooling;
-using namespace log4cpp;
 using namespace std;
 
 namespace opensaml {
@@ -64,11 +64,10 @@ void SAML1MessageRule::evaluate(const XMLObject& message, const GenericRequest*
     const QName& q = message.getElementQName(); 
     policy.setMessageQName(&q);
 
-    if (!XMLString::equals(q.getNamespaceURI(), samlconstants::SAML1P_NS)) {
-        log.debug("not a SAML 1.x protocol message");
+    if (!XMLString::equals(q.getNamespaceURI(), samlconstants::SAML1P_NS) &&
+        !XMLString::equals(q.getNamespaceURI(), samlconstants::SAML1_NS)) {
         return;
     }
-
     
     try {
         const RootObject& samlRoot = dynamic_cast<const RootObject&>(message);
@@ -77,23 +76,26 @@ void SAML1MessageRule::evaluate(const XMLObject& message, const GenericRequest*
 
         log.debug("extracting issuer from message");
 
-        // Only samlp:Response is known to carry issuer (via payload) in standard SAML 1.x.
         const XMLCh* protocol = NULL;
-        if (XMLString::equals(q.getLocalPart(), Response::LOCAL_NAME)) {
+        const saml1::Assertion* a = NULL;
+
+        // Handle assertions directly.
+        if (XMLString::equals(q.getLocalPart(), saml1::Assertion::LOCAL_NAME))
+            a = dynamic_cast<const saml1::Assertion*>(&samlRoot);
+            
+        // Only samlp:Response is known to carry issuer (via payload) in standard SAML 1.x.
+        if (!a && XMLString::equals(q.getLocalPart(), Response::LOCAL_NAME)) {
             // Should be a samlp:Response.
             const vector<saml1::Assertion*>& assertions = dynamic_cast<const saml1p::Response&>(samlRoot).getAssertions();
-            if (!assertions.empty()) {
-                const saml1::Assertion* a = assertions.front();
-                if (a->getIssuer()) {
-                    auto_ptr<saml2::Issuer> issuer(saml2::IssuerBuilder::buildIssuer());
-                    issuer->setName(a->getIssuer());
-                    policy.setIssuer(issuer.get());
-                    issuer.release();   // owned by policy now
-                    pair<bool,int> minor = a->getMinorVersion();
-                    protocol = (minor.first && minor.second==0) ?
-                        samlconstants::SAML10_PROTOCOL_ENUM : samlconstants::SAML11_PROTOCOL_ENUM;
-                }
-            }
+            if (!assertions.empty())
+                a = assertions.front();
+        }
+
+        if (a) {
+            policy.setIssuer(a->getIssuer());
+            pair<bool,int> minor = a->getMinorVersion();
+            protocol = (minor.first && minor.second==0) ?
+                samlconstants::SAML10_PROTOCOL_ENUM : samlconstants::SAML11_PROTOCOL_ENUM;
         }
         
         if (!protocol) {
@@ -102,15 +104,20 @@ void SAML1MessageRule::evaluate(const XMLObject& message, const GenericRequest*
         }
 
         if (log.isDebugEnabled()) {
-            auto_ptr_char iname(policy.getIssuer()->getName());
+            auto_ptr_char iname(a->getIssuer());
             log.debug("message from (%s)", iname.get());
         }
         
+        if (policy.getIssuerMetadata()) {
+            log.debug("metadata for issuer already set, leaving in place");
+            return;
+        }
+        
         if (policy.getMetadataProvider() && policy.getRole()) {
             log.debug("searching metadata for message issuer...");
-            const EntityDescriptor* entity = policy.getMetadataProvider()->getEntityDescriptor(policy.getIssuer()->getName());
+            const EntityDescriptor* entity = policy.getMetadataProvider()->getEntityDescriptor(a->getIssuer());
             if (!entity) {
-                auto_ptr_char temp(policy.getIssuer()->getName());
+                auto_ptr_char temp(a->getIssuer());
                 log.warn("no metadata found, can't establish identity of issuer (%s)", temp.get());
                 return;
             }