protected function setUp() { if (!constant('TESTS_ZEND_LDAP_ONLINE_ENABLED')) { $this->markTestSkipped("Zend_Ldap online tests are not enabled"); } $options = array('host' => TESTS_ZEND_LDAP_HOST, 'username' => TESTS_ZEND_LDAP_USERNAME, 'password' => TESTS_ZEND_LDAP_PASSWORD, 'baseDn' => TESTS_ZEND_LDAP_WRITEABLE_SUBTREE); if (defined('TESTS_ZEND_LDAP_PORT') && TESTS_ZEND_LDAP_PORT != 389) { $options['port'] = TESTS_ZEND_LDAP_PORT; } if (defined('TESTS_ZEND_LDAP_USE_START_TLS')) { $options['useStartTls'] = TESTS_ZEND_LDAP_USE_START_TLS; } if (defined('TESTS_ZEND_LDAP_USE_SSL')) { $options['useSsl'] = TESTS_ZEND_LDAP_USE_SSL; } if (defined('TESTS_ZEND_LDAP_BIND_REQUIRES_DN')) { $options['bindRequiresDn'] = TESTS_ZEND_LDAP_BIND_REQUIRES_DN; } if (defined('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT')) { $options['accountFilterFormat'] = TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT; } if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME')) { $options['accountDomainName'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME; } if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT')) { $options['accountDomainNameShort'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT; } $this->ldap = new Ldap\Ldap($options); $this->ldap->bind(); }
/** * {@inheritDoc} */ public function bind(UserInterface $user, $password) { if ($user instanceof LdapUserInterface && $user->getDn()) { $bind_rdn = $user->getDn(); } else { $bind_rdn = $user->getUsername(); } try { $this->logDebug(sprintf('ldap_bind(%s, ****)', $bind_rdn)); $bind = $this->driver->bind($bind_rdn, $password); return $bind instanceof Ldap; } catch (ZendLdapException $exception) { $this->zendExceptionHandler($exception); } return false; }
/** * Returns Zend LDAP * * @return \Zend\Ldap\Ldap */ public function getLdap() { if ($this->_ldap === null) { $options = array('host' => Yii::$app->getModule('user')->settings->get('auth.ldap.hostname'), 'port' => Yii::$app->getModule('user')->settings->get('auth.ldap.port'), 'username' => Yii::$app->getModule('user')->settings->get('auth.ldap.username'), 'password' => Yii::$app->getModule('user')->settings->get('auth.ldap.password'), 'useStartTls' => Yii::$app->getModule('user')->settings->get('auth.ldap.encryption') == 'tls', 'useSsl' => Yii::$app->getModule('user')->settings->get('auth.ldap.encryption') == 'ssl', 'bindRequiresDn' => true, 'baseDn' => Yii::$app->getModule('user')->settings->get('auth.ldap.baseDn'), 'accountFilterFormat' => Yii::$app->getModule('user')->settings->get('auth.ldap.loginFilter')); $this->_ldap = new \Zend\Ldap\Ldap($options); $this->_ldap->bind(); } return $this->_ldap; }
public function bind() { $options = $this->config; /* We will try to loop through the list of servers * if no active servers are available then we will use the error msg */ foreach ($options as $server) { $this->log("Attempting bind with ldap"); try { $this->ldap = new ZendLdap($server); $this->ldap->bind(); $this->log("Bind successful setting active server."); $this->active_server = $server; } catch (LdapException $exc) { $this->error[] = $exc->getMessage(); continue; } } }
public function factory_ldap(ServiceManager $sm) { $config = $sm->get('Config'); $ldapConfig = $config['ldap']; try { $ldap = new Ldap($ldapConfig); $ldap->bind($ldapConfig['username'], $ldapConfig['password']); } catch (LdapException $e) { Debug::dump($e->getMessage()); die; } return $ldap; }
/** * Authenticate a login request against ldap. * * @return \Application\Model\Zend\Ldap\Exception\LdapException|boolean */ public function authenticate() { $multiOptions = $this->getConfiguration(); $ldap = new Ldap(); foreach ($multiOptions as $options) { $ldap->setOptions($options); try { $ldap->bind($this->sFullIdentity, $this->sPass); $oResult = new Result(Result::SUCCESS, $this->sUser, array('Account is authenticate')); break; } catch (\Zend\Ldap\Exception\LdapException $oExp) { $oResult = new Result(Result::FAILURE_CREDENTIAL_INVALID, $this->sUser, array($oExp->getMessage())); $this->log('Could not authenticate user: '******' reason is ' . $oExp->getMessage()); } } return $oResult; }
public function testMismatchDomainBind() { $ldap = new Ldap\Ldap($this->options); try { $ldap->bind('BOGUS\\doesntmatter', 'doesntmatter'); $this->fail('Expected exception not thrown'); } catch (Exception\LdapException $zle) { $this->assertTrue($zle->getCode() == Exception\LdapException::LDAP_X_DOMAIN_MISMATCH); } }
/** * @group ZF-8259 */ public function testBoundUserIsReturnedAfterBinding() { $ldap = new Ldap\Ldap($this->_options); $ldap->bind(); $this->assertEquals(TESTS_ZEND_LDAP_USERNAME, $ldap->getBoundUser()); }
public function getComputers($computerService) { $domain = $this->options['accountDomainName']; $ldap = new Ldap($this->options); $ldap->bind(); $result = $ldap->search('(&(objectCategory=computer))', 'dc=wr,dc=local', Ldap::SEARCH_SCOPE_SUB); foreach ($result as $item) { if ($item['name'][0] != '') { $hostname = $item['name'][0]; $computer = $computerService->findByDNSName($hostname, $domain); if (!$computer) { $computer = new Computer(); $computerService->setType($computer, 'Computer'); $computerService->setStatus($computer, 'In Use'); $computerService->setManufacturer($computer, 'Dell'); $computer->setHostname($hostname)->setDomain($domain); } // Operating system if (array_key_exists('operatingsystem', $item)) { $computer->setOsName($item['operatingsystem'][0]); } // Operating system service pack if (array_key_exists('operatingsystemservicepack', $item)) { $computer->setOsServicePack($item['operatingsystemservicepack'][0]); } // Operating system version. if (array_key_exists('operatingsystemversion', $item)) { $computer->setOsVersion($item['operatingsystemversion'][0]); } // die(var_dump($computer->getStatus())); $computerService->persist($computer); } } }