adldap / adLDAP

adLDAP is a PHP class that provides LDAP authentication and integration with Active Directory.
GNU Lesser General Public License v2.1
424 stars 204 forks source link

$adldap->user()->info($username) - \vendor\adldap\adldap\src\Objects\Ldap\Entry.php:52 - Undefined offset: 4 #127

Closed hNczy closed 7 years ago

hNczy commented 7 years ago

I configurate and connect to ldap before:

$info = $adldap->user()->info($username);

Undefined offset: 4

C:\Users\hNczy\Documents\intranet_vagrant\data\hasznaltauto-intranet\vendor\adldap\adldap\src\Objects\Ldap\Entry.php:52 C:\Users\hNczy\Documents\intranet_vagrant\data\hasznaltauto-intranet\vendor\adldap\adldap\src\Objects\Ldap\Entry.php:32 C:\Users\hNczy\Documents\intranet_vagrant\data\hasznaltauto-intranet\vendor\adldap\adldap\src\Classes\AdldapSearch.php:394 C:\Users\hNczy\Documents\intranet_vagrant\data\hasznaltauto-intranet\vendor\adldap\adldap\src\Classes\AdldapSearch.php:437 C:\Users\hNczy\Documents\intranet_vagrant\data\hasznaltauto-intranet\vendor\adldap\adldap\src\Classes\AdldapSearch.php:98 C:\Users\hNczy\Documents\intranet_vagrant\data\hasznaltauto-intranet\vendor\adldap\adldap\src\Classes\AdldapSearch.php:111 C:\Users\hNczy\Documents\intranet_vagrant\data\hasznaltauto-intranet\vendor\adldap\adldap\src\Classes\AdldapSearch.php:169 C:\Users\hNczy\Documents\intranet_vagrant\data\hasznaltauto-intranet\vendor\adldap\adldap\src\Classes\AdldapUsers.php:86 C:\Users\hNczy\Documents\intranet_vagrant\data\hasznaltauto-intranet\vendor\adldap\adldap\src\Classes\AbstractAdldapQueryable.php:115 C:\Users\hNczy\Documents\intranet_vagrant\data\hasznaltauto-intranet\tests\unit\AdldapTest.php:75

The $attributes[$key] is:

(
    [count] => 4
    [0] => top
    [1] => person
    [2] => organizationalPerson
    [3] => user
)

my test code is:


    protected function _before()
    {
        $this->adldapOptions = array(
            'base_dn' => 'DC=hasznaltauto,DC=local',
            'account_suffix' => '@hasznaltauto.local',
            'domain_controllers' => array('***.***.***.***'), 
            'admin_username' => 'someusername',
            'admin_password' => 'somepassword',
            'user_id_key' => 'samaccountname',
            'person_filter' => array('category' => 'objectCategory', 'person' => 'person'),
            'real_primarygroup' => true,
            'use_ssl' => false,
            'use_tls' => false,
            'recursive_groups' => true,
            'ad_port' => '389',
            'sso' => false, );

    }

    /**
     * @depends testAuthentication
     */
    public function testGetGroups()
    {
        $adldap = new Adldap($this->adldapOptions);
        $username = getenv('TEST_LDAP_USER');
        $password = getenv('TEST_LDAP_PASS');
        codecept_debug($username);
        codecept_debug($password);
        if ($adldap->authenticate($username, $password))
        {
            $info = $adldap->user()->info($username); // This is C:\Users\hNczy\Documents\intranet_vagrant\data\hasznaltauto-intranet\tests\unit\AdldapTest.php:75
            codecept_debug($info);
            $groups = $adldap->user()->groups($username);
            codecept_debug($groups);
        } else {
            $this->fail('Authentication faild');
        }
    }
mdevoldere commented 7 years ago

in src/Objects/Ldap/Entry.php, at line (52)

i added a condition before $data[] = $attributes[$key][$i];

i replaced

$data[] = $attributes[$key][$i];

by if(array_key_exists($i, $attributes[$key])) { $data[] = $attributes[$key][$i]; }

it works :)

stevebauman commented 7 years ago

Hey guys, just letting you know this repository is based on old code from Adldap2 located here:

https://github.com/Adldap2/Adldap2

This repository is very unlikely to be patched.