Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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 2 commits into from
Feb 14, 2016
Merged

[Ldap] Improving the LDAP component #17560

merged 2 commits into from
Feb 14, 2016

Conversation

csarrazi
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? yes
Deprecations? no
Tests pass? no
Fixed tickets #14602
License MIT
Doc PR not yet

This PR will address a few issues mentioned in #14602.

  • Integrate the Config component in order to simplify the client's configuration
  • Separate Connection handling from the Client
  • Support for multiple drivers
  • Add functional tests
  • Update Security component

public function __construct(array $config = array())
{
if (!extension_loaded('ldap')) {
throw new LdapException('The ldap module is needed.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change this error message by something like: The ldap PHP extension is not enabled ?

@ChadSikorra
Copy link
Contributor

Is support for paging planned to be implemented in the query? For many corporate LDAP implementations a max page size is enforced as a best practice, and large queries will fail without paging.

However, I guess adding that might be a bit cumbersome as paging support for LDAP was added in PHP 5.4 and the min requirement for this component is 5.3.

@csarrazi
Copy link
Contributor Author

There's no issue with supporting paging, especially as version 3.0 of Symfony only supports PHP 5.5+. Thus, we could implement this.

However, I won't support this right now, but maybe in a later PR.

The goal of this PR is to be able to make the component more flexible, and make the correct abstractions, so different implementations can be used (using the PHP extension, for example). This way, we could support a userland ldap client, or even third-party libraries to provide such capability.

'maxItems' => 0,
'sizeLimit' => 0,
'timeout' => 0,
'deref' => LDAP_DEREF_NEVER,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constants should be moved in QueryInterface.

@csarrazi
Copy link
Contributor Author

By the way, as this PR breaks compatibility, the code from the Security component will be updated in another PR.

@csarrazi csarrazi changed the title Improving the LDAP component [Ldap] Improving the LDAP component Jan 27, 2016
@csarrazi csarrazi changed the title [Ldap] Improving the LDAP component [Ldap] [RFR] Improving the LDAP component Jan 28, 2016
@csarrazi csarrazi changed the title [Ldap] [RFR] Improving the LDAP component [Ldap] [WIP] Improving the LDAP component Jan 28, 2016
@csarrazi csarrazi changed the title [Ldap] [WIP] Improving the LDAP component [Ldap] [RFR] Improving the LDAP component Feb 5, 2016
@csarrazi
Copy link
Contributor Author

csarrazi commented Feb 5, 2016

Ping @fabpot @nicolas-grekas

This PR is now stable, and a functional tests have been bootstrapped.

@csarrazi csarrazi changed the title [Ldap] [RFR] Improving the LDAP component [Ldap] Improving the LDAP component Feb 5, 2016
@csarrazi
Copy link
Contributor Author

csarrazi commented Feb 5, 2016

The only build failing is the Appveyor build, as the CI does not have a LDAP server.

Does anyone have a solution?

@csarrazi
Copy link
Contributor Author

csarrazi commented Feb 5, 2016

For now, I'm disabling the ldap extension for the Windows build. The component will be unsupported on Windows, until we have a way to run functional tests on the platform.

/**
* @author Charles Sarrazin <[email protected]>
*/
final class LdapFactory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this class for? I would remove it altogether as it does not add anything useful AFAICS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class is simply a shorthand way to create the Ldap class. Indeed, otherwise, you need to manually inject the adapter (and other configuration). This is basically to improve DX.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we don't have any other such classes anywhere in Symfony. So, I would remove it for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will merge the static method in the Ldap class. The idea was to have something like PropertyAccess::createPropertyAccessor().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


$this->connection = null;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it possible to keep this class for BC and proxy to the new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. What I will do:

  • create a LdapClient class, implementing LdapClientInterface and wrapping the Ldap class.
  • create a backward-compatible constructor initializing a Ldap instance.
  • move the find() method from the Ldap class to the LdapClient class.

* 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
@csarrazi
Copy link
Contributor Author

All done!

It seems some tests fail because of VarDumper.

@csarrazi
Copy link
Contributor Author

@fabpot
Copy link
Member

fabpot commented Feb 12, 2016

👍

@fabpot
Copy link
Member

fabpot commented Feb 14, 2016

Thank you @csarrazi.

@fabpot fabpot merged commit 34d3c85 into symfony:master Feb 14, 2016
fabpot added a commit that referenced this pull request Feb 14, 2016
This PR was merged into the 3.1-dev branch.

Discussion
----------

[Ldap] Improving the LDAP component

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | #14602
| License       | MIT
| Doc PR        | not yet

This PR will address a few issues mentioned in #14602.

* [x] Integrate the Config component in order to simplify the client's configuration
* [x] Separate Connection handling from the Client
* [x] Support for multiple drivers
* [x] Add functional tests
* [x] Update Security component

Commits
-------

34d3c85 Added compatibility layer for previous version of the Security component
81cb79b Improved the Ldap Component
@@ -48,6 +50,11 @@ before_install:
- if [[ $deps != skip ]]; then composer self-update; fi;
- if [[ $deps != skip ]]; then ./phpunit install; fi;
- export PHPUNIT=$(readlink -f ./phpunit)
- mkdir /tmp/slapd
- slapd -f src/Symfony/Component/Ldap/Tests/Fixtures/conf/slapd.conf -h ldap://localhost:3389 &
- sleep 3
Copy link
Member

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.

Copy link
Contributor Author

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.

@csarrazi csarrazi deleted the feat-improve-ldap branch February 14, 2016 19:49
@fabpot fabpot mentioned this pull request May 13, 2016
fabpot added a commit that referenced this pull request Jun 29, 2016
This PR was merged into the 3.1 branch.

Discussion
----------

[Security] Allow LDAP loadUser override

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

Back to 3.0, one could extend `Symfony\Component\Security\Core\User\LdapUserProvider` and override how User objects are created.
Among several improvements, #17560 changed `loadUser` signature but also visibility to `private` which disallow any overriding.
Even if the signature BC break is legitimate, we should still be able to override this method IMHO, which is not possible with a private visibility.
This PRs introduces a `protected` visibility to allow again overriding.

Commits
-------

ae99aa8 [Security] Allow LDAP loadUser override
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants