Set policy role based on peer entity.
[shibboleth/opensaml2.git] / saml / binding / impl / SOAPClient.cpp
index 15aaa82..84fa0ee 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.
@@ -37,13 +37,19 @@ using namespace opensaml;
 using namespace xmltooling;
 using namespace std;
 
-void SOAPClient::send(const soap11::Envelope* env, const KeyInfoSource& peer, const char* endpoint)
+void SOAPClient::send(const soap11::Envelope& env, const KeyInfoSource& peer, const char* endpoint)
 {
     // Clear policy.
-    m_policy.setIssuer(NULL);
-    m_policy.setIssuerMetadata(NULL);
+    m_policy.reset();
     
     m_peer = dynamic_cast<const RoleDescriptor*>(&peer);
+    if (m_peer) {
+        const QName& role = m_peer->getElementQName();
+        if (XMLString::equals(role.getLocalPart(),RoleDescriptor::LOCAL_NAME))
+            m_policy.setRole(m_peer->getSchemaType());
+        else
+            m_policy.setRole(&role);
+    }
     
     soap11::SOAPClient::send(env, peer, endpoint);
 }
@@ -78,9 +84,18 @@ soap11::Envelope* SOAPClient::receive()
                 issuer->setName(parent->getEntityID());
                 m_policy.setIssuer(issuer);
                 m_policy.setIssuerMetadata(m_peer);
+                m_policy.setSecure(true);
             }
         }
         m_policy.evaluate(*(env.get()));
     }
     return env.release();
 }
+
+void SOAPClient::reset()
+{
+    soap11::SOAPClient::reset();
+    m_policy.reset();
+    XMLString::release(&m_correlate);
+    m_correlate=NULL;
+}