diff --git a/core/lib/Drupal/Core/Session/AccountProxy.php b/core/lib/Drupal/Core/Session/AccountProxy.php index b675b02..eae71e7 100644 --- a/core/lib/Drupal/Core/Session/AccountProxy.php +++ b/core/lib/Drupal/Core/Session/AccountProxy.php @@ -56,7 +56,7 @@ public function getAccount() { // After the container is rebuilt, DrupalKernel sets the initial // account to the id of the logged in user. This is necessary in order // to refresh the user account reference here. - $this->account = \Drupal::entityManager()->getStorage('user')->load($this->initialAccountId); + $this->account = $this->loadUserEntity($this->initialAccountId); } else { $this->account = new AnonymousUserSession(); @@ -182,4 +182,27 @@ public function setInitialAccountId($account_id) { $this->initialAccountId = $account_id; } + /** + * Load a user entity. + * + * The entity manager requires additional initialization code and cache + * clearing after the list of modules is changed. Therefore it is necessary to + * retrieve it as late as possible. + * + * Because of serialization issues it is currently not possible to inject the + * container into the AccountProxy. Thus it is necessary to retrieve the + * entity manager statically. + * + * @see https://www.drupal.org/node/2430447 + * + * @param int $account_id + * The id of an account to load. + * + * @return \Drupal\Core\Session\AccountInterface|NULL + * An account or NULL if none is found. + */ + protected function loadUserEntity($account_id) { + return \Drupal::entityManager()->getStorage('user')->load($account_id); + } + } diff --git a/core/modules/basic_auth/basic_auth.services.yml b/core/modules/basic_auth/basic_auth.services.yml index 05d1252..a0d4368 100644 --- a/core/modules/basic_auth/basic_auth.services.yml +++ b/core/modules/basic_auth/basic_auth.services.yml @@ -1,6 +1,6 @@ services: authentication.basic_auth: class: Drupal\basic_auth\Authentication\Provider\BasicAuth - arguments: ['@config.factory', '@user.auth', '@flood', '@entity.manager', '@current_user'] + arguments: ['@config.factory', '@user.auth', '@flood', '@entity.manager'] tags: - { name: authentication_provider, priority: 100 } diff --git a/core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php b/core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php index ec31954..30f1873 100644 --- a/core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php +++ b/core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php @@ -14,7 +14,6 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Flood\FloodInterface; use Drupal\Core\Routing\RouteMatch; -use Drupal\Core\Session\AccountInterface; use Drupal\user\UserAuthInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; @@ -54,13 +53,6 @@ class BasicAuth implements AuthenticationProviderInterface, AuthenticationProvid protected $entityManager; /** - * The current user. - * - * @var Drupal\Core\Session\AccountInterface - */ - protected $currentUser; - - /** * Constructs a HTTP basic authentication provider object. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory @@ -72,12 +64,11 @@ class BasicAuth implements AuthenticationProviderInterface, AuthenticationProvid * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager service. */ - public function __construct(ConfigFactoryInterface $config_factory, UserAuthInterface $user_auth, FloodInterface $flood, EntityManagerInterface $entity_manager, AccountInterface $current_user) { + public function __construct(ConfigFactoryInterface $config_factory, UserAuthInterface $user_auth, FloodInterface $flood, EntityManagerInterface $entity_manager) { $this->configFactory = $config_factory; $this->userAuth = $user_auth; $this->flood = $flood; $this->entityManager = $entity_manager; - $this->currentUser = $current_user; } /**