You are here

protected function WindowsAadSSORouteSubscriber::alterRoutes in OpenID Connect Microsoft Azure Active Directory client 2.0.x

Same name and namespace in other branches
  1. 8 src/Routing/WindowsAadSSORouteSubscriber.php \Drupal\openid_connect_windows_aad\Routing\WindowsAadSSORouteSubscriber::alterRoutes()

Alters existing routes for a specific collection.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection for adding routes.

Overrides RouteSubscriberBase::alterRoutes

File

src/Routing/WindowsAadSSORouteSubscriber.php, line 17

Class

WindowsAadSSORouteSubscriber
Listens to the dynamic route events.

Namespace

Drupal\openid_connect_windows_aad\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  if ($route = $collection
    ->get('user.logout')) {
    try {
      $configuration = \Drupal::config('openid_connect.settings.windows_aad');
      $settings = $configuration
        ->get('settings');
      $enabled = $configuration
        ->get('enabled');
    } catch (Exception $exception) {

      // Not important to differentiate between Exceptions here, we just need
      // make it know that something is wrong and we won't enable SSOut.
      $configuration = FALSE;

      // TODO: When watchdog_exception() is deprecated and ExceptionLogger is
      // available, update this to use ExceptionLogger.
      // @see https://www.drupal.org/project/drupal/issues/2932518
      $variables = Error::decodeException($exception);
      \Drupal::logger('openid_connect_windows_aad')
        ->error('Failed to check OpenID Connect Windows AAD configuration so Single Sign Off will remain disabled. %type: @message in %function (line %line of %file).', $variables);
    }

    // Override the controller for the user.logout route in order to redirect
    // to the Windows Azure AD Single Sign out endpoint if SSOut is enabled.
    if ($configuration && $enabled && isset($settings['enable_single_sign_out']) && $settings['enable_single_sign_out']) {
      $route
        ->setDefault('_controller', '\\Drupal\\openid_connect_windows_aad\\Controller\\WindowsAadSSOController::logout');
    }
  }
}