From 907e92ced8c101a912114ed932d39887641c3419 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Mon, 17 Aug 2015 12:05:21 +0000 Subject: [PATCH] authentication : better error management in configuration (Exception in case of errors). git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2254 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- authentication.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/authentication.php b/authentication.php index a67c96e..8172cba 100644 --- a/authentication.php +++ b/authentication.php @@ -217,6 +217,8 @@ class authentication an exception if noting is found */ private function verifAuth ($email, $password) { + if (! is_array ($this->authMethods) || count ($this->authMethods) === 0) + throw new Exception ("No authentication method defined", 500); if (isset ($_SESSION["domframework"]["authentication"]["lastcheck"]) && $_SESSION["domframework"]["authentication"]["lastcheck"] + 180 < time ()) @@ -228,19 +230,30 @@ class authentication foreach ($this->authMethods as $method) { + if (! is_string ($method)) + throw new Exception ("The authentication method is not a string", 500); $classname = "auth$method"; require_once ("domframework/$classname.php"); - + if (! array_key_exists ($classname, $this->authServers)) + throw new Exception ("No authentication server '$classname' enabled", + 500); // If only one server is defined, the parameters can directely be pushed // to the classname - if (! is_array ($this->authServers[$classname])) + if (! is_array (reset ($this->authServers[$classname]))) { $this->authServers[$classname] = array ($this->authServers[$classname]); } + if (! is_array ($this->authServers[$classname]) || + count ($this->authServers[$classname]) === 0) + throw new Exception ("No authentication server defined for method ". + "'$method'", 500); foreach ($this->authServers[$classname] as $key=>$serversParam) { if ($this->debug) echo "Test auth server $method # $classname # $key\n"; + if (! is_array ($serversParam)) + throw new Exception ("Auth Server $key configuration error : ". + "not an array", 500); $authmethod = new $classname (); foreach ($serversParam as $param=>$value) {