- Added new constants LDAP_NO_USER_DN and LDAP_TOO_MANY_USER_DN in constants.php

- LDAP_Model->getUserDN now returns errors with more information
- Login redirection is performed with HTTP code 302 instead of 301
- Fixed _checkHBALDAPAuthentication behavior
- AuthLib errors have more information
This commit is contained in:
Paolo
2019-03-12 16:14:58 +01:00
parent 13db712fa7
commit d1b4024b76
4 changed files with 35 additions and 15 deletions
+19 -12
View File
@@ -227,7 +227,7 @@ class AuthLib
// Prints date and time
$this->_ci->eprintflib->printInfo('Date and time: '.date('Y.m.d H:i:s'));
$this->_ci->loglib->logError($errorMessage);
$this->_ci->loglib->logError($errorMessage); // CI log error
exit; // immediately terminate the execution
}
@@ -301,11 +301,23 @@ class AuthLib
}
elseif (isError($personResult)) // blocking error
{
$hta = $personResult; // return it!
$hta = $personResult; // to be displayed
}
}
return $hta;
// Invalid credentials
// NOTE: this is a corner case because of the HTTP basic authentication
if (getCode($hta) == AUTH_NOT_AUTHENTICATED || getCode($hta) == AUTH_INVALID_CREDENTIALS
|| getCode($hta) == LDAP_NO_USER_DN || getCode($hta) == LDAP_TOO_MANY_USER_DN)
{
$this->_showInvalidAuthentication(); // this also stop the execution
}
elseif (isError($hta)) // display error and stop execution
{
$this->_showError(getData($hta));
}
return $hta; // if success then is returned!
}
/**
@@ -330,7 +342,7 @@ class AuthLib
if (isSuccess($ldapConnection)) // connected!
{
$ldapModel->close(); // close the previous connection
$ldap = success('Authenticated'); // authenticated!
$ldap = success('Authenticated', AUTH_SUCCESS); // authenticated!
}
else // blocking error
{
@@ -354,6 +366,8 @@ class AuthLib
* Tries to find if the user is already logged via a foreign authentication method
* using a list of foreign authentication methods provided with the configurations
* If the user is logged via a foreign authentication method then an authentication object is returned
* NOTE: _checkHBALDAPAuthentication is the last to be called and it is a corner case due the HTTP basic
* authentication mechanism, and it does not return anything
*/
private function _checkForeignAuthentication()
{
@@ -374,13 +388,6 @@ class AuthLib
break;
}
// Invalid credentials
// NOTE: this is a corner case because of the HTTP basic authentication
if (getCode($auth) == AUTH_INVALID_CREDENTIALS)
{
$this->_showInvalidAuthentication(); // this also stop the execution
}
// If not authenticated with this method...
if (getCode($auth) == AUTH_NOT_AUTHENTICATED)
{
@@ -416,7 +423,7 @@ class AuthLib
// If the configuration is valid
if (!isEmptyArray($alp) && isset($alp[$al]))
{
header('HTTP/1.1 301 Moved Permanently'); // permanent redirection
header('HTTP/1.1 302 Moved temporary'); // temporary redirection
header('Location: '.site_url().$alp[$al]); // redirect to the configured login page
exit(); // stops execution!
}