Ejemplo n.º 1
1
<?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());
Ejemplo n.º 2
0
 /**
  * @Then /^The "(?P<objectclass>[^"]+)" with cn "(?P<cn>[^"]+)" should exist in Ldap$/
  */
 public function theObjectclassWithCnShouldExistInLdap($objectclass, $cn)
 {
     if (is_null($results = $this->client->query($this->rootDn, '(cn=' . $cn . ')')->execute())) {
         throw new \Exception('Unknow entry cn=' . $cn . ' in Ldap');
     }
     $results = $results->toArray();
     if ($results[0]->getAttribute('objectclass')[0] != $objectclass) {
         throw new \Exception('The entry cn=' . $cn . ' is not a ' . $objectclass . ' (' . $results[0]->getAttribute('objectclass')[0] . ')');
     }
 }
Ejemplo n.º 3
0
 public function testLdapQuery()
 {
     $this->adapter->expects($this->once())->method('createQuery')->with('foo', 'bar', array('baz'));
     $this->ldap->query('foo', 'bar', array('baz'));
 }