-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Ldap] Improving the LDAP component #17560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Improved the Ldap Component
* 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
commit 81cb79b10a0a9f6fa0e40e225bb9bd48310d025f
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 <[email protected]> | ||
* | ||
* 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 <[email protected]> | ||
*/ | ||
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 hidden or 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 <[email protected]> | ||
* | ||
* 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 <[email protected]> | ||
*/ | ||
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 hidden or 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 <[email protected]> | ||
* | ||
* 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 <[email protected]> | ||
*/ | ||
interface AdapterInterface | ||
{ | ||
/** | ||
* Returns the current connection. | ||
* | ||
* @return ConnectionInterface | ||
*/ | ||
public function getConnection(); | ||
|
||
/** | ||
* Creates a new Query. | ||
* | ||
* @param $dn | ||
* @param $query | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing |
||
* @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 hidden or 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 <[email protected]> | ||
* | ||
* 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 <[email protected]> | ||
*/ | ||
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 hidden or 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 <[email protected]> | ||
* | ||
* 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 <[email protected]> | ||
*/ | ||
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 hidden or 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 <[email protected]> | ||
* | ||
* 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 <[email protected]> | ||
*/ | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this? And why three seconds? This looks like it may cause wrong build failure reports in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slapd is run in the background. Also, this ensures that the daemon is started before the test are run. We could remove this, but tests may be flaky.