Error message after re-login with switch-edu

Created on 7 November 2024, 9 days ago

Problem/Motivation

Our client has been reported an error message when tried to re-login.
And after clearing the session cookie, he can login again.

Stack trace:

TypeError: Drupal\basicshib\AttributeMapper::getAttribute(): Return value must be of type string, null returned in Drupal\basicshib\AttributeMapper->getAttribute() (line 81 of modules/contrib/basicshib/src/AttributeMapper.php).

Drupal\basicshib\AuthenticationHandler->checkUserSession() (Line: 69)
Drupal\basicshib\EventSubscriber\RequestEventSubscriber->onRequest()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 157)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 270)
Drupal\shield\ShieldMiddleware->bypass() (Line: 137)
Drupal\shield\ShieldMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

Here are the steps to reproduce:

  • Install 3.0.x dev version, apply patch from #3407324 to make module compatible with Drupal 10.
  • Login with Switch-Edu
  • Quit the browser
  • Start the browser again an go to login page
  • I should be automatically logged in, but I get the an error message.

Proposed resolution

It looks like public function getAttribute($id, $empty_allowed = FALSE): string return type needs to be nullable according to the method logic:

if (!$value && !$empty_allowed) {
        throw new AttributeException(
                      sprintf(
                          'Attribute is not set: \'%s\' (mapped to \'%s\')',
                          $def['name'], $id
                      ),
                      AttributeException::NOT_SET
        );
}
return $value;

Then AuthenticationHandler::checkUserSession should handle this case correctly:

    // Authenticated user with expired shib session.
    $session_id = $this->_attribute_mapper->getAttribute('session_id', TRUE);
    if (!$session_id) {
      $this->_terminateSession($account);
      return self::AUTHCHECK_SHIB_SESSION_EXPIRED;
    }

Remaining tasks

Create and review MR.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine vlad.dancer Kyiv

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024