You are here

public function ServerFactory::getUserDataFromServerByIdentifier in Lightweight Directory Access Protocol (LDAP) 8.3

Fetch user data from server by Identifier.

Parameters

string $identifier: User identifier.

string $id: Server id.

Return value

array|bool Result data or false.

1 call to ServerFactory::getUserDataFromServerByIdentifier()
ServerFactory::getUserDataFromServerByAccount in ldap_servers/src/ServerFactory.php
Fetch user data from server by user account.

File

ldap_servers/src/ServerFactory.php, line 113

Class

ServerFactory
Helper class to working with the Server classes.

Namespace

Drupal\ldap_servers

Code

public function getUserDataFromServerByIdentifier($identifier, $id) {

  // Try to retrieve the user from the cache.
  $cache = $this->cache
    ->get('ldap_servers:user_data:' . $identifier);
  if ($cache && $cache->data) {
    return $cache->data;
  }
  $server = $this
    ->getServerByIdEnabled($id);
  if (!$server) {
    $this->logger
      ->error('Failed to load server object %sid in _ldap_servers_get_user_ldap_data', [
      '%sid' => $id,
    ]);
    return FALSE;
  }
  $ldap_user = $server
    ->matchUsernameToExistingLdapEntry($identifier);
  if ($ldap_user) {
    $ldap_user['id'] = $id;
    $cache_expiry = 5 * 60 + time();
    $cache_tags = [
      'ldap',
      'ldap_servers',
      'ldap_servers.user_data',
    ];
    $this->cache
      ->set('ldap_servers:user_data:' . $identifier, $ldap_user, $cache_expiry, $cache_tags);
  }
  return $ldap_user;
}