From 94fcba86b18d67a1c624f9e0e77912c48b5620bd Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Mon, 25 Oct 2010 11:44:50 +0000
Subject: [PATCH] statistics: Use SimpleSAML_Auth_Simple.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2598 44740490-163a-0410-bde0-09ae8108e29a
---
 modules/statistics/lib/AccessCheck.php | 67 ++++++++++++--------------
 1 file changed, 32 insertions(+), 35 deletions(-)

diff --git a/modules/statistics/lib/AccessCheck.php b/modules/statistics/lib/AccessCheck.php
index 867927436..4350c2b48 100644
--- a/modules/statistics/lib/AccessCheck.php
+++ b/modules/statistics/lib/AccessCheck.php
@@ -15,7 +15,6 @@ class sspmod_statistics_AccessCheck {
 	 * If the user doesn't have access, send the user to the login page.
 	 */
 	public static function checkAccess(SimpleSAML_Configuration $statconfig) {
-		$session = SimpleSAML_Session::getInstance();
 		$protected = $statconfig->getBoolean('protected', FALSE);
 		$authsource = $statconfig->getString('auth', NULL);
 		$allowedusers = $statconfig->getValue('allowedUsers', NULL);
@@ -36,52 +35,50 @@ class sspmod_statistics_AccessCheck {
 			return;
 		}
 
-		if (isset($authsource) && $session->isValid($authsource) ) {
+		if (!isset($authsource)) {
+			// If authsource is not defined, init admin login.
+			SimpleSAML_Utilities::requireAdmin();
+		}
 
-			// User logged in with auth source.
-			SimpleSAML_Logger::debug('Statistics auth - valid login with auth source [' . $authsource . ']');
+		/* We are using an authsource for login. */
 
-			// Retrieving attributes
-			$attributes = $session->getAttributes();
+		$as = new SimpleSAML_Auth_Simple($authsource);
+		$as->requireAuth();
 
-			if (!empty($allowedusers)) {
-				// Check if userid exists
-				if (!isset($attributes[$useridattr][0]))
-					throw new Exception('User ID is missing');
+		// User logged in with auth source.
+		SimpleSAML_Logger::debug('Statistics auth - valid login with auth source [' . $authsource . ']');
 
-				// Check if userid is allowed access..
-				if (in_array($attributes[$useridattr][0], $allowedusers)) {
-					SimpleSAML_Logger::debug('Statistics auth - User granted access by user ID [' . $attributes[$useridattr][0] . ']');
-					return;
-				}
-				SimpleSAML_Logger::debug('Statistics auth - User denied access by user ID [' . $attributes[$useridattr][0] . ']');
+		// Retrieving attributes
+		$attributes = $as->getAttributes();
 
-			} else {
-				SimpleSAML_Logger::debug('Statistics auth - no allowedUsers list.');
-			}
+		if (!empty($allowedusers)) {
+			// Check if userid exists
+			if (!isset($attributes[$useridattr][0]))
+				throw new Exception('User ID is missing');
 
-			if (!is_null($acl)) {
-				$acl = new sspmod_core_ACL($acl);
-				if ($acl->allows($attributes)) {
-					SimpleSAML_Logger::debug('Statistics auth - allowed access by ACL.');
-					return;
-				}
-				SimpleSAML_Logger::debug('Statistics auth - denied access by ACL.');
-			} else {
-				SimpleSAML_Logger::debug('Statistics auth - no ACL configured.');
+			// Check if userid is allowed access..
+			if (in_array($attributes[$useridattr][0], $allowedusers)) {
+				SimpleSAML_Logger::debug('Statistics auth - User granted access by user ID [' . $attributes[$useridattr][0] . ']');
+				return;
 			}
+			SimpleSAML_Logger::debug('Statistics auth - User denied access by user ID [' . $attributes[$useridattr][0] . ']');
 
-			throw new SimpleSAML_Error_Exception('Access denied to the current user.');
-
+		} else {
+			SimpleSAML_Logger::debug('Statistics auth - no allowedUsers list.');
 		}
 
-		if(isset($authsource)) {
-			// If user is not logged in init login with authrouce if authsousrce is defined.
-			SimpleSAML_Auth_Default::initLogin($authsource, SimpleSAML_Utilities::selfURL());
+		if (!is_null($acl)) {
+			$acl = new sspmod_core_ACL($acl);
+			if ($acl->allows($attributes)) {
+				SimpleSAML_Logger::debug('Statistics auth - allowed access by ACL.');
+				return;
+			}
+			SimpleSAML_Logger::debug('Statistics auth - denied access by ACL.');
 		} else {
-			// If authsource is not defined, init admin login.
-			SimpleSAML_Utilities::requireAdmin();
+			SimpleSAML_Logger::debug('Statistics auth - no ACL configured.');
 		}
+
+		throw new SimpleSAML_Error_Exception('Access denied to the current user.');
 	}
 
 }
\ No newline at end of file
-- 
GitLab