You are here

function samlauth_check_saml_user in SAML Authentication 8

Same name and namespace in other branches
  1. 8.3 samlauth.module \samlauth_check_saml_user()
  2. 8.2 samlauth.module \samlauth_check_saml_user()
  3. 7 samlauth.module \samlauth_check_saml_user()
  4. 4.x samlauth.module \samlauth_check_saml_user()

Validation callback for SAML users logging in through the normal methods.

1 string reference to 'samlauth_check_saml_user'
samlauth_form_user_login_form_alter in ./samlauth.module
Implements hook_form_FORM_ID_alter().

File

./samlauth.module, line 74
Contains samlauth.module.

Code

function samlauth_check_saml_user($form, FormStateInterface $form_state) {
  if (!\Drupal::config('samlauth.authentication')
    ->get('drupal_saml_login')) {
    if ($form_state
      ->hasAnyErrors()) {

      // If previous validation has already failed (name/pw incorrect or blocked),
      // bail out so we don't disclose any details about a user that otherwise
      // wouldn't be authenticated.
      return;
    }
    if ($account = user_load_by_name($form_state
      ->getValue('name'))) {
      $user_data = \Drupal::service('user.data');
      $saml_id = $user_data
        ->get('samlauth', $account
        ->id(), 'saml_id');
      if (!is_null($saml_id)) {
        $form_state
          ->setErrorByName('name', t('SAML users must sign in with SSO'));
      }
    }
  }
}