You are here

function hook_ldap_convert_to_local_alter in LDAP integration 6

Called when an existing ldap user is converted back to a normal Drupal user. This is called before the account is saved to remove ldapauth specific user properties.

Parameters

Array $data The Array of account properties to remove or add from: user object. This should only be added or modified, not recreated..

User $account The account with all it's ldap properties included,: e.g. $account->ldap_dn, $account->ldap_conf, etc.

1 function implements hook_ldap_convert_to_local_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

ldapgroups_ldap_convert_to_local_alter in ./ldapgroups.module
Implementation of hook_ldap_convert_to_local_alter().
1 invocation of hook_ldap_convert_to_local_alter()
ldapauth_user_to_local_user in ./ldapauth.admin.inc
Page callback function to convert a user from an LDAP authenticated user to a normal drupal user.

File

./ldapauth.api.php, line 130
LDAPAuth API function documentation

Code

function hook_ldap_convert_to_local_alter(&$data, $account) {

  // Some example code to show how to remove a custom account property
  // and alter the ldap user entry.
  // remove the ldap_myprop property from account
  $data['ldap_myprop'] = NULL;

  // Get LDAP connection and alter user LDAP entry
  $ldap = _ldapauth_init($account->ldap_config);
  if (!$ldap) {
    return;
  }

  // If there is no bindn and bindpw - the connect will be an anonymous connect.
  $success = $ldap
    ->connect($ldap
    ->getOption('binddn'), $ldap
    ->getOption('bindpw'));
  if (!$success) {
    watchdog('ldapauth', "Failed to connect to ldap.", array(), WATCHDOG_ERROR);
    return;
  }
  $attributes = array(
    'someAttribute' => '',
  );

  // delete someAttribute
  $ldap
    ->writeAttributes($account->ldap_dn, $attributes);
  $ldap
    ->disconnect();
}