You are here

public function Server::userAccountFromPuid in Lightweight Directory Access Protocol (LDAP) 8.3

Fetches the user account based on the persistent UID.

Parameters

string $puid: As returned from ldap_read or other LDAP function (can be binary).

Return value

bool|User The updated user or error.

File

ldap_servers/src/Entity/Server.php, line 1005

Class

Server
Defines the Server entity.

Namespace

Drupal\ldap_servers\Entity

Code

public function userAccountFromPuid($puid) {
  $query = \Drupal::entityQuery('user');
  $query
    ->condition('ldap_user_puid_sid', $this
    ->id(), '=')
    ->condition('ldap_user_puid', $puid, '=')
    ->condition('ldap_user_puid_property', $this
    ->get('unique_persistent_attr'), '=')
    ->accessCheck(FALSE);
  $result = $query
    ->execute();
  if (!empty($result)) {
    if (count($result) == 1) {
      return User::load(array_values($result)[0]);
    }
    else {
      $uids = implode(',', $result);
      $this->logger
        ->error('Multiple users (uids: %uids) with same puid (puid=%puid, sid=%sid, ldap_user_puid_property=%ldap_user_puid_property)', [
        '%uids' => $uids,
        '%puid' => $puid,
        '%id' => $this
          ->id(),
        '%ldap_user_puid_property' => $this
          ->get('unique_persistent_attr'),
      ]);
      return FALSE;
    }
  }
  else {
    return FALSE;
  }
}