function ldap_user_get_authname in Lightweight Directory Access Protocol (LDAP) 7.2
Returns LDAP authname from the authmap table for a variant input.
Parameters
$data: A variant input. Allowed variable types:
- object: user account object
- string: username
Return value
string|null Returns the LDAP authname of the passed Drupal user.
5 calls to ldap_user_get_authname()
- hook_user_ldap_servers_username_to_ldapname_alter in ldap_servers/
ldap_servers.api.php - Allows other modules to transform the Drupal login username to an LDAP UserName attribute. Invoked in LdapServer::userUsernameToLdapNameTransform()
- ldap_authentication_ldap_authenticated in ldap_authentication/
ldap_authentication.module - Determines if the passed user has a valid authmap record.
- ldap_servers_get_user_ldap_data in ldap_servers/
ldap_servers.module - @todo needs caching element. several modules could potentially call this in the same page request.
- ldap_user_is_ldap_associated in ldap_user/
ldap_user.module - ldap_user_ldap_servers_username_to_ldapname_alter in ldap_user/
ldap_user.module - Implements hook_ldap_servers_username_to_ldapname_alter
1 string reference to 'ldap_user_get_authname'
- ldap_servers_get_user_ldap_data in ldap_servers/
ldap_servers.module - @todo needs caching element. several modules could potentially call this in the same page request.
File
- ldap_user/
ldap_user.module, line 1238 - Module for the LDAP User Entity.
Code
function ldap_user_get_authname($data) {
$cache =& drupal_static(__FUNCTION__, []);
$authname = NULL;
$uid = NULL;
if (is_object($data)) {
// Object - set uid if object has uid and uid > 0.
if (!empty($data->uid)) {
$uid = $data->uid;
}
}
else {
// String - load account and set uid if uid > 0.
$account = user_load_by_name($data);
if (!empty($account->uid)) {
$uid = $account->uid;
}
}
// Exit if no uid found.
if (empty($uid)) {
return NULL;
}
// Run query if uid is not statically cached.
if (!array_key_exists($uid, $cache)) {
$authname = db_query('SELECT authname FROM {authmap} WHERE uid = :uid AND module = :module', [
':uid' => $uid,
':module' => 'ldap_user',
])
->fetchField();
$cache[$uid] = !empty($authname) ? $authname : NULL;
}
return $cache[$uid];
}