bug #18076 [Ldap] Add forward compatibility layer (csarrazi)

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
This commit is contained in:
Nicolas Grekas 2016-03-16 18:10:29 +01:00
commit 009b544f41
5 changed files with 51 additions and 51 deletions

View File

@ -1,48 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Ldap;
use Symfony\Component\Ldap\Exception\ConnectionException;
/**
* Base Ldap interface.
*
* This interface is here for reusability in the BC layer,
* and will be merged in LdapInterface in Symfony 4.0.
*
* @author Charles Sarrazin <charles@sarraz.in>
*
* @internal
*/
interface BaseLdapInterface
{
/**
* 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);
/**
* 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);
}

View File

@ -44,6 +44,22 @@ final class LdapClient implements LdapClientInterface
$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}
*/

View File

@ -21,9 +21,9 @@ namespace Symfony\Component\Ldap;
*
* @deprecated You should use LdapInterface instead
*/
interface LdapClientInterface extends BaseLdapInterface
interface LdapClientInterface extends LdapInterface
{
/*
/**
* Find a username into ldap connection.
*
* @param string $dn

View File

@ -13,17 +13,28 @@ namespace Symfony\Component\Ldap;
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.
*
@ -39,4 +50,15 @@ interface LdapInterface extends BaseLdapInterface
* @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);
}

View File

@ -54,6 +54,16 @@ class LdapClientTest extends \PHPUnit_Framework_TestCase
$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);