Convert logging to log4shib via compile time switch.
[shibboleth/opensaml2.git] / saml / saml2 / binding / impl / SAML2SOAPEncoder.cpp
index 7a5bfef..9eaac3f 100644 (file)
 
 #include "internal.h"
 #include "exceptions.h"
-#include "binding/HTTPResponse.h"
 #include "binding/MessageEncoder.h"
+#include "signature/ContentReference.h"
 #include "saml2/core/Protocols.h"
 
 #include <sstream>
-#include <log4cpp/Category.hh>
+#include <xmltooling/logging.h>
+#include <xmltooling/io/HTTPResponse.h>
 #include <xmltooling/util/NDC.h>
 #include <xmltooling/soap/SOAP.h>
 
 using namespace opensaml::saml2p;
+using namespace opensaml::saml2md;
 using namespace opensaml;
 using namespace xmlsignature;
 using namespace soap11;
+using namespace xmltooling::logging;
 using namespace xmltooling;
-using namespace log4cpp;
 using namespace std;
 
 namespace opensaml {
@@ -44,37 +46,43 @@ namespace opensaml {
         class SAML_DLLLOCAL SAML2SOAPEncoder : public MessageEncoder
         {
         public:
-            SAML2SOAPEncoder(const DOMElement* e);
+            SAML2SOAPEncoder() {}
             virtual ~SAML2SOAPEncoder() {}
-            
+
+            bool isUserAgentPresent() const {
+                return false;
+            }
+
             long encode(
                 GenericResponse& genericResponse,
-                xmltooling::XMLObject* xmlObject,
+                XMLObject* xmlObject,
                 const char* destination,
-                const char* recipientID=NULL,
+                const EntityDescriptor* recipient=NULL,
                 const char* relayState=NULL,
-                const xmltooling::CredentialResolver* credResolver=NULL,
-                const XMLCh* sigAlgorithm=NULL
+                const ArtifactGenerator* artifactGenerator=NULL,
+                const Credential* credential=NULL,
+                const XMLCh* signatureAlg=NULL,
+                const XMLCh* digestAlg=NULL
                 ) const;
         };
 
-        MessageEncoder* SAML_DLLLOCAL SAML2SOAPEncoderFactory(const DOMElement* const & e)
+        MessageEncoder* SAML_DLLLOCAL SAML2SOAPEncoderFactory(const pair<const DOMElement*,const XMLCh*>& p)
         {
-            return new SAML2SOAPEncoder(e);
+            return new SAML2SOAPEncoder();
         }
     };
 };
 
-SAML2SOAPEncoder::SAML2SOAPEncoder(const DOMElement* e) {}
-
 long SAML2SOAPEncoder::encode(
     GenericResponse& genericResponse,
     XMLObject* xmlObject,
     const char* destination,
-    const char* recipientID,
+    const EntityDescriptor* recipient,
     const char* relayState,
-    const CredentialResolver* credResolver,
-    const XMLCh* sigAlgorithm
+    const ArtifactGenerator* artifactGenerator,
+    const Credential* credential,
+    const XMLCh* signatureAlg,
+    const XMLCh* digestAlg
     ) const
 {
 #ifdef _DEBUG
@@ -101,7 +109,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();
@@ -110,12 +118,19 @@ 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 (signatureAlg)
+                        sig->setSignatureAlgorithm(signatureAlg);
+                    if (digestAlg) {
+                        opensaml::ContentReference* cr = dynamic_cast<opensaml::ContentReference*>(sig->getContentReference());
+                        if (cr)
+                            cr->setDigestAlgorithm(digestAlg);
+                    }
             
                     // Sign response while marshalling.
                     vector<Signature*> sigs(1,sig);
-                    rootElement = env->marshall((DOMDocument*)NULL,&sigs);
+                    rootElement = env->marshall((DOMDocument*)NULL,&sigs,credential);
                 }
             }
             else {