/*
- * 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.
#include "internal.h"
#include "exceptions.h"
-#include "saml/binding/ArtifactMap.h"
-#include "saml/binding/SAMLArtifact.h"
-#include "saml1/binding/SAML1ArtifactEncoder.h"
+#include "binding/ArtifactMap.h"
+#include "binding/MessageEncoder.h"
+#include "binding/SAMLArtifact.h"
#include "saml1/core/Assertions.h"
+#include "saml1/core/Protocols.h"
#include <log4cpp/Category.hh>
+#include <xmltooling/XMLToolingConfig.h>
+#include <xmltooling/io/HTTPResponse.h>
#include <xmltooling/util/NDC.h>
+#include <xmltooling/util/URLEncoder.h>
using namespace opensaml::saml1;
using namespace opensaml::saml1p;
namespace opensaml {
namespace saml1p {
+ class SAML_DLLLOCAL SAML1ArtifactEncoder : public MessageEncoder
+ {
+ public:
+ SAML1ArtifactEncoder(const DOMElement* e) {}
+ virtual ~SAML1ArtifactEncoder() {}
+
+ 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;
+ };
+
MessageEncoder* SAML_DLLLOCAL SAML1ArtifactEncoderFactory(const DOMElement* const & e)
{
return new SAML1ArtifactEncoder(e);
};
};
-SAML1ArtifactEncoder::SAML1ArtifactEncoder(const DOMElement* e) {}
-
-SAML1ArtifactEncoder::~SAML1ArtifactEncoder() {}
-
-void SAML1ArtifactEncoder::encode(
- map<string,string>& outputFields,
+long SAML1ArtifactEncoder::encode(
+ GenericResponse& genericResponse,
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
xmltooling::NDC ndc("encode");
#endif
Category& log = Category::getInstance(SAML_LOGCAT".MessageEncoder.SAML1Artifact");
+
log.debug("validating input");
-
- outputFields.clear();
+ HTTPResponse* httpResponse=dynamic_cast<HTTPResponse*>(&genericResponse);
+ if (!httpResponse)
+ throw BindingException("Unable to cast response interface to HTTPResponse type.");
if (xmlObject->getParent())
throw BindingException("Cannot encode XML content with parent.");
Assertion* assertion = dynamic_cast<Assertion*>(xmlObject);
log.debug("obtaining new artifact for relying party (%s)", recipientID ? recipientID : "unknown");
auto_ptr<SAMLArtifact> artifact(m_artifactGenerator->generateSAML1Artifact(recipientID));
- // Pass back output fields.
- outputFields["SAMLart"] = artifact->encode();
- outputFields["TARGET"] = relayState;
-
// Store the assertion. Last step in storage will be to delete the XML.
log.debug("storing artifact and content in map");
mapper->storeContent(xmlObject, artifact.get(), recipientID);
- log.debug("message encoded");
+ // Generate redirect.
+ string loc = destination;
+ loc += (strchr(destination,'?') ? '&' : '?');
+ const URLEncoder* escaper = XMLToolingConfig::getConfig().getURLEncoder();
+ loc = loc + "SAMLart=" + escaper->encode(artifact->encode().c_str()) + "&TARGET=" + escaper->encode(relayState);
+ log.debug("message encoded, sending redirect to client");
+ return httpResponse->sendRedirect(loc.c_str());
}