You are here

function simplesamlphp_auth_loginpage in simpleSAMLphp Authentication 7

Same name and namespace in other branches
  1. 6.3 simplesamlphp_auth.module \simplesamlphp_auth_loginpage()
  2. 6.2 simplesamlphp_auth.module \simplesamlphp_auth_loginpage()
  3. 7.3 simplesamlphp_auth.pages.inc \simplesamlphp_auth_loginpage()
  4. 7.2 simplesamlphp_auth.module \simplesamlphp_auth_loginpage()

Represents the Drupal page (saml_login), which triggers user authentication against the SimpleSAMLphp service provider.

1 string reference to 'simplesamlphp_auth_loginpage'
simplesamlphp_auth_menu in ./simplesamlphp_auth.module
Implements hook_menu().

File

./simplesamlphp_auth.module, line 90
simpleSAMLphp authentication module for Drupal.

Code

function simplesamlphp_auth_loginpage() {
  global $user;
  global $_simplesamlphp_auth_as;
  global $_simplesamlphp_auth_saml_attributes;
  $fail = NULL;
  $output = NULL;
  if (!_simplesamlphp_auth_isEnabled()) {

    // Exit without initializing.
    drupal_set_message(t('We\'re sorry this feature is not yet enabled.'));
    return;
  }

  // Do some sanity checking before attempting anything.
  $config = SimpleSAML_Configuration::getInstance();
  $configStoreType = $config
    ->getValue('store.type');

  // Make sure phpsession is NOT being used.
  if ($configStoreType == 'phpsession') {
    watchdog('simplesamlphp_auth', 'A user attempted to login using simplesamlphp but the store.type is phpsession, use memcache or sql for simplesamlphp session storage. See: simplesamlphp/config/config.php.', NULL, WATCHDOG_WARNING);
    $fail = TRUE;
  }

  // Make sure there is an instance of SimpleSAML_Auth_Simple.
  if (!$_simplesamlphp_auth_as) {
    watchdog('simplesamlphp_auth', 'A user attempted to login using this module but there was a problem.', NULL, WATCHDOG_WARNING);
    $fail = TRUE;
  }

  // There was a problem, we can't go on, but we don't want to tell the user any specifics either.
  if ($fail) {
    drupal_set_message(t('We\'re sorry. There was a problem. The issue has been logged for the administrator.'));
    drupal_goto('/');
  }
  if ($user->uid == 0) {

    // Require the user to be authenticated.
    $_simplesamlphp_auth_as
      ->requireAuth();
  }
  else {
    drupal_goto('user/' . $user->uid);
  }
  return $output;
}