Skip to content

Commit

Permalink
Disable Autodetection if getUserIP is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
robin.kluth committed Jan 26, 2024
1 parent f3ea2ff commit 7d781d3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/LdapAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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'];
Expand Down

0 comments on commit 7d781d3

Please sign in to comment.