X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=saml%2Fsaml1%2Fbinding%2Fimpl%2FSAML1SOAPEncoder.cpp;h=7dc59a1d6dd729d257cbf58f3bf3d785d3f41c93;hb=2d05f4d1935e7b79e70f2775a14c10964a04164e;hp=121acbe12b659925ca4a6601303f26bda3fea1f9;hpb=8a21bb42163a78e9c324f840004fd9e9821ad745;p=shibboleth%2Fcpp-opensaml.git diff --git a/saml/saml1/binding/impl/SAML1SOAPEncoder.cpp b/saml/saml1/binding/impl/SAML1SOAPEncoder.cpp index 121acbe..7dc59a1 100644 --- a/saml/saml1/binding/impl/SAML1SOAPEncoder.cpp +++ b/saml/saml1/binding/impl/SAML1SOAPEncoder.cpp @@ -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. @@ -22,16 +22,18 @@ #include "internal.h" #include "exceptions.h" -#include "binding/HTTPResponse.h" -#include "saml1/binding/SAML1SOAPEncoder.h" +#include "binding/MessageEncoder.h" +#include "signature/ContentReference.h" #include "saml1/core/Protocols.h" #include #include +#include #include #include using namespace opensaml::saml1p; +using namespace opensaml::saml2md; using namespace opensaml; using namespace xmlsignature; using namespace soap11; @@ -41,6 +43,29 @@ using namespace std; namespace opensaml { namespace saml1p { + class SAML_DLLLOCAL SAML1SOAPEncoder : public MessageEncoder + { + public: + SAML1SOAPEncoder(const DOMElement* e) {} + virtual ~SAML1SOAPEncoder() {} + + bool isUserAgentPresent() const { + return false; + } + + long encode( + GenericResponse& genericResponse, + XMLObject* xmlObject, + const char* destination, + const EntityDescriptor* recipient=NULL, + const char* relayState=NULL, + const ArtifactGenerator* artifactGenerator=NULL, + const Credential* credential=NULL, + const XMLCh* signatureAlg=NULL, + const XMLCh* digestAlg=NULL + ) const; + }; + MessageEncoder* SAML_DLLLOCAL SAML1SOAPEncoderFactory(const DOMElement* const & e) { return new SAML1SOAPEncoder(e); @@ -48,16 +73,16 @@ namespace opensaml { }; }; -SAML1SOAPEncoder::SAML1SOAPEncoder(const DOMElement* e) {} - long SAML1SOAPEncoder::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 @@ -70,6 +95,11 @@ long SAML1SOAPEncoder::encode( throw BindingException("Cannot encode XML content with parent."); genericResponse.setContentType("text/xml"); + HTTPResponse* httpResponse = dynamic_cast(&genericResponse); + if (httpResponse) { + httpResponse->setResponseHeader("Cache-Control", "no-cache, no-store, must-revalidate, private"); + httpResponse->setResponseHeader("Pragma", "no-cache"); + } DOMElement* rootElement = NULL; Response* response = dynamic_cast(xmlObject); @@ -78,8 +108,8 @@ long SAML1SOAPEncoder::encode( Envelope* env = EnvelopeBuilder::buildEnvelope(); Body* body = BodyBuilder::buildBody(); env->setBody(body); - body->getXMLObjects().push_back(response); - if (credResolver ) { + body->getUnknownXMLObjects().push_back(response); + if (credential) { if (response->getSignature()) { log.debug("response already signed, skipping signature operation"); rootElement = env->marshall(); @@ -88,12 +118,19 @@ long SAML1SOAPEncoder::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(sig->getContentReference()); + if (cr) + cr->setDigestAlgorithm(digestAlg); + } // Sign response while marshalling. vector sigs(1,sig); - rootElement = env->marshall((DOMDocument*)NULL,&sigs); + rootElement = env->marshall((DOMDocument*)NULL,&sigs,credential); } } else { @@ -101,9 +138,8 @@ long SAML1SOAPEncoder::encode( rootElement = env->marshall(); } - string xmlbuf; - XMLHelper::serialize(rootElement, xmlbuf); - istringstream s(xmlbuf); + stringstream s; + s << *rootElement; log.debug("sending serialized response"); long ret = genericResponse.sendResponse(s); @@ -129,7 +165,7 @@ long SAML1SOAPEncoder::encode( Envelope* env = EnvelopeBuilder::buildEnvelope(); Body* body = BodyBuilder::buildBody(); env->setBody(body); - body->getXMLObjects().push_back(fault); + body->getUnknownXMLObjects().push_back(fault); rootElement = env->marshall(); string xmlbuf; @@ -161,7 +197,7 @@ long SAML1SOAPEncoder::encode( bool error = (env->getBody() && env->getBody()->hasChildren() && - dynamic_cast(env->getBody()->getXMLObjects().front())); + dynamic_cast(env->getBody()->getUnknownXMLObjects().front())); string xmlbuf; XMLHelper::serialize(rootElement, xmlbuf);