-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Moved connection logic to dedicated class * Added support for Ldap result entries iterator and renamed LdapClient to Ldap * Added support for multiple adapters * Attempt anonymous bind if the connection is not bound beforehand * Finalized API * Updated the Security component to use v3.1 of the Ldap component * Updated unit tests * Added support for functional tests * Updated README file
- Loading branch information
Showing
35 changed files
with
1,136 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?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\Adapter; | ||
|
||
use Symfony\Component\OptionsResolver\Options; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Charles Sarrazin <charles@sarraz.in> | ||
*/ | ||
abstract class AbstractConnection implements ConnectionInterface | ||
{ | ||
protected $config; | ||
|
||
public function __construct(array $config = array()) | ||
{ | ||
$resolver = new OptionsResolver(); | ||
$resolver->setDefaults(array( | ||
'host' => null, | ||
'port' => 389, | ||
'version' => 3, | ||
'useSsl' => false, | ||
'useStartTls' => false, | ||
'optReferrals' => false, | ||
)); | ||
$resolver->setNormalizer('host', function (Options $options, $value) { | ||
if ($value && $options['useSsl']) { | ||
return 'ldaps://'.$value; | ||
} | ||
|
||
return $value; | ||
}); | ||
|
||
$this->config = $resolver->resolve($config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?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\Adapter; | ||
|
||
use Symfony\Component\OptionsResolver\Options; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Charles Sarrazin <charles@sarraz.in> | ||
*/ | ||
abstract class AbstractQuery implements QueryInterface | ||
{ | ||
protected $connection; | ||
protected $dn; | ||
protected $query; | ||
protected $options; | ||
|
||
public function __construct(ConnectionInterface $connection, $dn, $query, array $options = array()) | ||
{ | ||
$resolver = new OptionsResolver(); | ||
$resolver->setDefaults(array( | ||
'filter' => '*', | ||
'maxItems' => 0, | ||
'sizeLimit' => 0, | ||
'timeout' => 0, | ||
'deref' => static::DEREF_NEVER, | ||
'attrsOnly' => 0, | ||
)); | ||
$resolver->setAllowedValues('deref', array(static::DEREF_ALWAYS, static::DEREF_NEVER, static::DEREF_FINDING, static::DEREF_SEARCHING)); | ||
$resolver->setNormalizer('filter', function (Options $options, $value) { | ||
return is_array($value) ? $value : array($value); | ||
}); | ||
|
||
$this->connection = $connection; | ||
$this->dn = $dn; | ||
$this->query = $query; | ||
$this->options = $resolver->resolve($options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?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\Adapter; | ||
|
||
/** | ||
* @author Charles Sarrazin <charles@sarraz.in> | ||
*/ | ||
interface AdapterInterface | ||
{ | ||
/** | ||
* Returns the current connection. | ||
* | ||
* @return ConnectionInterface | ||
*/ | ||
public function getConnection(); | ||
|
||
/** | ||
* Creates a new Query. | ||
* | ||
* @param $dn | ||
* @param $query | ||
* @param array $options | ||
* | ||
* @return QueryInterface | ||
*/ | ||
public function createQuery($dn, $query, array $options = array()); | ||
|
||
/** | ||
* 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); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Symfony/Component/Ldap/Adapter/CollectionInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?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\Adapter; | ||
|
||
use Symfony\Component\Ldap\Entry; | ||
|
||
/** | ||
* @author Charles Sarrazin <charles@sarraz.in> | ||
*/ | ||
interface CollectionInterface extends \Countable, \IteratorAggregate, \ArrayAccess | ||
{ | ||
/** | ||
* @return Entry[] | ||
*/ | ||
public function toArray(); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Symfony/Component/Ldap/Adapter/ConnectionInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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\Adapter; | ||
|
||
/** | ||
* @author Charles Sarrazin <charles@sarraz.in> | ||
*/ | ||
interface ConnectionInterface | ||
{ | ||
/** | ||
* Checks whether the connection was already bound or not. | ||
* | ||
* @return bool | ||
*/ | ||
public function isBound(); | ||
|
||
/** | ||
* Binds the connection against a DN and password. | ||
* | ||
* @param string $dn The user's DN | ||
* @param string $password The associated password | ||
*/ | ||
public function bind($dn = null, $password = null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?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\Adapter\ExtLdap; | ||
|
||
use Symfony\Component\Ldap\Adapter\AdapterInterface; | ||
use Symfony\Component\Ldap\Exception\LdapException; | ||
|
||
/** | ||
* @author Charles Sarrazin <charles@sarraz.in> | ||
*/ | ||
class Adapter implements AdapterInterface | ||
{ | ||
private $config; | ||
private $connection; | ||
|
||
public function __construct(array $config = array()) | ||
{ | ||
if (!extension_loaded('ldap')) { | ||
throw new LdapException('The LDAP PHP extension is not enabled.'); | ||
} | ||
|
||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getConnection() | ||
{ | ||
if (null === $this->connection) { | ||
$this->connection = new Connection($this->config); | ||
} | ||
|
||
return $this->connection; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createQuery($dn, $query, array $options = array()) | ||
{ | ||
return new Query($this->getConnection(), $dn, $query, $options); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function escape($subject, $ignore = '', $flags = 0) | ||
{ | ||
$value = ldap_escape($subject, $ignore, $flags); | ||
|
||
// Per RFC 4514, leading/trailing spaces should be encoded in DNs, as well as carriage returns. | ||
if ((int) $flags & LDAP_ESCAPE_DN) { | ||
if (!empty($value) && $value[0] === ' ') { | ||
$value = '\\20'.substr($value, 1); | ||
} | ||
if (!empty($value) && $value[strlen($value) - 1] === ' ') { | ||
$value = substr($value, 0, -1).'\\20'; | ||
} | ||
$value = str_replace("\r", '\0d', $value); | ||
} | ||
|
||
return $value; | ||
} | ||
} |
Oops, something went wrong.