Skip to content

[Ldap] Allow search scoping #20310

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

Closed
wants to merge 2 commits into from
Closed

[Ldap] Allow search scoping #20310

wants to merge 2 commits into from

Conversation

xunto
Copy link
Contributor

@xunto xunto commented Oct 26, 2016

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

Quite trivial, PR adds "scope" attribute to the query options. For example:

    public function ldapAction()
    {
        $ldap = $this->get("app.ldap");
        $dn = $this->getParameter("dn");

        $results = $ldap->query($dn, "(objectClass=*)", [
            "scope" => Query::SCOPE_ONELEVEL
        ])->execute();

        foreach ($results as $entry) {
            var_dump($entry->getDn()); echo "<br/>";
        }

        return new Response("");
    }

SCOPE_BASE: http://php.net/manual/ru/function.ldap-read.php
SCOPE_ONELEVEL: http://php.net/manual/ru/function.ldap-list.php
SCOPE_SUBTREE: http://php.net/manual/ru/function.ldap-search.php

@xunto
Copy link
Contributor Author

xunto commented Oct 27, 2016

I need to further tell that without this change ldap is almost unusable in some cases.

For example, to build a tree of departments, you need to search in SCOPE_ONELEVEL but you can't (without this PR).

My dirty workaround is to look at length of entry's dn to understand if this is sub-department (cn is uuid, so it has fixed size). This is very dirty and unreliable solution.

@xunto
Copy link
Contributor Author

xunto commented Nov 1, 2016

Why does nobody look at this PR (it's week already)? @csarrazi marked as author in https://github.com/symfony/ldap. Should I contact him?

@csarrazi
Copy link
Contributor

csarrazi commented Nov 1, 2016

@xunto I do not receive notifications unless I am explicitly tagged in a comment.

Copy link
Contributor

@csarrazi csarrazi left a comment

Choose a reason for hiding this comment

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

Just change the constant values to strings instead of integers, and this is LGTM. I've considered doing this a while ago, but it got out of my mind. Thanks @xunto!

@@ -23,6 +23,10 @@
const DEREF_FINDING = 0x02;
const DEREF_ALWAYS = 0x03;

const SCOPE_BASE = 0x00;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not use integer constants here unless they are actually part of the specification. Here, please use string values.

I.e.

const SCOPE_BASE = 'base';
const SCOPE_ONELEVEL = 'one_level';
const SCOPE_SUBTREE = 'subtree';

@csarrazi
Copy link
Contributor

csarrazi commented Nov 1, 2016

One thing though, please also add functional tests for the scope handling.

$func = 'ldap_list';
break;
case static::SCOPE_SUBTREE:
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

The default should actually throw an exception (which should actually never be thrown, as the OptionsResolver is actually the one which sanitizes the scope option) instead of being a fall-through for the subtree scope.

Copy link
Contributor Author

@xunto xunto Nov 2, 2016

Choose a reason for hiding this comment

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

@csarrazi actually I already defined allowed values in option OptionsResolver (c6c47ae#diff-822ec15d626e08f71c9ebaea383b5a89R40). So default is only for linter.

Copy link
Contributor

@csarrazi csarrazi Nov 2, 2016

Choose a reason for hiding this comment

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

Okay. So throw an exception in the default, and set $func to ldap_search in the SCOPE_SUBTREE case. :)

'scope' => Query::SCOPE_SUBTREE,
))->execute()->count();

$this->assertNotEquals($one_level, $subtree);
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not feel that this tests anything useful (Apart from checking that a one level scope is different from a subtree). We should actually check whether we have the expected content in the output from the test.

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'm working on it right now)


dn: cn=Scope,cn=Ldap,ou=Components,dc=symfony,dc=com
objectclass: organizationalunit
cn: Scopes
Copy link
Contributor

Choose a reason for hiding this comment

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

Add newline to end of file.

@xunto
Copy link
Contributor Author

xunto commented Nov 2, 2016

I apologise for big amount of commits. My distro have different paths for openldap so I can't run tests on my computer.

@csarrazi
Copy link
Contributor

csarrazi commented Nov 2, 2016

@xunto No problem, as long as you squash everything later! ;)

You could also use the csarrazi/symfony-ldap docker repository, if you want to easily spawn an openldap instance, btw!

@xunto
Copy link
Contributor Author

xunto commented Nov 2, 2016

@csarrazi Everything should be ok now. Thanks for review. I going to squash it right now.

@csarrazi
Copy link
Contributor

csarrazi commented Nov 2, 2016

You're welcome!

@xunto
Copy link
Contributor Author

xunto commented Nov 2, 2016

@csarrazi done

@xunto
Copy link
Contributor Author

xunto commented Nov 2, 2016

Oh, didn't noticed yout anwser about default in switch/case. Give me a minute...

@xunto
Copy link
Contributor Author

xunto commented Nov 2, 2016

@csarrazi Everything is done. Tests pass.

@csarrazi
Copy link
Contributor

csarrazi commented Nov 2, 2016

👍

@xunto
Copy link
Contributor Author

xunto commented Nov 3, 2016

@csarrazi Should I slap deciders or mergers now?

@csarrazi
Copy link
Contributor

csarrazi commented Nov 3, 2016

Yup! :)

@xunto
Copy link
Contributor Author

xunto commented Nov 3, 2016

@csarrazi Thanks for help! @symfony/deciders, it's your turn!

@fabpot
Copy link
Member

fabpot commented Nov 3, 2016

Just for your information, this new feature won't be merged for 3.2, but considered for 3.3.

@xunto
Copy link
Contributor Author

xunto commented Nov 3, 2016

@fabpot Sad but ok, I think.

So it won't get into the master until 3.2 is released? So, in december.

@fabpot
Copy link
Member

fabpot commented Nov 3, 2016

Right, that's correct.

@xabbuh
Copy link
Member

xabbuh commented Nov 5, 2016

👍

@javiereguiluz javiereguiluz added this to the 3.3 milestone Nov 6, 2016
@csarrazi
Copy link
Contributor

Hey @xunto! Sorry for getting back one more time. Could you just amend your PR and change the scope names so they respect RFC 2255? ("base" / "one" / "sub").

See https://tools.ietf.org/html/rfc2255

The scope construct is used to specify the scope of the search to
perform in the given LDAP server. The allowable scopes are "base"
for a base object search, "one" for a one-level search, or "sub" for
a subtree search. If scope is omitted, a scope of "base" is assumed.

That would be great! :)

@xunto
Copy link
Contributor Author

xunto commented Nov 14, 2016

@csarrazi Ok, will do.

@xunto
Copy link
Contributor Author

xunto commented Nov 15, 2016

@csarrazi done.

@xunto
Copy link
Contributor Author

xunto commented Dec 2, 2016

@symfony/deciders, 3.2 is released. Looks like now we can merge this.

@fabpot
Copy link
Member

fabpot commented Dec 4, 2016

Thank you @xunto.

@fabpot fabpot closed this Dec 4, 2016
fabpot added a commit that referenced this pull request Dec 4, 2016
This PR was squashed before being merged into the 3.3-dev branch (closes #20310).

Discussion
----------

[Ldap] Allow search scoping

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

Quite trivial, PR adds "scope" attribute to the query options. For example:

```php
    public function ldapAction()
    {
        $ldap = $this->get("app.ldap");
        $dn = $this->getParameter("dn");

        $results = $ldap->query($dn, "(objectClass=*)", [
            "scope" => Query::SCOPE_ONELEVEL
        ])->execute();

        foreach ($results as $entry) {
            var_dump($entry->getDn()); echo "<br/>";
        }

        return new Response("");
    }
```

SCOPE_BASE: http://php.net/manual/ru/function.ldap-read.php
SCOPE_ONELEVEL: http://php.net/manual/ru/function.ldap-list.php
SCOPE_SUBTREE: http://php.net/manual/ru/function.ldap-search.php

Commits
-------

83c7915 [Ldap] Allow search scoping
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
@fabpot fabpot mentioned this pull request May 1, 2017
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.

7 participants