public function LdapUserConf::drupalUserToLdapEntry in Lightweight Directory Access Protocol (LDAP) 7.2
Same name and namespace in other branches
- 8.2 ldap_user/LdapUserConf.class.php \LdapUserConf::drupalUserToLdapEntry()
Populate ldap entry array for provisioning.
Parameters
array $account: drupal account.
\LdapServer $ldap_server:
array $ldap_user: ldap entry of user, returned by reference.
array $params: with the following key values: 'ldap_context' => 'module' => module calling function, e.g. 'ldap_user' 'function' => function calling function, e.g. 'provisionLdapEntry' 'include_count' => should 'count' array key be included 'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY || LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER.
Return value
array(ldap entry, $result) in ldap extension array format.!THIS IS NOT THE ACTUAL LDAP ENTRY
3 calls to LdapUserConf::drupalUserToLdapEntry()
- LdapUserConf::getProvisionRelatedLdapEntry in ldap_user/
LdapUserConf.class.php - Given a drupal account, find the related ldap entry.
- LdapUserConf::provisionLdapEntry in ldap_user/
LdapUserConf.class.php - Given a drupal account, provision an ldap entry if none exists. if one exists do nothing.
- LdapUserConf::synchToLdapEntry in ldap_user/
LdapUserConf.class.php - Given a drupal account, synch to related ldap entry.
File
- ldap_user/
LdapUserConf.class.php, line 959
Class
Code
public function drupalUserToLdapEntry($account, $ldap_server, $params, $ldap_user_entry = NULL) {
$provision = isset($params['function']) && $params['function'] == 'provisionLdapEntry';
$result = LDAP_USER_PROV_RESULT_NO_ERROR;
if (!$ldap_user_entry) {
$ldap_user_entry = [];
}
if (!is_object($account) || !is_object($ldap_server)) {
return [
NULL,
LDAP_USER_PROV_RESULT_BAD_PARAMS,
];
}
$watchdog_tokens = [
'%drupal_username' => $account->name,
];
$include_count = isset($params['include_count']) && $params['include_count'];
$direction = isset($params['direction']) ? $params['direction'] : LDAP_USER_PROV_DIRECTION_ALL;
$prov_events = empty($params['prov_events']) ? ldap_user_all_events() : $params['prov_events'];
$mappings = $this
->getSynchMappings($direction, $prov_events);
foreach ($mappings as $field_key => $field_detail) {
list($ldap_attr_name, $ordinal, $conversion) = ldap_servers_token_extract_parts($field_key, TRUE);
$ordinal = !$ordinal ? 0 : $ordinal;
if ($ldap_user_entry && isset($ldap_user_entry[$ldap_attr_name]) && is_array($ldap_user_entry[$ldap_attr_name]) && isset($ldap_user_entry[$ldap_attr_name][$ordinal])) {
// don't override values passed in.
continue;
}
$synched = $this
->isSynched($field_key, $params['prov_events'], LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY);
if ($synched) {
$token = $field_detail['user_attr'] == 'user_tokens' ? $field_detail['user_tokens'] : $field_detail['user_attr'];
$value = ldap_servers_token_replace($account, $token, 'user_account');
// Deal with empty/unresolved password.
if (substr($token, 0, 10) == '[password.' && (!$value || $value == $token)) {
if (!$provision) {
// don't overwrite password on synch if no value provided.
continue;
}
}
if ($ldap_attr_name == 'dn' && $value) {
$ldap_user_entry['dn'] = $value;
}
elseif ($value) {
if (!isset($ldap_user_entry[$ldap_attr_name]) || !is_array($ldap_user_entry[$ldap_attr_name])) {
$ldap_user_entry[$ldap_attr_name] = [];
}
$ldap_user_entry[$ldap_attr_name][$ordinal] = $value;
if ($include_count) {
$ldap_user_entry[$ldap_attr_name]['count'] = count($ldap_user_entry[$ldap_attr_name]);
}
}
}
}
/**
* 4. call drupal_alter() to allow other modules to alter $ldap_user
*/
$params['account'] = $account;
drupal_alter('ldap_entry', $ldap_user_entry, $params);
return [
$ldap_user_entry,
$result,
];
}