Replace call for Logger with DI::logger() in ldapauth addon
parent
5d51c5b56e
commit
a488f25131
|
@ -30,7 +30,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
use Friendica\Core\Logger;
|
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
|
@ -69,54 +68,54 @@ function ldapauth_authenticate($username, $password)
|
||||||
$ldap_autocreateaccount_nameattribute = DI::config()->get('ldapauth', 'ldap_autocreateaccount_nameattribute');
|
$ldap_autocreateaccount_nameattribute = DI::config()->get('ldapauth', 'ldap_autocreateaccount_nameattribute');
|
||||||
|
|
||||||
if (!extension_loaded('ldap') || !strlen($ldap_server)) {
|
if (!extension_loaded('ldap') || !strlen($ldap_server)) {
|
||||||
Logger::error('Addon not configured or missing php-ldap extension', ['extension_loaded' => extension_loaded('ldap'), 'server' => $ldap_server]);
|
DI::logger()->error('Addon not configured or missing php-ldap extension', ['extension_loaded' => extension_loaded('ldap'), 'server' => $ldap_server]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strlen($password)) {
|
if (!strlen($password)) {
|
||||||
Logger::error('Empty password disallowed', ['provided_password_length' => strlen($password)]);
|
DI::logger()->error('Empty password disallowed', ['provided_password_length' => strlen($password)]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$connect = @ldap_connect($ldap_server);
|
$connect = @ldap_connect($ldap_server);
|
||||||
if ($connect === false) {
|
if ($connect === false) {
|
||||||
Logger::warning('Could not connect to LDAP server', ['server' => $ldap_server]);
|
DI::logger()->warning('Could not connect to LDAP server', ['server' => $ldap_server]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
|
@ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||||
@ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
|
@ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
|
||||||
if ((@ldap_bind($connect, $ldap_binddn, $ldap_bindpw)) === false) {
|
if ((@ldap_bind($connect, $ldap_binddn, $ldap_bindpw)) === false) {
|
||||||
Logger::warning('Could not bind to LDAP server', ['server' => $ldap_server, 'binddn' => $ldap_binddn, 'errno' => ldap_errno($connect), 'error' => ldap_error($connect)]);
|
DI::logger()->warning('Could not bind to LDAP server', ['server' => $ldap_server, 'binddn' => $ldap_binddn, 'errno' => ldap_errno($connect), 'error' => ldap_error($connect)]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = @ldap_search($connect, $ldap_searchdn, $ldap_userattr . '=' . $username);
|
$res = @ldap_search($connect, $ldap_searchdn, $ldap_userattr . '=' . $username);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
Logger::notice('LDAP user not found.', ['searchdn' => $ldap_searchdn, 'userattr' => $ldap_userattr, 'username' => $username, 'errno' => ldap_errno($connect), 'error' => ldap_error($connect)]);
|
DI::logger()->notice('LDAP user not found.', ['searchdn' => $ldap_searchdn, 'userattr' => $ldap_userattr, 'username' => $username, 'errno' => ldap_errno($connect), 'error' => ldap_error($connect)]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = @ldap_first_entry($connect, $res);
|
$id = @ldap_first_entry($connect, $res);
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
Logger::notice('Could not retrieve first LDAP entry.', ['searchdn' => $ldap_searchdn, 'userattr' => $ldap_userattr, 'username' => $username, 'errno' => ldap_errno($connect), 'error' => ldap_error($connect)]);
|
DI::logger()->notice('Could not retrieve first LDAP entry.', ['searchdn' => $ldap_searchdn, 'userattr' => $ldap_userattr, 'username' => $username, 'errno' => ldap_errno($connect), 'error' => ldap_error($connect)]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dn = @ldap_get_dn($connect, $id);
|
$dn = @ldap_get_dn($connect, $id);
|
||||||
if (!@ldap_bind($connect, $dn, $password)) {
|
if (!@ldap_bind($connect, $dn, $password)) {
|
||||||
Logger::notice('Could not authenticate LDAP user with provided password', ['errno' => ldap_errno($connect), 'error' => ldap_error($connect)]);
|
DI::logger()->notice('Could not authenticate LDAP user with provided password', ['errno' => ldap_errno($connect), 'error' => ldap_error($connect)]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($ldap_group) && @ldap_compare($connect, $ldap_group, 'member', $dn) !== true) {
|
if (strlen($ldap_group) && @ldap_compare($connect, $ldap_group, 'member', $dn) !== true) {
|
||||||
$errno = @ldap_errno($connect);
|
$errno = @ldap_errno($connect);
|
||||||
if ($errno === 32) {
|
if ($errno === 32) {
|
||||||
Logger::notice('LDAP Access Control Group does not exist', ['errno' => $errno, 'error' => ldap_error($connect)]);
|
DI::logger()->notice('LDAP Access Control Group does not exist', ['errno' => $errno, 'error' => ldap_error($connect)]);
|
||||||
} elseif ($errno === 16) {
|
} elseif ($errno === 16) {
|
||||||
Logger::notice('LDAP membership attribute does not exist in access control group', ['errno' => $errno, 'error' => ldap_error($connect)]);
|
DI::logger()->notice('LDAP membership attribute does not exist in access control group', ['errno' => $errno, 'error' => ldap_error($connect)]);
|
||||||
} else {
|
} else {
|
||||||
Logger::notice('LDAP user isn\'t part of the authorized group', ['dn' => $dn]);
|
DI::logger()->notice('LDAP user isn\'t part of the authorized group', ['dn' => $dn]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ldap_close($connect);
|
@ldap_close($connect);
|
||||||
|
@ -140,7 +139,7 @@ function ldapauth_authenticate($username, $password)
|
||||||
$authentication = User::getAuthenticationInfo($username);
|
$authentication = User::getAuthenticationInfo($username);
|
||||||
return User::getById($authentication['uid']);
|
return User::getById($authentication['uid']);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Logger::notice('LDAP authentication error: ' . $e->getMessage());
|
DI::logger()->notice('LDAP authentication error: ' . $e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +147,7 @@ function ldapauth_authenticate($username, $password)
|
||||||
function ldap_createaccount($username, $password, $email, $name)
|
function ldap_createaccount($username, $password, $email, $name)
|
||||||
{
|
{
|
||||||
if (!strlen($email) || !strlen($name)) {
|
if (!strlen($email) || !strlen($name)) {
|
||||||
Logger::notice('Could not create local user from LDAP data, no email or nickname provided');
|
DI::logger()->notice('Could not create local user from LDAP data, no email or nickname provided');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,10 +159,10 @@ function ldap_createaccount($username, $password, $email, $name)
|
||||||
'password' => $password,
|
'password' => $password,
|
||||||
'verified' => 1
|
'verified' => 1
|
||||||
]);
|
]);
|
||||||
Logger::info('Local user created from LDAP data', ['username' => $username, 'name' => $name]);
|
DI::logger()->info('Local user created from LDAP data', ['username' => $username, 'name' => $name]);
|
||||||
return $user;
|
return $user;
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
Logger::error('Could not create local user from LDAP data', ['username' => $username, 'exception' => $ex->getMessage()]);
|
DI::logger()->error('Could not create local user from LDAP data', ['username' => $username, 'exception' => $ex->getMessage()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue