Skip to content

[LDAP] Check whether an entry attribute exists #18492

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 1 commit into from
Apr 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Symfony/Component/Ldap/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ public function getDn()
return $this->dn;
}

/**
* Returns whether an attribute exists.
*
* @param $name string The name of the attribute
*
* @return bool
*/
public function hasAttribute($name)
{
return isset($this->attributes[$name]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure, but we may need to check whether the value is actually null or not.

Could you try running real-world tests with some empty LDAP attributes, to see whether this behaves correctly or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using a real world (though fake data) LDAP octet stream of length zero, internally the entry contains a value which is an empty PHP string. As far as I can find any non-existing attributes do not return in the entry, and null values get converted to empty strings.

Output:

// var_dump($entry)
object(Symfony\Component\Ldap\Entry)#23 (2) {
  ["dn":"Symfony\Component\Ldap\Entry":private]=>
  string(34) "uid=john2,ou=People,dc=localdomain"
  ["attributes":"Symfony\Component\Ldap\Entry":private]=>
  array(21) {
    ["objectClass"]=>
    array(4) {
      ["count"]=>
      int(3)
      [0]=>
      string(13) "inetOrgPerson"
      [1]=>
      string(12) "posixAccount"
      [2]=>
      string(13) "shadowAccount"
    }
    [0]=>
    string(11) "objectClass"
    ["uid"]=>
    array(2) {
      ["count"]=>
      int(1)
      [0]=>
      string(5) "john2"
    }
    ...
    [6]=>
    string(9) "gidNumber"
    ["gecos"]=>
    array(2) {
      ["count"]=>
      int(1)
      [0]=>
      string(0) ""
    }
    [7]=>
    string(5) "gecos"
    ["loginShell"]=>
    array(2) {
      ["count"]=>
      int(1)
      [0]=>
      string(9) "/bin/bash"
    }
    [8]=>
    string(10) "loginShell"
    ["homeDirectory"]=>
    array(2) {
      ["count"]=>
      int(1)
      [0]=>
      string(10) "/home/john"
    }
    [9]=>
    string(13) "homeDirectory"
    ["count"]=>
    int(10)
  }
}

// var_dump($entry->hasAttibute('gecos'))
bool(true)

// var_dump($entry->getAttribute('gecos'))
array(2) {
  ["count"]=>
  int(1)
  [0]=>
  string(0) ""
}

So there should be no problem, because empty strings return an isset of true.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

}

/**
* Returns a specific attribute's value.
*
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy