You are here

public function LoginController::login in LDAP Single Sign On 8

Same name and namespace in other branches
  1. 8.4 src/Controller/LoginController.php \Drupal\ldap_sso\Controller\LoginController::login()

Login.

A proxy function for the actual authentication routine. This is in place so various implementations of grabbing NTLM credentials can be used and selected from an administration page. This is the real gatekeeper since this assumes that any NTLM authentication from the underlying web server is good enough, and only checks that there are values in place for the user name, and anything else that is set for a particular implementation. In the case that there are no credentials set by the underlying web server, the user is redirected to the normal user login form.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current Symfony HTTP Request.

1 string reference to 'LoginController::login'
ldap_sso.routing.yml in ./ldap_sso.routing.yml
ldap_sso.routing.yml

File

src/Controller/LoginController.php, line 91

Class

LoginController
Class LoginController.

Namespace

Drupal\ldap_sso\Controller

Code

public function login(Request $request) {
  $this->detailLog
    ->log('Beginning SSO login.', [], 'ldap_sso');
  $remote_user = FALSE;
  $realm = NULL;
  if (isset($_SERVER[$this->config
    ->get('ssoVariable')])) {
    $remote_user = $_SERVER[$this->config
      ->get('ssoVariable')];
  }
  if ($this->config
    ->get('ssoSplitUserRealm')) {
    list($remote_user, $realm) = $this
      ->splitUserNameRealm($remote_user);
  }
  $this->detailLog
    ->log('SSO raw result is username=@remote_user, (realm=@realm).', [
    '@remote_user' => $remote_user,
    '@realm' => $realm,
  ], 'ldap_sso');
  if ($remote_user) {
    $this->detailLog
      ->log('User found, logging in.', [], 'ldap_sso');
    $this
      ->loginRemoteUser($remote_user, $realm);
    $destination = $request->query
      ->get('destination', NULL);
    if ($destination == NULL) {
      $finalDestination = Url::fromRoute('<front>');
    }
    else {
      $finalDestination = Url::fromUserInput($destination);
    }
  }
  else {
    $this->detailLog
      ->log('User missing.', [], 'ldap_sso');
    $this
      ->remoteUserMissing();
    $finalDestination = Url::fromRoute('user.login');
  }

  // Removes our automated SSO semaphore, should it have been set.
  $cookies[] = new Cookie('sso_login_running', '', REQUEST_TIME - 3600, base_path());
  return new RedirectResponseWithCookie($finalDestination
    ->toString(), 302, $cookies);
}