From 725b94dcd19b0a09a4ba848a4791890774d63a3d Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Thu, 8 Jul 2010 13:18:40 +0000
Subject: [PATCH] Move getAuthority() from Utilities to IdP.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2388 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/IdP.php       | 45 +++++++++++++++++++++++++++++++++++-
 lib/SimpleSAML/Utilities.php | 40 --------------------------------
 2 files changed, 44 insertions(+), 41 deletions(-)

diff --git a/lib/SimpleSAML/IdP.php b/lib/SimpleSAML/IdP.php
index 18f78b75c..a16ef1762 100644
--- a/lib/SimpleSAML/IdP.php
+++ b/lib/SimpleSAML/IdP.php
@@ -225,6 +225,49 @@ class SimpleSAML_IdP {
 	}
 
 
+	/**
+	 * Retrieve the authority for the given IdP metadata.
+	 *
+	 * This function provides backwards-compatibility with
+	 * previous versions of simpleSAMLphp.
+	 *
+	 * @param array $idpmetadata  The IdP metadata.
+	 * @return string  The authority that should be used to validate the session.
+	 */
+	private function getAuthority() {
+
+		if ($this->config->hasValue('authority')) {
+			return $this->config->getString('authority');
+		}
+
+		$candidates = array(
+			'auth/login-admin.php' => 'login-admin',
+			'auth/login-auto.php' => 'login-auto',
+			'auth/login-cas-ldap.php' => 'login-cas-ldap',
+			'auth/login-feide.php' => 'login-feide',
+			'auth/login-ldapmulti.php' => 'login-ldapmulti',
+			'auth/login-radius.php' => 'login-radius',
+			'auth/login-tlsclient.php' => 'tlsclient',
+			'auth/login-wayf-ldap.php' => 'login-wayf-ldap',
+			'auth/login.php' => 'login',
+		);
+
+		$auth = $this->config->getString('auth');
+
+		if (isset($candidates[$auth])) {
+			return $candidates[$auth];
+		}
+		if (strpos($auth, '/') !== FALSE) {
+			/* Probably a file. */
+			throw new SimpleSAML_Error_Exception('You need to set \'authority\' in the metadata for ' .
+				var_export($this->id, TRUE) . '.');
+		} else {
+			throw new SimpleSAML_Error_Exception('Unknown authsource ' .
+				var_export($auth, TRUE) . '.');
+		}
+	}
+
+
 	/**
 	 * Is the current user authenticated?
 	 *
@@ -246,7 +289,7 @@ class SimpleSAML_IdP {
 		}
 
 		/* It wasn't an authentication source. */
-		$authority = SimpleSAML_Utilities::getAuthority($this->config->toArray());
+		$authority = $this->getAuthority();
 		return $session->isValid($authority);
 	}
 
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 3657a5ffa..98a2a103e 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -2123,46 +2123,6 @@ class SimpleSAML_Utilities {
 	}
 
 
-	/**
-	 * Retrieve the authority for the given IdP metadata.
-	 *
-	 * This function provides backwards-compatibility with
-	 * previous versions of simpleSAMLphp.
-	 *
-	 * @param array $idpmetadata  The IdP metadata.
-	 * @return string  The authority that should be used to validate the session.
-	 */
-	public static function getAuthority(array $idpmetadata) {
-
-		if (isset($idpmetadata['authority'])) {
-			return $idpmetadata['authority'];
-		}
-
-		$candidates = array(
-			'auth/login-admin.php' => 'login-admin',
-			'auth/login-auto.php' => 'login-auto',
-			'auth/login-cas-ldap.php' => 'login-cas-ldap',
-			'auth/login-feide.php' => 'login-feide',
-			'auth/login-ldapmulti.php' => 'login-ldapmulti',
-			'auth/login-radius.php' => 'login-radius',
-			'auth/login-tlsclient.php' => 'tlsclient',
-			'auth/login-wayf-ldap.php' => 'login-wayf-ldap',
-			'auth/login.php' => 'login',
-		);
-		if (isset($candidates[$idpmetadata['auth']])) {
-			return $candidates[$idpmetadata['auth']];
-		}
-		if (strpos($idpmetadata['auth'], '/') !== FALSE) {
-			/* Probably a file. */
-			throw new SimpleSAML_Error_Exception('You need to set \'authority\' in the metadata for ' .
-				var_export($idpmetadata['entityid'], TRUE) . '.');
-		} else {
-			throw new SimpleSAML_Error_Exception('Unknown authsource ' .
-				var_export($idpmetadata['auth'], TRUE) . '.');
-		}
-	}
-
-
 	/**
 	 * Check for session cookie, and show missing-cookie page if it is missing.
 	 *
-- 
GitLab