From 6a2deacaa7e81fa6780a4beb8a3fa1280a26acc9 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Mon, 9 Aug 2010 08:51:13 +0000
Subject: [PATCH] IdP/Artifact: Use the new datastore to store artifacts.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2491 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SAML2/HTTPArtifact.php                  | 9 ++++++++-
 www/saml2/idp/ArtifactResolutionService.php | 7 ++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib/SAML2/HTTPArtifact.php b/lib/SAML2/HTTPArtifact.php
index 958d61b00..21646ff64 100644
--- a/lib/SAML2/HTTPArtifact.php
+++ b/lib/SAML2/HTTPArtifact.php
@@ -20,11 +20,18 @@ class SAML2_HTTPArtifact extends SAML2_Binding {
 	 */
 	public function getRedirectURL(SAML2_Message $message) {
 
+		$store = SimpleSAML_Store::getInstance();
+		if ($store === FALSE) {
+			throw new Exception('Unable to send artifact without a datastore configured.');
+		}
+
 		$generatedId = pack('H*', ((string)  SimpleSAML_Utilities::stringToHex(SimpleSAML_Utilities::generateRandomBytes(20))));
 		$artifact = base64_encode("\x00\x04\x00\x00" . sha1($message->getIssuer(), TRUE) . $generatedId) ;
 		$artifactData = $message->toUnsignedXML();
 		$artifactDataString = $artifactData->ownerDocument->saveXML($artifactData);
-		SimpleSAML_Memcache::set('artifact:' . $artifact, $artifactDataString);
+
+		$store->set('artifact', $artifact, $artifactDataString, time() + 15*60);
+
 		$params = array(
 			'SAMLart' => $artifact,
 		);
diff --git a/www/saml2/idp/ArtifactResolutionService.php b/www/saml2/idp/ArtifactResolutionService.php
index b1f10d8c6..d1bdf7cd0 100644
--- a/www/saml2/idp/ArtifactResolutionService.php
+++ b/www/saml2/idp/ArtifactResolutionService.php
@@ -24,13 +24,18 @@ if (!$idpMetadata->getBoolean('saml20.sendartifact', FALSE)) {
 	throw new SimpleSAML_Error_Error('NOACCESS');
 }
 
+$store = SimpleSAML_Store::getInstance();
+if ($store === FALSE) {
+	throw new Exception('Unable to send artifact without a datastore configured.');
+}
+
 $binding = new SAML2_SOAP();
 $request = $binding->receive();
 if (!($request instanceof SAML2_ArtifactResolve)) {
 	throw new Exception('Message received on ArtifactResolutionService wasn\'t a ArtifactResolve request.');
 }
 $artifact = $request->getArtifact();
-$responseData = SimpleSAML_Memcache::get('artifact:' . $artifact);
+$responseData = $store->get('artifact', $artifact);
 $document = new DOMDocument();
 $document->loadXML($responseData);
 $responseXML = $document->firstChild;
-- 
GitLab