Major revamp of credential and trust handling code, PKIX engine still needs work.
[shibboleth/cpp-opensaml.git] / saml / saml2 / binding / impl / SAML2SOAPEncoder.cpp
index 7c407d9..43ec706 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.
@@ -23,7 +23,7 @@
 #include "internal.h"
 #include "exceptions.h"
 #include "binding/HTTPResponse.h"
-#include "saml2/binding/SAML2SOAPEncoder.h"
+#include "binding/MessageEncoder.h"
 #include "saml2/core/Protocols.h"
 
 #include <sstream>
@@ -41,6 +41,23 @@ using namespace std;
 
 namespace opensaml {
     namespace saml2p {              
+        class SAML_DLLLOCAL SAML2SOAPEncoder : public MessageEncoder
+        {
+        public:
+            SAML2SOAPEncoder(const DOMElement* e);
+            virtual ~SAML2SOAPEncoder() {}
+            
+            long encode(
+                GenericResponse& genericResponse,
+                XMLObject* xmlObject,
+                const char* destination,
+                const char* recipientID=NULL,
+                const char* relayState=NULL,
+                const Credential* credential=NULL,
+                const XMLCh* sigAlgorithm=NULL
+                ) const;
+        };
+
         MessageEncoder* SAML_DLLLOCAL SAML2SOAPEncoderFactory(const DOMElement* const & e)
         {
             return new SAML2SOAPEncoder(e);
@@ -56,14 +73,14 @@ long SAML2SOAPEncoder::encode(
     const char* destination,
     const char* recipientID,
     const char* relayState,
-    const CredentialResolver* credResolver,
+    const Credential* credential,
     const XMLCh* sigAlgorithm
     ) const
 {
 #ifdef _DEBUG
     xmltooling::NDC ndc("encode");
 #endif
-    Category& log = Category::getInstance(SAML_LOGCAT".MessageEncoder.SAML1SOAP");
+    Category& log = Category::getInstance(SAML_LOGCAT".MessageEncoder.SAML2SOAP");
 
     log.debug("validating input");
     if (xmlObject->getParent())
@@ -72,8 +89,8 @@ long SAML2SOAPEncoder::encode(
     genericResponse.setContentType("text/xml");
     HTTPResponse* httpResponse = dynamic_cast<HTTPResponse*>(&genericResponse);
     if (httpResponse) {
-        httpResponse->setHeader("Cache-Control", "no-cache, no-store, must-revalidate, private");
-        httpResponse->setHeader("Pragma", "no-cache");
+        httpResponse->setResponseHeader("Cache-Control", "no-cache, no-store, must-revalidate, private");
+        httpResponse->setResponseHeader("Pragma", "no-cache");
     }
 
     DOMElement* rootElement = NULL;
@@ -84,7 +101,7 @@ long SAML2SOAPEncoder::encode(
             Body* body = BodyBuilder::buildBody();
             env->setBody(body);
             body->getUnknownXMLObjects().push_back(response);
-            if (credResolver ) {
+            if (credential) {
                 if (response->getSignature()) {
                     log.debug("response already signed, skipping signature operation");
                     rootElement = env->marshall();
@@ -93,12 +110,14 @@ long SAML2SOAPEncoder::encode(
                     log.debug("signing and marshalling the response");
         
                     // Build a Signature.
-                    Signature* sig = buildSignature(credResolver, sigAlgorithm);
-                    response->setSignature(sig);
+                    Signature* sig = SignatureBuilder::buildSignature();
+                    response->setSignature(sig);    
+                    if (sigAlgorithm)
+                        sig->setSignatureAlgorithm(sigAlgorithm);
             
                     // Sign response while marshalling.
                     vector<Signature*> sigs(1,sig);
-                    rootElement = env->marshall((DOMDocument*)NULL,&sigs);
+                    rootElement = env->marshall((DOMDocument*)NULL,&sigs,credential);
                 }
             }
             else {