ShMaunder / JMapMyLDAP

LDAP Integration for Joomla! 2.5+
shmanic.com/tools/jmapmyldap
26 stars 19 forks source link

Sync Issue with name #42

Open kirancheema opened 9 years ago

kirancheema commented 9 years ago

Hi I think there may be an issue with the sync of the name field.

I have an LDAP cron set up. I have the authentication adapter active and the profile adapter active.

The profile adapter is set to sync Name = pull only & email = pull only

I thought that these should Sync when the user logs in and when the LDAP_CRON.php is run?

However the Name field doesn't seem to be updating when the CLI script is run.

I have manually run the script from the CLI and the only way to update the name is to remove the user and the run the cli script again..

Is that right? have i missed something? does the name not sync on cli cron?

the other thing that i noticed is that when i manually run the cli i get the following error notice.

Notice: Trying to get property of non-object in C:\UniServer\www\sandbox\scwcsu\ libraries\shmanic\user\adapters\ldap.php on line 566

which is the getFullname function ...

kirancheema commented 9 years ago

I have tried 2.0.2 and 2.0.3 still happening?

kirancheema commented 9 years ago

Update on this issue..

Ldap-profile plugin - enabled.

Sync on login yes

Allow push - YES (also tried with No)

Sync name - pull only Sync e-mail - pull only

I'm also using the Profile fields

I have "discovered" that Ldap_cron will update the profile fields but not the name and e-mail fields

name & email Will only Sync on login ... is that how it is supposed to be?

kirancheema commented 9 years ago

so having investigated further there is definitely an issue with the getFullname(); function in users\adapters\Ldap.php

profile.php calls $adapter->getFullname(); in Function updateMandatory();

which is returning empty and not updating the jUser object

it is failing on $key = $this->client->keyName; line 566;

I'm not sure where that is going but if someone can point me in the right direction that would be grand,

does $this->client = new SHLdap() ? or SHLdap::getInstance();

not sure if this is an issue with getEmail as well?

kirancheema commented 9 years ago

actually this change seemed to make it work, don't know if it is the right thing to do but it updates the name on cron sync ....

public function getFullname($key = false, $default = null)
    {
        if ($key)
        {
            // Only return the key id
            $this->getId(false);

            return $this->client->keyName;
        }
        $this->client = SHLdap::getInstance(
                    $this->domain, array(
                        'authenticate' => SHLdap::AUTH_PROXY)
                );
        // Find the Ldap attribute name key
        $key = $this->client->keyName;

        if ($value = $this->getAttributes($key))
        {
            if (isset($value[$key][0]))
            {
                // Fullname found so lets return it
                return $value[$key][0];
            }
        }

        return $default;
    }
jbrailas commented 7 months ago

If we place print_r($this->client) in line 3 before "if ($key)" then we can see that attribute keyName doesn't exist. Now if we place print_r("fullname is " . $this->client->ldap_fullname); then it will output the key name which is "name" according to switch of the public function __get($name) in ldap\ldap.php file. Using the cron sync $this->client is null, so we must check for null value. The full code of the function is:

public function getFullname($key = false, $default = null) {
    if (is_null($this->client))
        $this->client = SHLdap::getInstance(
                $this->domain, array(
                    'authenticate' => SHLdap::AUTH_PROXY)
        );

    if ($key) {
        // Only return the key id
        $this->getId(false);
        return $this->client->keyName;
    }

    // Find the Ldap attribute name key
    if (!is_null($this->client->keyName))
        $key = $this->client->keyName;
    else
        $key = $this->client->ldap_fullname;

    if ($value = $this->getAttributes($key))    {
        if (isset($value[$key][0]))     {
            // Fullname found so lets return it
            return $value[$key][0];
        }
    }
    return $default;
}