From 92fd606df3a41ad924ce7dba565ab0b203354713 Mon Sep 17 00:00:00 2001 From: Danny Su Date: Sun, 5 Aug 2012 18:11:45 -0400 Subject: [PATCH] Allow custom LDAP port Summary: Allow custom LDAP port to be defined in config file Test Plan: Test login works by specifying a custom port Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3153 --- conf/default.conf.php | 3 +++ .../auth/ldap/PhabricatorLDAPProvider.php | 20 +++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/conf/default.conf.php b/conf/default.conf.php index e3746a857a..8130bb85dc 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -627,6 +627,9 @@ return array( // The LDAP server hostname 'ldap.hostname' => '', + // The LDAP server port + 'ldap.port' => 389, + // The LDAP base domain name 'ldap.base_dn' => '', diff --git a/src/applications/auth/ldap/PhabricatorLDAPProvider.php b/src/applications/auth/ldap/PhabricatorLDAPProvider.php index f203af44a1..0d98d2beef 100644 --- a/src/applications/auth/ldap/PhabricatorLDAPProvider.php +++ b/src/applications/auth/ldap/PhabricatorLDAPProvider.php @@ -42,6 +42,10 @@ final class PhabricatorLDAPProvider { return PhabricatorEnv::getEnvConfig('ldap.hostname'); } + public function getPort() { + return PhabricatorEnv::getEnvConfig('ldap.port'); + } + public function getBaseDN() { return PhabricatorEnv::getEnvConfig('ldap.base_dn'); } @@ -57,7 +61,7 @@ final class PhabricatorLDAPProvider { public function getLDAPVersion() { return PhabricatorEnv::getEnvConfig('ldap.version'); } - + public function getLDAPReferrals() { return PhabricatorEnv::getEnvConfig('ldap.referrals'); } @@ -78,7 +82,7 @@ final class PhabricatorLDAPProvider { if (is_array($name_attributes)) { foreach ($name_attributes AS $attribute) { if (isset($data[$attribute][0])) { - $real_name .= $data[$attribute][0] . ' '; + $real_name .= $data[$attribute][0].' '; } } @@ -100,16 +104,16 @@ final class PhabricatorLDAPProvider { public function getConnection() { if (!isset($this->connection)) { - $this->connection = ldap_connect($this->getHostname()); + $this->connection = ldap_connect($this->getHostname(), $this->getPort()); if (!$this->connection) { - throw new Exception('Could not connect to LDAP host at ' . - $this->getHostname()); + throw new Exception('Could not connect to LDAP host at '. + $this->getHostname().':'.$this->getPort()); } ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $this->getLDAPVersion()); - ldap_set_option($this->connection, LDAP_OPT_REFERRALS, + ldap_set_option($this->connection, LDAP_OPT_REFERRALS, $this->getLDAPReferrals()); } @@ -150,7 +154,7 @@ final class PhabricatorLDAPProvider { PhabricatorEnv::getEnvConfig('ldap.activedirectory_domain'); if ($activeDirectoryDomain) { - $dn = $username . '@' . $activeDirectoryDomain; + $dn = $username.'@'.$activeDirectoryDomain; } else { $dn = ldap_sprintf( '%Q=%s,%Q', @@ -198,7 +202,7 @@ final class PhabricatorLDAPProvider { } if ($entries['count'] > 1) { - throw new Exception('Found more then one user with this ' . + throw new Exception('Found more then one user with this '. $attribute); }