LdapBundle icon indicating copy to clipboard operation
LdapBundle copied to clipboard

Support proper case of user attributes

Open johnkary opened this issue 11 years ago • 1 comments

Currently when the LDAP user's record is retrieved from the LDAP directory all the attribute names come back as lower-case.

So if my LDAP provider exposes an attribute named displayName, the attribute is returned from LDAP as displayname. This causes issues when configuring the bundle's imag_ldap.user.attributes array:

# app/config/security.yml
imag_ldap:
    user:
        attributes: ['displayName']
$user = $this->get('security.context')->getToken()->getUser();
$user->getAttribute('displayName'); // returns null

I did a little poking around to isolate the issue and it stems from how users are being searched for in LdapConnection::search().

Currently ldap_get_entries() is used to find entries, but when those entries are returned, all attributes are returned in lower-case. According to the PHP manual's page for ldap_get_entries this is expected behavior for this function:

http://php.net/manual/en/function.ldap-get-entries.php The attribute index is converted to lowercase. (Attributes are case-insensitive for directory servers, but not when used as array indices.)

This is a bit weird on PHP's behalf because the similar function ldap_get_attributes() returns attributes with proper casing.

The current workaround is to define all attributes in security.yml as lower-case:

# app/config/security.yml
imag_ldap:
    user:
        attributes: ['displayname']
$user->getAttribute('displayname'); // returns "John Kary"

Ideally I would like to see the bundle support defining and exposing attributes in a case-sensitive manner. So that an attribute exposed as displayName by the LDAP directory is accessible via $user->getAttribute('displayName')

johnkary avatar May 14 '13 19:05 johnkary

Yes i will seeing how can I implement ldap_get_attributes function.

BorisMorel avatar Jun 25 '13 08:06 BorisMorel