From c0c57d610a077ef99daecbe490cb82bc0eab20e7 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Tue, 16 Nov 2010 14:31:18 +0000
Subject: [PATCH] www/saml2/sp: Use the new interface in Session.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2642 44740490-163a-0410-bde0-09ae8108e29a
---
 www/example-simple/saml2-example.php      |  4 ++--
 www/saml2/sp/AssertionConsumerService.php | 15 ++++++++-------
 www/saml2/sp/SingleLogoutService.php      |  2 +-
 www/saml2/sp/initSLO.php                  | 10 +++++-----
 4 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/www/example-simple/saml2-example.php b/www/example-simple/saml2-example.php
index 7dd041364..c0483c9e8 100644
--- a/www/example-simple/saml2-example.php
+++ b/www/example-simple/saml2-example.php
@@ -50,7 +50,7 @@ if (!$session->isValid('saml2') ) {
 /* Prepare attributes for presentation 
 * and call a hook function for organizing the attribute array
 */
-$attributes = $session->getAttributes();
+$attributes = $session->getAuthData('saml2', 'Attributes');
 $para = array(
 	'attributes' => &$attributes
 );
@@ -69,7 +69,7 @@ SimpleSAML_Module::callHooks('attributepresentation', $para);
 $t = new SimpleSAML_XHTML_Template($config, 'status.php', 'attributes');
 
 $t->data['header'] = '{status:header_saml20_sp}';
-$t->data['remaining'] = $session->remainingTime();
+$t->data['remaining'] = $session->getAuthData('saml2', 'Expire') - time();
 $t->data['sessionsize'] = $session->getSize();
 $t->data['attributes'] = $attributes;
 $t->data['logouturl'] = '/' . $config->getBaseURL() . 'saml2/sp/initSLO.php?RelayState=/' .
diff --git a/www/saml2/sp/AssertionConsumerService.php b/www/saml2/sp/AssertionConsumerService.php
index 3e36f9616..bb5a3c1da 100644
--- a/www/saml2/sp/AssertionConsumerService.php
+++ b/www/saml2/sp/AssertionConsumerService.php
@@ -37,14 +37,15 @@ function finishLogin($authProcState) {
 	assert('array_key_exists("Source", $authProcState)');
 	assert('array_key_exists("entityid", $authProcState["Source"])');
 
-	global $session;
+	$authData = array(
+		'Attributes' => $authProcState['Attributes'],
+		'saml:sp:NameID' => $authProcState['core:saml20-sp:NameID'],
+		'saml:sp:SessionIndex' => $authProcState['core:saml20-sp:SessionIndex'],
+		'saml:sp:IdP' => $authProcState['Source']['entityid'],
+	);
 
-	/* Update the session information */
-	$session->doLogin('saml2');
-	$session->setAttributes($authProcState['Attributes']);
-	$session->setNameID($authProcState['core:saml20-sp:NameID']);
-	$session->setSessionIndex($authProcState['core:saml20-sp:SessionIndex']);
-	$session->setIdP($authProcState['Source']['entityid']);
+	global $session;
+	$session->doLogin('saml2', $authData);
 
 	SimpleSAML_Utilities::redirect($authProcState['core:saml20-sp:TargetURL']);
 }
diff --git a/www/saml2/sp/SingleLogoutService.php b/www/saml2/sp/SingleLogoutService.php
index 3b6b1a4e8..559a088c0 100644
--- a/www/saml2/sp/SingleLogoutService.php
+++ b/www/saml2/sp/SingleLogoutService.php
@@ -17,7 +17,7 @@ if (!$config->getBoolean('enable.saml20-sp', TRUE))
 
 
 // Destroy local session if exists.
-$session->doLogout();
+$session->doLogout('saml2');
 
 $binding = SAML2_Binding::getCurrentBinding();
 $message = $binding->receive();
diff --git a/www/saml2/sp/initSLO.php b/www/saml2/sp/initSLO.php
index b280a1311..7d4bb8f86 100644
--- a/www/saml2/sp/initSLO.php
+++ b/www/saml2/sp/initSLO.php
@@ -22,7 +22,7 @@ if (isset($_REQUEST['RelayState'])) {
 try {
 	$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
 
-	$idpEntityId = $session->getIdP();
+	$idpEntityId = $session->getAuthData('saml2', 'saml:sp:IdP');
 	if ($idpEntityId === NULL) {
 		SimpleSAML_Logger::info('SAML2.0 - SP.initSLO: User not authenticated with an IdP.');
 		SimpleSAML_Utilities::redirect($returnTo);
@@ -30,7 +30,7 @@ try {
 	$idpMetadata = $metadata->getMetaDataConfig($idpEntityId, 'saml20-idp-remote');
 	$SLOendpoint = $idpMetadata->getDefaultEndpoint('SingleLogoutService', array(SAML2_Const::BINDING_HTTP_REDIRECT), NULL);
 	if ($SLOendpoint === NULL) {
-		$session->doLogout();
+		$session->doLogout('saml2');
 		SimpleSAML_Logger::info('SAML2.0 - SP.initSLO: No supported SingleLogoutService endpoint in IdP.');
 		SimpleSAML_Utilities::redirect($returnTo);
 	}
@@ -38,13 +38,13 @@ try {
 	$spEntityId = isset($_GET['spentityid']) ? $_GET['spentityid'] : $metadata->getMetaDataCurrentEntityID();
 	$spMetadata = $metadata->getMetaDataConfig($spEntityId, 'saml20-sp-hosted');
 
-	$nameId = $session->getNameId();
+	$nameId = $session->getAuthData('saml2', 'saml:sp:NameID');
 
 	$lr = sspmod_saml_Message::buildLogoutRequest($spMetadata, $idpMetadata);
 	$lr->setNameId($nameId);
-	$lr->setSessionIndex($session->getSessionIndex());
+	$lr->setSessionIndex($session->getAuthData('saml2', 'saml:sp:SessionIndex'));
 
-	$session->doLogout();
+	$session->doLogout('saml2');
 
 	/* Save the $returnTo url until the user returns from the IdP. */
 	$session->setData('spLogoutReturnTo', $lr->getId(), $returnTo);
-- 
GitLab