From 7d781d36c8b8d2a7f6b9d8fb884ae7e55ea00215 Mon Sep 17 00:00:00 2001 From: "robin.kluth" Date: Fri, 26 Jan 2024 07:50:02 +0100 Subject: [PATCH] Disable Autodetection if getUserIP is not available --- src/LdapAuth.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/LdapAuth.php b/src/LdapAuth.php index d5c3c59..cc8b6a7 100644 --- a/src/LdapAuth.php +++ b/src/LdapAuth.php @@ -131,6 +131,11 @@ private function serviceping($host, $port = 389, $timeout = 5) public function autoDetect($overrideIp = false) { + if (!isset(Yii::$app->request) || !method_exists(Yii::$app->request, 'getUserIP')) { + Yii::debug("[Autodetect] Skipping autodetection: No getUserIP method found!", __METHOD__); + return 0; + } + Yii::debug('[Autodetect] Started IP autodetection!', __METHOD__); if (count($this->domains) <= 1) { @@ -191,6 +196,9 @@ public function login($username, $password, $domainKey = false, $fetchUserDN = f $firstArrayKey = !$userDNSearch ? false : array_key_first($userDNSearch); + Yii::debug("userDNSearch result:", __METHOD__); + Yii::debug($userDNSearch, __METHOD__); + if ($userDNSearch && count($userDNSearch) == 1 && $firstArrayKey) { Yii::debug("Overwrite username " . $username . " to " . $userDNSearch[$firstArrayKey]['dn'], __METHOD__); $this->_curDn = $username = $userDNSearch[$firstArrayKey]['dn'];