FIX add $context parameter in checkLoginPassEntity

This commit is contained in:
Regis Houssin 2019-08-22 10:56:07 +02:00
parent c7bec909b4
commit 90f60b0137
3 changed files with 11 additions and 6 deletions

View File

@ -64,7 +64,9 @@ class Login
// Authentication mode // Authentication mode
if (empty($dolibarr_main_authentication)) if (empty($dolibarr_main_authentication))
$dolibarr_main_authentication = 'http,dolibarr'; $dolibarr_main_authentication = 'http,dolibarr';
$dolibarr_main_authentication = preg_replace('/twofactor/', 'dolibarr', $dolibarr_main_authentication);
// this is manage directly in the module with $context parameters
//$dolibarr_main_authentication = preg_replace('/twofactor/', 'dolibarr', $dolibarr_main_authentication);
// Authentication mode: forceuser // Authentication mode: forceuser
if ($dolibarr_main_authentication == 'forceuser') if ($dolibarr_main_authentication == 'forceuser')
@ -87,7 +89,7 @@ class Login
if ($entity == '') $entity=1; if ($entity == '') $entity=1;
include_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php'; include_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php';
$login = checkLoginPassEntity($login, $password, $entity, $authmode); $login = checkLoginPassEntity($login, $password, $entity, $authmode, 'api');
if (empty($login)) if (empty($login))
{ {
throw new RestException(403, 'Access denied'); throw new RestException(403, 'Access denied');

View File

@ -47,9 +47,10 @@ function dol_getwebuser($mode)
* @param string $passwordtotest Password value to test * @param string $passwordtotest Password value to test
* @param string $entitytotest Instance of data we must check * @param string $entitytotest Instance of data we must check
* @param array $authmode Array list of selected authentication mode array('http', 'dolibarr', 'xxx'...) * @param array $authmode Array list of selected authentication mode array('http', 'dolibarr', 'xxx'...)
* @param string $context Context checkLoginPassEntity was created for ('api', 'dav', ...)
* @return string Login or '' * @return string Login or ''
*/ */
function checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode) function checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode, $context = null)
{ {
global $conf,$langs; global $conf,$langs;
//global $dolauthmode; // To return authentication finally used //global $dolauthmode; // To return authentication finally used
@ -90,7 +91,7 @@ function checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $auth
{ {
// Call function to check user/password // Call function to check user/password
$function='check_user_password_'.$mode; $function='check_user_password_'.$mode;
$login=call_user_func($function, $usertotest, $passwordtotest, $entitytotest); $login=call_user_func($function, $usertotest, $passwordtotest, $entitytotest, $context);
if ($login) // Login is successfull if ($login) // Login is successfull
{ {
$test=false; // To stop once at first login success $test=false; // To stop once at first login success

View File

@ -105,7 +105,9 @@ $authBackend = new \Sabre\DAV\Auth\Backend\BasicCallBack(function ($username, $p
// Authentication mode // Authentication mode
if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication='dolibarr'; if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication='dolibarr';
$dolibarr_main_authentication = preg_replace('/twofactor/', 'dolibarr', $dolibarr_main_authentication);
// this is manage directly in the module with $context parameters
//$dolibarr_main_authentication = preg_replace('/twofactor/', 'dolibarr', $dolibarr_main_authentication);
// Authentication mode: forceuser // Authentication mode: forceuser
if ($dolibarr_main_authentication == 'forceuser') if ($dolibarr_main_authentication == 'forceuser')
@ -121,7 +123,7 @@ $authBackend = new \Sabre\DAV\Auth\Backend\BasicCallBack(function ($username, $p
$authmode = explode(',', $dolibarr_main_authentication); $authmode = explode(',', $dolibarr_main_authentication);
$entity = (GETPOST('entity', 'int') ? GETPOST('entity', 'int') : (!empty($conf->entity) ? $conf->entity : 1)); $entity = (GETPOST('entity', 'int') ? GETPOST('entity', 'int') : (!empty($conf->entity) ? $conf->entity : 1));
if (checkLoginPassEntity($username, $password, $entity, $authmode) != $username) if (checkLoginPassEntity($username, $password, $entity, $authmode, 'dav') != $username)
return false; return false;
return true; return true;