- Issue created by @vlad.dancer
- Merge request !11Make return type nullable in getAttribute method to match code logic β (Open) created by vlad.dancer
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)
Here are the steps to reproduce:
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;
}
Create and review MR.
N/A
N/A
N/A
Active
3.0
Code