Reducing header overuse, non-inlining selected methods (CPPOST-35).
[shibboleth/cpp-opensaml.git] / saml / binding / impl / SOAPClient.cpp
index feff377..ac29569 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2007 Internet2
+ *  Copyright 2001-2009 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
 #include "internal.h"
 #include "exceptions.h"
 #include "version.h"
+#include "binding/SecurityPolicy.h"
 #include "binding/SOAPClient.h"
 #include "saml2/metadata/Metadata.h"
 #include "saml2/metadata/MetadataProvider.h"
@@ -37,22 +38,34 @@ using namespace opensaml;
 using namespace xmltooling;
 using namespace std;
 
-void SOAPClient::send(const soap11::Envelope& env, MetadataCredentialCriteria& peer, const char* endpoint)
+SOAPClient::SOAPClient(SecurityPolicy& policy)
+    : soap11::SOAPClient(policy.getValidating()), m_policy(policy), m_force(true), m_peer(NULL), m_criteria(NULL)
+{
+}
+
+void SOAPClient::send(const soap11::Envelope& env, const char* from, MetadataCredentialCriteria& to, const char* endpoint)
 {
     // Clear policy.
     m_policy.reset();
 
-    m_criteria = &peer;
-    m_peer = &(peer.getRole());
+    m_criteria = &to;
+    m_peer = &(to.getRole());
     
-    const QName& role = m_peer->getElementQName();
+    const xmltooling::QName& role = m_peer->getElementQName();
     if (XMLString::equals(role.getLocalPart(),RoleDescriptor::LOCAL_NAME))
         m_policy.setRole(m_peer->getSchemaType());
     else
         m_policy.setRole(&role);
 
-    auto_ptr_char pn(dynamic_cast<const EntityDescriptor*>(m_peer->getParent())->getEntityID());
-    soap11::SOAPClient::send(env, pn.get(), endpoint);
+    // Establish the "expected" issuer identity.
+    const XMLCh* entityID = dynamic_cast<const EntityDescriptor*>(m_peer->getParent())->getEntityID();
+    m_policy.setIssuer(entityID);
+    if (!m_policy.getIssuerMetadata())
+        m_policy.setIssuerMetadata(m_peer);
+
+    // Call the base class.
+    auto_ptr_char pn(entityID);
+    soap11::SOAPClient::send(env, SOAPTransport::Address(from, pn.get(), endpoint));
 }
 
 void SOAPClient::prepareTransport(xmltooling::SOAPTransport& transport)
@@ -76,12 +89,12 @@ soap11::Envelope* SOAPClient::receive()
 {
     auto_ptr<soap11::Envelope> env(soap11::SOAPClient::receive());
     if (env.get()) {
-        if (m_peer && m_transport->isSecure()) {
-            // Set issuer based on peer identity.
-            m_policy.setIssuer(dynamic_cast<EntityDescriptor*>(m_peer->getParent())->getEntityID());
-            m_policy.setIssuerMetadata(m_peer);
-            m_policy.setSecure(true);
+        if (m_peer && m_transport->isAuthenticated()) {
+            // Set flag based on peer identity.
+            m_policy.setAuthenticated(true);
         }
+
+        // Run policy against SOAP layer.
         m_policy.evaluate(*(env.get()));
     }
     return env.release();