Skip to content

Commit

Permalink
bug #18076 [Ldap] Add forward compatibility layer (csarrazi)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.1-dev branch.

Discussion
----------

[Ldap] Add forward compatibility layer

| Q             | A
| ------------- | ---
| Branch        | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

This PR adds forward-compatibility for the use of the Ldap component within the Security component. Indeed, currently, if one uses the `Symfony\Component\Ldap\LdapClient` class and upgrades to the `master` branch of `symfony/symfony`, the Security component will break as the class does not implement `LdapInterface`.

This PR fixes this.

This means that from now on, the `master` branch of the Ldap component should be compatible with all versions of the Security component. The 2.8/3.0 Security component should be compatible with all versions of the Ldap component, and the 3.1 Security component should be compatible with versions 3.1 onwards of the Ldap component.

Commits
-------

97d9cee Improved BC layer for the Ldap component
  • Loading branch information
nicolas-grekas committed Mar 16, 2016
2 parents 728bb0f + 97d9cee commit 009b544
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 51 deletions.
48 changes: 0 additions & 48 deletions src/Symfony/Component/Ldap/BaseLdapInterface.php

This file was deleted.

16 changes: 16 additions & 0 deletions src/Symfony/Component/Ldap/LdapClient.php
Expand Up @@ -44,6 +44,22 @@ public function bind($dn = null, $password = null)
$this->ldap->bind($dn, $password);
}

/**
* {@inheritdoc}
*/
public function query($dn, $query, array $options = array())
{
return $this->ldap->query($dn, $query, $options);
}

/**
* {@inheritdoc}
*/
public function getEntryManager()
{
return $this->ldap->getEntryManager();
}

/**
* {@inheritdoc}
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Ldap/LdapClientInterface.php
Expand Up @@ -21,9 +21,9 @@
*
* @deprecated You should use LdapInterface instead
*/
interface LdapClientInterface extends BaseLdapInterface
interface LdapClientInterface extends LdapInterface
{
/*
/**
* Find a username into ldap connection.
*
* @param string $dn
Expand Down
24 changes: 23 additions & 1 deletion src/Symfony/Component/Ldap/LdapInterface.php
Expand Up @@ -13,17 +13,28 @@

use Symfony\Component\Ldap\Adapter\EntryManagerInterface;
use Symfony\Component\Ldap\Adapter\QueryInterface;
use Symfony\Component\Ldap\Exception\ConnectionException;

/**
* Ldap interface.
*
* @author Charles Sarrazin <charles@sarraz.in>
*/
interface LdapInterface extends BaseLdapInterface
interface LdapInterface
{
const ESCAPE_FILTER = 0x01;
const ESCAPE_DN = 0x02;

/**
* Return a connection bound to the ldap.
*
* @param string $dn A LDAP dn
* @param string $password A password
*
* @throws ConnectionException If dn / password could not be bound.
*/
public function bind($dn = null, $password = null);

/**
* Queries a ldap server for entries matching the given criteria.
*
Expand All @@ -39,4 +50,15 @@ public function query($dn, $query, array $options = array());
* @return EntryManagerInterface
*/
public function getEntryManager();

/**
* Escape a string for use in an LDAP filter or DN.
*
* @param string $subject
* @param string $ignore
* @param int $flags
*
* @return string
*/
public function escape($subject, $ignore = '', $flags = 0);
}
10 changes: 10 additions & 0 deletions src/Symfony/Component/Ldap/Tests/LdapClientTest.php
Expand Up @@ -54,6 +54,16 @@ public function testLdapEscape()
$this->client->escape('foo', 'bar', 'baz');
}

public function testLdapQuery()
{
$this->ldap
->expects($this->once())
->method('query')
->with('foo', 'bar', array('baz'))
;
$this->client->query('foo', 'bar', array('baz'));
}

public function testLdapFind()
{
$collection = $this->getMock(CollectionInterface::class);
Expand Down

0 comments on commit 009b544

Please sign in to comment.