本文整理汇总了PHP中Zend\Ldap\Ldap类的典型用法代码示例。如果您正苦于以下问题:PHP Ldap类的具体用法?PHP Ldap怎么用?PHP Ldap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ldap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reload
/**
* Reload node attributes from LDAP.
*
* This is an online method.
*
* @param \Zend\Ldap\Ldap $ldap
* @return AbstractNode Provides a fluid interface
*/
public function reload(Ldap\Ldap $ldap = null)
{
if ($ldap !== null) {
$data = $ldap->getEntry($this->_getDn(), array('*', '+'), true);
$this->loadData($data, true);
}
return $this;
}
示例2: testSearch
public function testSearch()
{
$baseDn = 'ou=example,dc=org';
$filter = '(&(uid=test_username))';
$attributes = array('uid');
$entry = array('dn' => 'uid=test_username,ou=example,dc=org', 'uid' => array('test_username'));
$expect = array('count' => 1, $entry);
$this->zend = $this->getMockBuilder('Zend\\Ldap\\Ldap')->getMock();
$this->zendLdapDriver = new ZendLdapDriver($this->zend);
$this->zend->expects($this->once())->method('searchEntries')->with($this->equalTo($filter), $this->equalTo($baseDn), $this->equalTo(Ldap::SEARCH_SCOPE_SUB), $this->equalTo($attributes))->will($this->returnValue(array($entry)));
$this->assertEquals($expect, $this->zendLdapDriver->search($baseDn, $filter, $attributes));
}
示例3: factory_ldap
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;
}
示例4: create
/**
* Factory method to create the RootDse.
*
* @param \Zend\Ldap\Ldap $ldap
* @return RootDse
*/
public static function create(Ldap\Ldap $ldap)
{
$dn = Ldap\Dn::fromString('');
$data = $ldap->getEntry($dn, ['*', '+'], true);
if (isset($data['domainfunctionality'])) {
return new RootDse\ActiveDirectory($dn, $data);
} elseif (isset($data['dsaname'])) {
return new RootDse\eDirectory($dn, $data);
} elseif (isset($data['structuralobjectclass']) && $data['structuralobjectclass'][0] === 'OpenLDAProotDSE') {
return new RootDse\OpenLdap($dn, $data);
}
return new static($dn, $data);
}
示例5: create
/**
* Factory method to create the Schema node.
*
* @param \Zend\Ldap\Ldap $ldap
* @return \Zend\Ldap\Node\Schema
* @throws \Zend\Ldap\Exception
*/
public static function create(Ldap\Ldap $ldap)
{
$dn = $ldap->getRootDse()->getSchemaDn();
$data = $ldap->getEntry($dn, array('*', '+'), true);
switch ($ldap->getRootDse()->getServerType()) {
case RootDSE::SERVER_TYPE_ACTIVEDIRECTORY:
return new Schema\ActiveDirectory($dn, $data, $ldap);
case RootDSE::SERVER_TYPE_OPENLDAP:
return new Schema\OpenLdap($dn, $data, $ldap);
case RootDSE::SERVER_TYPE_EDIRECTORY:
default:
return new self($dn, $data, $ldap);
}
}
示例6: 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;
}
示例7: authenticate
/**
* 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: ' . $this->sUser . ' reason is ' . $oExp->getMessage());
}
}
return $oResult;
}
示例8: getLdap
/**
* 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;
}
示例9: rewind
/**
* Rewind the Iterator to the first result item
* Implements Iterator
*
* @throws \Zend\Ldap\Exception
*/
public function rewind()
{
if (is_resource($this->_resultId)) {
$this->_current = @ldap_first_entry($this->_ldap->getResource(), $this->_resultId);
if ($this->_current === false && $this->_ldap->getLastErrorCode() > Ldap\Exception::LDAP_SUCCESS) {
throw new Ldap\Exception($this->_ldap, 'getting first entry');
}
}
}
示例10: testBindUserInterfaceByUsernameSuccessful
public function testBindUserInterfaceByUsernameSuccessful()
{
$username = 'username';
$password = 'password';
$user = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface');
$user->expects($this->once())->method('getUsername')->will($this->returnValue($username));
$this->zend->expects($this->once())->method('bind')->with($this->equalTo($username), $this->equalTo($password))->will($this->returnValue($this->zend));
$this->assertTrue($this->zendLdapDriver->bind($user, $password));
}
示例11: rewind
/**
* Rewind the Iterator to the first result item
* Implements Iterator
*
*
* @throws \Zend\Ldap\Exception\LdapException
*/
public function rewind()
{
if (is_resource($this->resultId)) {
ErrorHandler::start();
$this->current = ldap_first_entry($this->ldap->getResource(), $this->resultId);
ErrorHandler::stop();
if ($this->current === false && $this->ldap->getLastErrorCode() > Exception\LdapException::LDAP_SUCCESS) {
throw new Exception\LdapException($this->ldap, 'getting first entry');
}
}
}
示例12: find
public function find($name, $value, $attr_name)
{
$this->bind();
$filter = "{$attr_name}={$value}";
$base_dn = $this->active_server['baseDn'];
$this->log("Attempting to search for {$name}={$value} using basedn={$base_dn}");
try {
$hm = $this->ldap->search($filter, $base_dn, $this->scope);
$this->log("Raw Ldap Object: " . var_export($hm, true), 7);
if ($hm->count() == 0) {
$this->log("Could not find an account for {$name}={$value}", 5);
return false;
} elseif ($hm->count() > 1) {
$this->log("Found more than one user account for {$name}={$value}", 1);
return false;
}
$this->user = $hm->current();
$this->log("User entry response: " . var_export($this->user, true), 7);
return $this->user;
} catch (LdapException $exc) {
return $exc->getMessage();
}
}
示例13: getAccountDn
/**
* Fix a bug, ex. CN=Alice Baker,CN=Users,DC=example,DC=com
*
* @param string $acctname
* @return string - Account DN
*/
protected function getAccountDn($acctname)
{
$baseDn = $this->getBaseDn();
if ($this->getBindRequiresDn() && isset($baseDn)) {
try {
return parent::getAccountDn($acctname);
} catch (\Zend\Ldap\Exception\LdapException $zle) {
if ($zle->getCode() != \Zend\Ldap\Exception\LdapException::LDAP_NO_SUCH_OBJECT) {
throw $zle;
}
}
$acctname = $this->usernameAttribute . '=' . \Zend\Ldap\Filter\AbstractFilter::escapeValue($acctname) . ',' . $baseDn;
}
return parent::getAccountDn($acctname);
}
示例14: findUnit
private function findUnit(Identity $identity)
{
if (null === $this->unit) {
$filter = Filter::equals('mail', $identity->mail);
$baseDn = Dn::factory($this->ldap->getBaseDn())->prepend(['ou' => 'people']);
$result = $this->ldap->search($filter, $baseDn, Ldap::SEARCH_SCOPE_ONE, ['l']);
if (1 !== $result->count()) {
return;
}
$result = $result->current();
$unitDn = $result['l'][0];
$this->unit = $this->ldap->getNode($unitDn);
}
return $this->unit;
}
示例15: sort
/**
* Sort the iterator
*
* Sorting is done using the set sortFunction which is by default strnatcasecmp.
*
* The attribute is determined by lowercasing everything.
*
* The sort-value will be the first value of the attribute.
*
* @param string $sortAttribute The attribute to sort by. If not given the
* value set via setSortAttribute is used.
*
* @return void
*/
public function sort($sortAttribute)
{
foreach ($this->entries as $key => $entry) {
$attributes = ldap_get_attributes($this->ldap->getResource(), $entry['resource']);
$attributes = array_change_key_case($attributes, CASE_LOWER);
if (isset($attributes[$sortAttribute][0])) {
$this->entries[$key]['sortValue'] = $attributes[$sortAttribute][0];
}
}
$sortFunction = $this->sortFunction;
$sorted = usort($this->entries, function ($a, $b) use($sortFunction) {
return $sortFunction($a['sortValue'], $b['sortValue']);
});
if (!$sorted) {
throw new Exception\LdapException($this, 'sorting result-set');
}
}