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:
commit
009b544f41
@ -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);
|
|
||||||
}
|
|
@ -44,6 +44,22 @@ final class LdapClient implements LdapClientInterface
|
|||||||
$this->ldap->bind($dn, $password);
|
$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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -21,9 +21,9 @@ namespace Symfony\Component\Ldap;
|
|||||||
*
|
*
|
||||||
* @deprecated You should use LdapInterface instead
|
* @deprecated You should use LdapInterface instead
|
||||||
*/
|
*/
|
||||||
interface LdapClientInterface extends BaseLdapInterface
|
interface LdapClientInterface extends LdapInterface
|
||||||
{
|
{
|
||||||
/*
|
/**
|
||||||
* Find a username into ldap connection.
|
* Find a username into ldap connection.
|
||||||
*
|
*
|
||||||
* @param string $dn
|
* @param string $dn
|
||||||
|
@ -13,17 +13,28 @@ namespace Symfony\Component\Ldap;
|
|||||||
|
|
||||||
use Symfony\Component\Ldap\Adapter\EntryManagerInterface;
|
use Symfony\Component\Ldap\Adapter\EntryManagerInterface;
|
||||||
use Symfony\Component\Ldap\Adapter\QueryInterface;
|
use Symfony\Component\Ldap\Adapter\QueryInterface;
|
||||||
|
use Symfony\Component\Ldap\Exception\ConnectionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ldap interface.
|
* Ldap interface.
|
||||||
*
|
*
|
||||||
* @author Charles Sarrazin <charles@sarraz.in>
|
* @author Charles Sarrazin <charles@sarraz.in>
|
||||||
*/
|
*/
|
||||||
interface LdapInterface extends BaseLdapInterface
|
interface LdapInterface
|
||||||
{
|
{
|
||||||
const ESCAPE_FILTER = 0x01;
|
const ESCAPE_FILTER = 0x01;
|
||||||
const ESCAPE_DN = 0x02;
|
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.
|
* Queries a ldap server for entries matching the given criteria.
|
||||||
*
|
*
|
||||||
@ -39,4 +50,15 @@ interface LdapInterface extends BaseLdapInterface
|
|||||||
* @return EntryManagerInterface
|
* @return EntryManagerInterface
|
||||||
*/
|
*/
|
||||||
public function getEntryManager();
|
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);
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,16 @@ class LdapClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->client->escape('foo', 'bar', 'baz');
|
$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()
|
public function testLdapFind()
|
||||||
{
|
{
|
||||||
$collection = $this->getMock(CollectionInterface::class);
|
$collection = $this->getMock(CollectionInterface::class);
|
||||||
|
Reference in New Issue
Block a user