You are here

function simple_ldap_sso_login_shutdown in Simple LDAP 7.2

Same name and namespace in other branches
  1. 7 simple_ldap_sso/simple_ldap_sso.module \simple_ldap_sso_login_shutdown()

Shutdown function.

Sets the cookie with data from the sessions table, and store the session ID on LDAP.

1 string reference to 'simple_ldap_sso_login_shutdown'
simple_ldap_sso_user_login in simple_ldap_sso/simple_ldap_sso.module
Implements hook_user_login().

File

simple_ldap_sso/simple_ldap_sso.module, line 128

Code

function simple_ldap_sso_login_shutdown() {
  global $is_https, $user;
  $column = $is_https ? 'ssid' : 'sid';
  $query = db_select('sessions')
    ->fields('sessions')
    ->condition($column, session_id());
  $data = $query
    ->execute()
    ->fetchAssoc();

  // LDAP needs the name field to look up the user.
  $data['name'] = $user->name;

  // Clean out the session data.
  $data['session'] = '';
  $sid = $data[$column];
  try {

    // And save the session id to LDAP.
    simple_ldap_sso_ldap_save_sid($user->name, $sid);

    // Now set the cookie.
    simple_ldap_sso_set_cookie($data);

    // Log a message.
    $message = 'SSO session created for @name.';
    $t_args = array(
      '@name' => $user->name,
    );
    watchdog('simple_ldap_sso', $message, $t_args, WATCHDOG_NOTICE);
  } catch (Exception $e) {
    $message = 'Unable to set SSO session for user %name. Error: @e';
    $t_args = array(
      '%name' => $user->name,
      '@e' => (string) $e,
    );
    watchdog(__FUNCTION__, $message, $t_args, WATCHDOG_WARNING);
  }
}