Add more debug for authentication

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2996 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2016-08-03 13:09:17 +00:00
parent 97194883b8
commit 1fc8635b71

View File

@@ -172,13 +172,14 @@ class authentication
/** Check all the REST API */ /** Check all the REST API */
public function verifAuthREST () public function verifAuthREST ()
{ {
if ($this->debug)
echo "=== entering verifAuthREST (restMethods=".
print_r ($this->restMethods, true).")\n";
$authparams = new \authparams ($this->restMethods); $authparams = new \authparams ($this->restMethods);
$res = array ("email"=>"anonymous", "password"=>"anonymous"); $res = array ("email"=>"anonymous", "password"=>"anonymous");
if ($authparams->email !== "anonymous" && if ($authparams->email !== "anonymous" &&
$authparams->password !== "anonymous") $authparams->password !== "anonymous")
{ {
if ($this->debug)
echo "verifAuth ($authparams->email, $authparams->password)\n";
$res = $this->verifAuth ($authparams->email, $authparams->password); $res = $this->verifAuth ($authparams->email, $authparams->password);
} }
if (! is_array ($res)) if (! is_array ($res))
@@ -196,7 +197,9 @@ class authentication
/** Check all the others pages of the site */ /** Check all the others pages of the site */
public function verifAuthHTML () public function verifAuthHTML ()
{ {
if ($this->debug) echo "verifAuthHTML() : "; if ($this->debug)
echo "=== entering verifAuthHTML (htmlMethods=".
print_r ($this->htmlMethods, true).")\n";
$authparams = new \authparams ($this->htmlMethods); $authparams = new \authparams ($this->htmlMethods);
// Don't ask to the provider if anonymous is known // Don't ask to the provider if anonymous is known
if ($authparams->email === "anonymous" || $authparams->email === null) if ($authparams->email === "anonymous" || $authparams->email === null)
@@ -230,19 +233,26 @@ class authentication
an exception if noting is found */ an exception if noting is found */
private function verifAuth ($email, $password) private function verifAuth ($email, $password)
{ {
if ($this->debug)
echo "Entering in verifAuth ($email, xxxxxxxx)\n";
if (! is_array ($this->authMethods) || count ($this->authMethods) === 0) if (! is_array ($this->authMethods) || count ($this->authMethods) === 0)
throw new \Exception ("No authentication method defined", 500); throw new \Exception ("No authentication method defined", 500);
if (isset ($_SESSION["domframework"]["authentication"]["lastcheck"]) && if ($this->debug < 2 &&
isset ($_SESSION["domframework"]["authentication"]["lastcheck"]) &&
$_SESSION["domframework"]["authentication"]["lastcheck"] + 180 < $_SESSION["domframework"]["authentication"]["lastcheck"] + 180 <
time ()) time ())
{ {
// Test the authentication each 3 minutes if there is a session, else // Test the authentication each 3 minutes if there is a session, else
// return the previous values // return the previous values
if ($this->debug)
echo "verifAuth : using auth cache (push in debug=2 to skip)\n";
return $_SESSION["domframework"]["authentication"]["authcache"]; return $_SESSION["domframework"]["authentication"]["authcache"];
} }
foreach ($this->authMethods as $method) foreach ($this->authMethods as $method)
{ {
if ($this->debug)
echo "Authentication method=$method\n";
if (! is_string ($method)) if (! is_string ($method))
throw new \Exception ("The authentication method is not a string", 500); throw new \Exception ("The authentication method is not a string", 500);
$classname = "auth$method"; $classname = "auth$method";
@@ -256,6 +266,9 @@ class authentication
{ {
$this->authServers[$classname] = array ($this->authServers[$classname]); $this->authServers[$classname] = array ($this->authServers[$classname]);
} }
if ($this->debug >= 2)
echo "Authentication method=$method : authServers=".
var_export ($this->authServers[$classname])."\n";
if (! is_array ($this->authServers[$classname]) || if (! is_array ($this->authServers[$classname]) ||
count ($this->authServers[$classname]) === 0) count ($this->authServers[$classname]) === 0)
throw new \Exception ("No authentication server defined for method ". throw new \Exception ("No authentication server defined for method ".
@@ -270,6 +283,8 @@ class authentication
$authmethod = new $classname (); $authmethod = new $classname ();
foreach ($serversParam as $param=>$value) foreach ($serversParam as $param=>$value)
{ {
if ($this->debug)
echo "Add param '$param' with value '$value' to auth$method\n";
$authmethod->$param = $value; $authmethod->$param = $value;
} }
$authmethod->connect (); $authmethod->connect ();