You are here

public function Server::deriveUsernameFromLdapResponse in Lightweight Directory Access Protocol (LDAP) 8.4

Returns the username from the LDAP entry.

Parameters

\Symfony\Component\Ldap\Entry $ldap_entry: The LDAP entry.

Return value

string The user name.

Overrides ServerInterface::deriveUsernameFromLdapResponse

File

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

Class

Server
Defines the Server entity.

Namespace

Drupal\ldap_servers\Entity

Code

public function deriveUsernameFromLdapResponse(Entry $ldap_entry) : string {
  $accountName = '';
  if ($this
    ->getAccountNameAttribute()) {
    if ($ldap_entry
      ->hasAttribute($this
      ->getAccountNameAttribute(), FALSE)) {
      $accountName = $ldap_entry
        ->getAttribute($this
        ->getAccountNameAttribute(), FALSE)[0];
    }
  }
  elseif ($this
    ->getAuthenticationNameAttribute()) {
    if ($ldap_entry
      ->hasAttribute($this
      ->getAuthenticationNameAttribute(), FALSE)) {
      $accountName = $ldap_entry
        ->getAttribute($this
        ->getAuthenticationNameAttribute(), FALSE)[0];
    }
  }
  return $accountName;
}