X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=saml%2Fsaml2%2Fbinding%2Fimpl%2FSAML2ECPEncoder.cpp;h=36c0fce11a8983abcf0517540bde856eb6544091;hb=5e62d2c1fb43763b3d627e641a310a79992b01c0;hp=2cddf29e6cb8f95084bf1775899d20a3029c69e2;hpb=30060a96ad3a0a97d8a51328c92faa64f4302049;p=shibboleth%2Fcpp-opensaml.git diff --git a/saml/saml2/binding/impl/SAML2ECPEncoder.cpp b/saml/saml2/binding/impl/SAML2ECPEncoder.cpp index 2cddf29..36c0fce 100644 --- a/saml/saml2/binding/impl/SAML2ECPEncoder.cpp +++ b/saml/saml2/binding/impl/SAML2ECPEncoder.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2010 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ /** * SAML2ECPEncoder.cpp * - * SAML 2.0 ECP profile message encoder + * SAML 2.0 ECP profile message encoder. */ #include "internal.h" @@ -32,6 +32,7 @@ #include #include #include +#include #include using namespace samlconstants; @@ -54,8 +55,8 @@ namespace opensaml { { public: SAML2ECPEncoder(const DOMElement* e, const XMLCh* ns) : m_actor("http://schemas.xmlsoap.org/soap/actor/next"), - m_providerName(e ? e->getAttributeNS(ns, ProviderName) : NULL), m_idpList(NULL) { - DOMElement* child = e ? XMLHelper::getFirstChildElement(e, SAML20P_NS, IDPList::LOCAL_NAME) : NULL; + m_providerName(e ? e->getAttributeNS(ns, ProviderName) : nullptr), m_idpList(nullptr) { + DOMElement* child = e ? XMLHelper::getFirstChildElement(e, SAML20P_NS, IDPList::LOCAL_NAME) : nullptr; if (child) m_idpList = dynamic_cast(XMLObjectBuilder::buildOneFromElement(child)); } @@ -63,16 +64,20 @@ namespace opensaml { delete m_idpList; } + const XMLCh* getProtocolFamily() const { + return samlconstants::SAML20P_NS; + } + 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 EntityDescriptor* recipient=nullptr, + const char* relayState=nullptr, + const ArtifactGenerator* artifactGenerator=nullptr, + const Credential* credential=nullptr, + const XMLCh* signatureAlg=nullptr, + const XMLCh* digestAlg=nullptr ) const; private: @@ -110,7 +115,7 @@ long SAML2ECPEncoder::encode( if (xmlObject->getParent()) throw BindingException("Cannot encode XML content with parent."); - Response* response = NULL; + Response* response = nullptr; AuthnRequest* request = dynamic_cast(xmlObject); if (!request) { response = dynamic_cast(xmlObject); @@ -127,6 +132,7 @@ long SAML2ECPEncoder::encode( genericResponse.setContentType(request ? "application/vnd.paos+xml" : "text/xml"); HTTPResponse* httpResponse = dynamic_cast(&genericResponse); if (httpResponse) { + httpResponse->setResponseHeader("Expires", "01-Jan-1997 12:00:00 GMT"); httpResponse->setResponseHeader("Cache-Control", "no-cache, no-store, must-revalidate, private"); httpResponse->setResponseHeader("Pragma", "no-cache"); } @@ -140,8 +146,8 @@ long SAML2ECPEncoder::encode( body->getUnknownXMLObjects().push_back(xmlObject); ElementProxy* hdrblock; - QName qMU(SOAP11ENV_NS, Header::MUSTUNDERSTAND_ATTRIB_NAME, SOAP11ENV_PREFIX); - QName qActor(SOAP11ENV_NS, Header::ACTOR_ATTRIB_NAME, SOAP11ENV_PREFIX); + xmltooling::QName qMU(SOAP11ENV_NS, Header::MUSTUNDERSTAND_ATTRIB_NAME, SOAP11ENV_PREFIX); + xmltooling::QName qActor(SOAP11ENV_NS, Header::ACTOR_ATTRIB_NAME, SOAP11ENV_PREFIX); if (request) { // Create paos:Request header. @@ -150,8 +156,8 @@ long SAML2ECPEncoder::encode( hdrblock = dynamic_cast(m_anyBuilder.buildObject(PAOS_NS, saml1p::Request::LOCAL_NAME, PAOS_PREFIX)); hdrblock->setAttribute(qMU, XML_ONE); hdrblock->setAttribute(qActor, m_actor.get()); - hdrblock->setAttribute(QName(NULL, service), SAML20ECP_NS); - hdrblock->setAttribute(QName(NULL, responseConsumerURL), request->getAssertionConsumerServiceURL()); + hdrblock->setAttribute(xmltooling::QName(nullptr, service), SAML20ECP_NS); + hdrblock->setAttribute(xmltooling::QName(nullptr, responseConsumerURL), request->getAssertionConsumerServiceURL()); header->getUnknownXMLObjects().push_back(hdrblock); // Create ecp:Request header. @@ -160,9 +166,9 @@ long SAML2ECPEncoder::encode( hdrblock->setAttribute(qMU, XML_ONE); hdrblock->setAttribute(qActor, m_actor.get()); if (!request->IsPassive()) - hdrblock->setAttribute(QName(NULL,IsPassive), XML_ZERO); + hdrblock->setAttribute(xmltooling::QName(nullptr,IsPassive), XML_ZERO); if (m_providerName) - hdrblock->setAttribute(QName(NULL,ProviderName), m_providerName); + hdrblock->setAttribute(xmltooling::QName(nullptr,ProviderName), m_providerName); hdrblock->getUnknownXMLObjects().push_back(request->getIssuer()->clone()); if (request->getScoping() && request->getScoping()->getIDPList()) hdrblock->getUnknownXMLObjects().push_back(request->getScoping()->getIDPList()->clone()); @@ -175,11 +181,11 @@ long SAML2ECPEncoder::encode( hdrblock = dynamic_cast(m_anyBuilder.buildObject(SAML20ECP_NS, Response::LOCAL_NAME, SAML20ECP_PREFIX)); hdrblock->setAttribute(qMU, XML_ONE); hdrblock->setAttribute(qActor, m_actor.get()); - hdrblock->setAttribute(QName(NULL,AuthnRequest::ASSERTIONCONSUMERSERVICEURL_ATTRIB_NAME), response->getDestination()); + hdrblock->setAttribute(xmltooling::QName(nullptr,AuthnRequest::ASSERTIONCONSUMERSERVICEURL_ATTRIB_NAME), response->getDestination()); header->getUnknownXMLObjects().push_back(hdrblock); } - if (relayState) { + if (relayState && *relayState) { // Create ecp:RelayState header. static const XMLCh RelayState[] = UNICODE_LITERAL_10(R,e,l,a,y,S,t,a,t,e); hdrblock = dynamic_cast(m_anyBuilder.buildObject(SAML20ECP_NS, RelayState, SAML20ECP_PREFIX)); @@ -191,7 +197,7 @@ long SAML2ECPEncoder::encode( } try { - DOMElement* rootElement = NULL; + DOMElement* rootElement = nullptr; if (credential) { if (request->getSignature()) { log.debug("message already signed, skipping signature operation"); @@ -213,7 +219,7 @@ long SAML2ECPEncoder::encode( // Sign message while marshalling. vector sigs(1,sig); - rootElement = env->marshall((DOMDocument*)NULL,&sigs,credential); + rootElement = env->marshall((DOMDocument*)nullptr,&sigs,credential); } } else { @@ -224,8 +230,10 @@ long SAML2ECPEncoder::encode( stringstream s; s << *rootElement; - if (log.isDebugEnabled()) - log.debug("marshalled envelope:\n%s", s.str().c_str()); + if (log.isDebugEnabled()) { + string forlog(s.str()); + log.debug("marshalled envelope:\n%s", forlog.c_str()); + } log.debug("sending serialized envelope"); long ret = genericResponse.sendResponse(s);