X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=saml%2Fsaml2%2Fbinding%2Fimpl%2FSAML2ArtifactEncoder.cpp;h=f397ebd21609662b87b299902cdb2006dd238640;hb=f3a43f14f9dd53428f9e879bb489d6a4cf2674a8;hp=1534860d3c831c6778c1fe713b0b99338dc8ec56;hpb=2f1c4cb020bf2e6e2158c80741915244a3faf039;p=shibboleth%2Fcpp-opensaml.git diff --git a/saml/saml2/binding/impl/SAML2ArtifactEncoder.cpp b/saml/saml2/binding/impl/SAML2ArtifactEncoder.cpp index 1534860..f397ebd 100644 --- a/saml/saml2/binding/impl/SAML2ArtifactEncoder.cpp +++ b/saml/saml2/binding/impl/SAML2ArtifactEncoder.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. @@ -24,9 +24,8 @@ #include "exceptions.h" #include "binding/ArtifactMap.h" #include "binding/HTTPResponse.h" -#include "binding/URLEncoder.h" +#include "binding/MessageEncoder.h" #include "saml2/binding/SAML2Artifact.h" -#include "saml2/binding/SAML2ArtifactEncoder.h" #include "saml2/core/Protocols.h" #include @@ -34,6 +33,7 @@ #include #include #include +#include using namespace opensaml::saml2p; using namespace opensaml; @@ -44,6 +44,27 @@ using namespace std; namespace opensaml { namespace saml2p { + class SAML_DLLLOCAL SAML2ArtifactEncoder : public MessageEncoder + { + public: + SAML2ArtifactEncoder(const DOMElement* e); + virtual ~SAML2ArtifactEncoder() {} + + long encode( + GenericResponse& genericResponse, + XMLObject* xmlObject, + const char* destination, + const char* recipientID=NULL, + const char* relayState=NULL, + const Credential* credential=NULL, + const XMLCh* signatureAlg=NULL, + const XMLCh* digestAlg=NULL + ) const; + + private: + string m_template; + }; + MessageEncoder* SAML_DLLLOCAL SAML2ArtifactEncoderFactory(const DOMElement* const & e) { return new SAML2ArtifactEncoder(e); @@ -51,12 +72,12 @@ namespace opensaml { }; }; -static const XMLCh templat[] = UNICODE_LITERAL_8(t,e,m,p,l,a,t,e); +static const XMLCh _template[] = UNICODE_LITERAL_8(t,e,m,p,l,a,t,e); SAML2ArtifactEncoder::SAML2ArtifactEncoder(const DOMElement* e) { if (e) { - auto_ptr_char t(e->getAttributeNS(NULL, templat)); + auto_ptr_char t(e->getAttributeNS(NULL, _template)); if (t.get()) m_template = t.get(); } @@ -64,12 +85,13 @@ SAML2ArtifactEncoder::SAML2ArtifactEncoder(const DOMElement* e) long SAML2ArtifactEncoder::encode( GenericResponse& genericResponse, - xmltooling::XMLObject* xmlObject, + XMLObject* xmlObject, const char* destination, const char* recipientID, const char* relayState, - const CredentialResolver* credResolver, - const XMLCh* sigAlgorithm + const Credential* credential, + const XMLCh* signatureAlg, + const XMLCh* digestAlg ) const { #ifdef _DEBUG @@ -104,7 +126,7 @@ long SAML2ArtifactEncoder::encode( log.debug("obtaining new artifact for relying party (%s)", recipientID ? recipientID : "unknown"); auto_ptr artifact(m_artifactGenerator->generateSAML2Artifact(recipientID)); - if (credResolver) { + if (credential) { // Signature based on native XML signing. if (request ? request->getSignature() : response->getSignature()) { log.debug("message already signed, skipping signature operation"); @@ -113,14 +135,19 @@ long SAML2ArtifactEncoder::encode( log.debug("signing the message"); // Build a Signature. - Signature* sig = buildSignature(credResolver, sigAlgorithm); - - // Append Signature. + Signature* sig = SignatureBuilder::buildSignature(); request ? request->setSignature(sig) : 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); - xmlObject->marshall((DOMDocument*)NULL,&sigs); + xmlObject->marshall((DOMDocument*)NULL,&sigs,credential); } } @@ -132,7 +159,7 @@ long SAML2ArtifactEncoder::encode( // Generate redirect. string loc = destination; loc += (strchr(destination,'?') ? '&' : '?'); - URLEncoder* escaper = SAMLConfig::getConfig().getURLEncoder(); + const URLEncoder* escaper = XMLToolingConfig::getConfig().getURLEncoder(); loc = loc + "SAMLart=" + escaper->encode(artifact->encode().c_str()); if (relayState) loc = loc + "&RelayState=" + escaper->encode(relayState);