From 20902edce5388c6bcafc59c6defb96943e64bac9 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Tue, 6 Jul 2010 06:28:51 +0000
Subject: [PATCH] Utilities::generateUserIdentifier: Require UserID to be set
 in $state.

If UserID isn't set in $state, it means that we were unable to retrieve
it previously. Trying again isn't likely to succeed.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2377 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Utilities.php | 34 +++-------------------------------
 1 file changed, 3 insertions(+), 31 deletions(-)

diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 3a8018aef..98684ebf1 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -1107,39 +1107,11 @@ class SimpleSAML_Utilities {
 	 * @return A non-reversible unique identifier for the user.
 	 */
 	public static function generateUserIdentifier($idpEntityId, $spEntityId, array &$state, $idpset = 'saml20-idp-hosted', $spset = 'saml20-sp-remote') {
-	
-		$metadataHandler = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
-		$idpMetadata = $metadataHandler->getMetaData($idpEntityId, $idpset);
-		$spMetadata = $metadataHandler->getMetaData($spEntityId, $spset);
-
-		if (isset($state['UserID'])) {
-			$attributeValue = $state['UserID'];
-		} else {
-			if(array_key_exists('userid.attribute', $spMetadata)) {
-				$attributeName = $spMetadata['userid.attribute'];
-			} elseif(array_key_exists('userid.attribute', $idpMetadata)) {
-				$attributeName = $idpMetadata['userid.attribute'];
-			} else {
-				$attributeName = 'eduPersonPrincipalName';
-			}
 
-			if(!array_key_exists($attributeName, $attributes)) {
-				throw new Exception('Missing attribute "' . $attributeName . '" for user. Cannot' .
-					' generate user id.');
-			}
-
-			$attributeValue = $attributes[$attributeName];
-			if(count($attributeValue) !== 1) {
-				throw new Exception('Attribute "' . $attributeName . '" for user did not contain exactly' .
-					' one value. Cannot generate user id.');
-			}
-
-			$attributeValue = $attributeValue[0];
-			if(empty($attributeValue)) {
-				throw new Exception('Attribute "' . $attributeName . '" for user was empty. Cannot' .
-					' generate user id.');
-			}
+		if (!isset($state['UserID'])) {
+			throw new SimpleSAML_Error_Exception('Missing UserID. Please set the userid.attribute metadata option.');
 		}
+		$attributeValue = $state['UserID'];
 
 		$secretSalt = self::getSecretSalt();
 
-- 
GitLab