public function Connect() { $connected = false; $attempts = 0; $hosts = $this->options->Controllers(); $options = $this->options->AdLdapOptions(); while (!$connected && $attempts < count($hosts)) { try { $host = $hosts[$attempts]; Log::Debug('ActiveDirectory - Trying to connect to host %s', $host); $options['domain_controllers'] = array($host); $attempts++; $this->ldap = new adLdap($options); $connected = true; if ($connected) { Log::Debug('ActiveDirectory - Connection succeeded to host %s', $host); } else { Log::Debug('ActiveDirectory - Connection failed to host %s. Reason %s', $host, $this->ldap->getLastError()); } } catch (adLDAPException $ex) { Log::Error($ex); throw $ex; } } return $connected; }
public function testGetAllHosts() { $controllers = 'localhost, localhost.2'; $configFile = new FakeConfigFile(); $configFile->SetKey(ActiveDirectoryConfig::DOMAIN_CONTROLLERS, $controllers); $this->fakeConfig->SetFile(ActiveDirectoryConfig::CONFIG_ID, $configFile); $options = new ActiveDirectoryOptions(); $this->assertEquals(array('localhost', 'localhost.2'), $options->Controllers(), "comma separated values should become array"); }