Collapse unneeded header files.
[shibboleth/cpp-opensaml.git] / saml / saml2 / binding / impl / SAML2MessageRule.cpp
index fe604c2..c9bb283 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2006 Internet2
+ *  Copyright 2001-2007 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 /**
- * SAML1MessageRule.cpp
+ * SAML2MessageRule.cpp
  * 
- * SAML 1.x message extraction rule
+ * SAML 2.0 message extraction rule
  */
 
 #include "internal.h"
 #include "exceptions.h"
-#include "saml2/binding/SAML2MessageRule.h"
+#include "binding/SecurityPolicyRule.h"
 #include "saml2/core/Protocols.h"
 #include "saml2/metadata/Metadata.h"
 #include "saml2/metadata/MetadataProvider.h"
@@ -39,6 +39,15 @@ using namespace log4cpp;
 using namespace std;
 
 namespace opensaml {
+    class SAML_DLLLOCAL SAML2MessageRule : public SecurityPolicyRule
+    {
+    public:
+        SAML2MessageRule(const DOMElement* e) {}
+        virtual ~SAML2MessageRule() {}
+        
+        void evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
+    };
+
     SecurityPolicyRule* SAML_DLLLOCAL SAML2MessageRuleFactory(const DOMElement* const & e)
     {
         return new SAML2MessageRule(e);
@@ -52,27 +61,26 @@ void SAML2MessageRule::evaluate(const XMLObject& message, const GenericRequest*
     const QName& q = message.getElementQName(); 
     policy.setMessageQName(&q);
     
+    if (!XMLString::equals(q.getNamespaceURI(), samlconstants::SAML20P_NS)) {
+        log.debug("not a SAML 2.0 protocol message");
+        return;
+    }
+
     try {
-        const opensaml::RootObject& samlRoot = dynamic_cast<const opensaml::RootObject&>(message);
+        const saml2::RootObject& samlRoot = dynamic_cast<const saml2::RootObject&>(message);
         policy.setMessageID(samlRoot.getID());
         policy.setIssueInstant(samlRoot.getIssueInstantEpoch());
 
-        if (!XMLString::equals(q.getNamespaceURI(), samlconstants::SAML20P_NS)) {
-            log.warn("not a SAML 2.0 protocol message");
-            throw BindingException("Message was not a recognized SAML 2.0 protocol element.");
-        }
-
         log.debug("extracting issuer from message");
-        const saml2::RootObject& saml2Root = dynamic_cast<const saml2::RootObject&>(samlRoot);
-        Issuer* issuer = saml2Root.getIssuer();
+        Issuer* issuer = samlRoot.getIssuer();
         if (issuer && issuer->getName()) {
             auto_ptr<Issuer> copy(issuer->cloneIssuer());
             policy.setIssuer(copy.get());
             copy.release();
         }
-        else {
+        else if (XMLString::equals(q.getLocalPart(), Response::LOCAL_NAME)) {
             // No issuer in the message, so we have to try the Response approach. 
-            const vector<Assertion*>& assertions = dynamic_cast<const Response&>(saml2Root).getAssertions();
+            const vector<saml2::Assertion*>& assertions = dynamic_cast<const Response&>(samlRoot).getAssertions();
             if (!assertions.empty()) {
                 issuer = assertions.front()->getIssuer();
                 if (issuer && issuer->getName()) {