Example #1
0
 public function Connect()
 {
     Log::Debug('Trying to connect to LDAP');
     $this->ldap = Net_LDAP2::connect($this->options->Ldap2Config());
     if (PEAR::isError($this->ldap)) {
         $message = 'Could not connect to LDAP server. Check your settings in Ldap.config.php : ' . $this->ldap->getMessage();
         Log::Error($message);
         throw new Exception($message);
     }
     return true;
 }
Example #2
0
 public function testConstructsOptionsCorrectly()
 {
     $hosts = 'localhost, localhost.2';
     $port = '389';
     $binddn = 'cn=admin,ou=users,dc=example,dc=org';
     $password = '******';
     $base = 'dc=example,dc=org';
     $starttls = 'false';
     $version = '3';
     $configFile = new FakeConfigFile();
     $configFile->SetKey(LdapConfig::HOST, $hosts);
     $configFile->SetKey(LdapConfig::PORT, $port);
     $configFile->SetKey(LdapConfig::BINDDN, $binddn);
     $configFile->SetKey(LdapConfig::BINDPW, $password);
     $configFile->SetKey(LdapConfig::BASEDN, $base);
     $configFile->SetKey(LdapConfig::STARTTLS, $starttls);
     $configFile->SetKey(LdapConfig::VERSION, $version);
     $this->fakeConfig->SetFile(LdapConfig::CONFIG_ID, $configFile);
     $ldapOptions = new LdapOptions();
     $options = $ldapOptions->Ldap2Config();
     $this->assertNotNull($this->fakeConfig->_RegisteredFiles[LdapConfig::CONFIG_ID]);
     $this->assertEquals('localhost', $options['host'][0], 'domain_controllers must be an array');
     $this->assertEquals(intval($port), $options['port'], 'port should be int');
     $this->assertEquals($binddn, $options['binddn']);
     $this->assertEquals($password, $options['bindpw']);
     $this->assertEquals($base, $options['basedn']);
     $this->assertEquals(false, $options['starttls']);
     $this->assertEquals(intval($version), $options['version'], "version should be int");
 }