diff --git a/core/core.services.yml b/core/core.services.yml index cf380bd..ab0f6d8 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -332,6 +332,8 @@ services: arguments: ['@settings'] route_enhancer.authentication: class: Drupal\Core\Routing\Enhancer\AuthenticationEnhancer + calls: + - [setContainer, ['@service_container']] tags: - { name: route_enhancer, priority: 1000 } arguments: ['@authentication'] @@ -380,6 +382,8 @@ services: arguments: ['@content_negotiation'] legacy_access_subscriber: class: Drupal\Core\EventSubscriber\LegacyAccessSubscriber + calls: + - [setContainer, ['@service_container']] tags: - { name: event_subscriber } private_key: @@ -398,9 +402,11 @@ services: - [setRequest, ['@?request']] access_subscriber: class: Drupal\Core\EventSubscriber\AccessSubscriber + arguments: ['@access_manager', '@current_user'] + calls: + - [setCurrentUser, ['@?current_user']] tags: - { name: event_subscriber } - arguments: ['@access_manager', '@current_user'] scope: request access_route_subscriber: class: Drupal\Core\EventSubscriber\AccessRouteSubscriber @@ -624,6 +630,7 @@ services: factory_service: authentication arguments: ['@request'] scope: request + synchronized: true asset.css.collection_renderer: class: Drupal\Core\Asset\CssCollectionRenderer asset.css.collection_optimizer: diff --git a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php index f5df4ec..cd7a17d 100644 --- a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php +++ b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php @@ -107,6 +107,10 @@ protected function parseDefinition($id, $service, $filename) { $definition->setSynthetic($service['synthetic']); } + if (isset($service['synchronized'])) { + $definition->setSynchronized($service['synchronized']); + } + if (isset($service['public'])) { $definition->setPublic($service['public']); } diff --git a/core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php index 37c26c1..3cf5f4d 100644 --- a/core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php @@ -7,13 +7,13 @@ namespace Drupal\Core\EventSubscriber; +use Drupal\Core\Access\AccessManager; use Drupal\Core\Session\AccountInterface; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; -use Drupal\Core\Access\AccessManager; /** * Access subscriber for controller requests. @@ -21,6 +21,13 @@ class AccessSubscriber implements EventSubscriberInterface { /** + * The current user. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $currentUser; + + /** * The access manager. * * @var \Drupal\Core\Access\AccessManager @@ -33,12 +40,12 @@ class AccessSubscriber implements EventSubscriberInterface { * @param \Drupal\Core\Access\AccessManager $access_manager * The access check manager that will be responsible for applying * AccessCheckers against routes. - * @param \Drupal\Core\Session\AccountInterface $account + * @param \Drupal\Core\Session\AccountInterface $current_user * The current user. */ - public function __construct(AccessManager $access_manager, AccountInterface $account) { + public function __construct(AccessManager $access_manager, AccountInterface $current_user) { $this->accessManager = $access_manager; - $this->account = $account; + $this->currentUser = $current_user; } /** @@ -58,13 +65,23 @@ public function onKernelRequestAccessCheck(GetResponseEvent $event) { return; } - $access = $this->accessManager->check($request->attributes->get(RouteObjectInterface::ROUTE_OBJECT), $request, $this->account); + $access = $this->accessManager->check($request->attributes->get(RouteObjectInterface::ROUTE_OBJECT), $request, $this->currentUser); if (!$access) { throw new AccessDeniedHttpException(); } } /** + * Sets the current user. + * + * @param \Drupal\Core\Session\AccountInterface $current_user|null + * The current user service. + */ + public function setCurrentUser(AccountInterface $current_user = NULL) { + $this->currentUser = $current_user; + } + + /** * Registers the methods in this class that should be listeners. * * @return array @@ -75,4 +92,5 @@ static function getSubscribedEvents() { return $events; } + } diff --git a/core/lib/Drupal/Core/EventSubscriber/LegacyAccessSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/LegacyAccessSubscriber.php index 71f8efb..9abaabf 100644 --- a/core/lib/Drupal/Core/EventSubscriber/LegacyAccessSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/LegacyAccessSubscriber.php @@ -10,12 +10,13 @@ use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Access subscriber for legacy controller requests. */ -class LegacyAccessSubscriber implements EventSubscriberInterface { +class LegacyAccessSubscriber extends ContainerAware implements EventSubscriberInterface { /** * Verifies that the current user can access the requested path. @@ -41,8 +42,7 @@ public function onKernelRequestAccessCheck(GetResponseEvent $event) { $GLOBALS['user'] = drupal_anonymous_user(); // @todo Remove this in https://drupal.org/node/2073531 $request_attributes->set('_account', $GLOBALS['user']); - // @todo make this class container aware, or move to request scope. - \Drupal::getContainer()->set('current_user', $GLOBALS['user']); + $this->container->set('current_user', $GLOBALS['user']); throw new AccessDeniedHttpException(); } diff --git a/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php b/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php index 3e82820..7012412 100644 --- a/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php +++ b/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php @@ -9,6 +9,7 @@ use Drupal\Core\Authentication\AuthenticationManagerInterface; use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface; +use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\HttpFoundation\Request; use Symfony\Cmf\Component\Routing\RouteObjectInterface; @@ -20,7 +21,7 @@ * all authentication mechanisms. Instead, we check if the used provider is * valid for the matched route and if not, force the user to anonymous. */ -class AuthenticationEnhancer implements RouteEnhancerInterface { +class AuthenticationEnhancer extends ContainerAware implements RouteEnhancerInterface { /** * The authentication manager. @@ -53,10 +54,7 @@ public function enhance(array $defaults, Request $request) { if (!in_array($auth_provider_triggered, $auth_providers)) { $anonymous_user = drupal_anonymous_user(); - // Moving this service to request scope requires the whole route family - // of services to be moved in the same scope. - // @todo make this class container aware, or move to request scope. - \Drupal::getContainer()->set('current_user', $anonymous_user); + $this->container->set('current_user', $anonymous_user, 'request'); // @todo Remove this in https://drupal.org/node/2073531 $request->attributes->set('_account', $anonymous_user);