<?php require_once 'vendor/autoload.php'; use Symfony\Component\Ldap\Ldap; use Symfony\Component\Ldap\Adapter\ExtLdap\Adapter; $config = ['host' => 'localhost', 'port' => 389]; $dn = 'cn=admin,ou=admins,dc=openldap,dc=com'; $password = '******'; $adapter = new Adapter($config); $adapter->getConnection()->setOption('PROTOCOL_VERSION', 3); $ldap = new Ldap($adapter); $ldap->bind($dn, $password); $filter = 'objectClass=*'; $attributes = ['cn', 'sn', 'uid', 'description']; $query = $ldap->query($dn, 'objectClass=*', ['filter' => $attributes]); $collection = $query->execute(); var_dump('Good!', $collection->toArray());
public function testLdapQueryScopeOneLevel() { $ldap = new Adapter($this->getLdapConfig()); $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); $one_level_result = $ldap->createQuery('ou=Components,dc=symfony,dc=com', '(objectclass=*)', array('scope' => Query::SCOPE_ONE))->execute(); $subtree_count = $ldap->createQuery('ou=Components,dc=symfony,dc=com', '(objectclass=*)')->execute()->count(); $this->assertNotEquals($one_level_result->count(), $subtree_count); $this->assertEquals($one_level_result->count(), 1); $this->assertEquals($one_level_result[0]->getAttribute('ou'), array('Ldap')); }
/** * @group functional */ public function testLdapQuery() { $ldap = new Adapter($this->getLdapConfig()); $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); $query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', array()); $result = $query->execute(); $this->assertInstanceOf(Collection::class, $result); $this->assertCount(1, $result); $entry = $result[0]; $this->assertInstanceOf(Entry::class, $entry); $this->assertEquals(array('Fabien Potencier'), $entry->getAttribute('cn')); $this->assertEquals(array('*****@*****.**', '*****@*****.**'), $entry->getAttribute('mail')); }
protected function setUp() { $this->adapter = new Adapter(array('host' => 'localhost', 'port' => 3389)); $this->adapter->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); }
protected function setUp() { $this->adapter = new Adapter($this->getLdapConfig()); $this->adapter->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); }