diff --git a/core/lib/Drupal/Core/Authentication/AuthenticationManager.php b/core/lib/Drupal/Core/Authentication/AuthenticationManager.php index d154abd..aea0900 100644 --- a/core/lib/Drupal/Core/Authentication/AuthenticationManager.php +++ b/core/lib/Drupal/Core/Authentication/AuthenticationManager.php @@ -22,7 +22,7 @@ * * If no provider set an active user then the user is set to anonymous. */ -class AuthenticationManager implements AuthenticationProviderInterface, AuthenticationProviderAccessInterface, AuthenticationProviderChallengeInterface { +class AuthenticationManager implements AuthenticationProviderInterface, AuthenticationProviderFilterInterface, AuthenticationProviderChallengeInterface { /** * Array of all registered authentication providers, keyed by ID. @@ -46,11 +46,11 @@ class AuthenticationManager implements AuthenticationProviderInterface, Authenti protected $sortedProviders; /** - * List of providers which implement the access interface. + * List of providers which implement the filter interface. * * @var \Drupal\Core\Authentication\AuthenticationAccessProviderInterface[] */ - protected $accessCheckers; + protected $filters; /** * List of providers which implement the challenge interface. @@ -85,8 +85,8 @@ public function addProvider(AuthenticationProviderInterface $provider, $id, $pri // Force the builders to be re-sorted. $this->sortedProviders = NULL; - if ($provider instanceof AuthenticationProviderAccessInterface) { - $this->accessCheckers[$id] = $provider; + if ($provider instanceof AuthenticationProviderFilterInterface) { + $this->filters[$id] = $provider; } if ($provider instanceof AuthenticationProviderChallengeInterface) { $this->challengeProviders[$id] = $provider; @@ -114,10 +114,10 @@ public function authenticate(Request $request) { /** * {@inheritdoc} */ - public function access(Request $request) { + public function appliesToRoutedRequest(Request $request) { $provider_id = $this->getProvider($request); // Always grant access if no provider claims ownership of the request. - return $provider_id ? $this->hasAccess($request, $provider_id) : TRUE; + return $provider_id ? $this->applyFilter($request, $provider_id) : TRUE; } /** @@ -161,7 +161,7 @@ protected function getProvider(Request $request) { protected function getChallengeProvider($request) { if (!empty($this->challengeProviders)) { foreach ($this->getSortedProviders() as $provider_id => $provider) { - if (isset($this->challengeProviders[$provider_id]) && $this->hasAccess($request, $provider_id) && !$provider->applies($request)) { + if (isset($this->challengeProviders[$provider_id]) && $this->applyFilter($request, $provider_id) && !$provider->applies($request)) { return $provider_id; } } @@ -179,9 +179,9 @@ protected function getChallengeProvider($request) { * @return bool * TRUE if provider is allowed, FALSE otherwise. */ - protected function hasAccess(Request $request, $provider_id) { - if (isset($this->accessCheckers[$provider_id])) { - $result = $this->accessCheckers[$provider_id]->access($request); + protected function applyFilter(Request $request, $provider_id) { + if (isset($this->filters[$provider_id])) { + $result = $this->filters[$provider_id]->appliesToRoutedRequest($request); } else { $route = RouteMatch::createFromRequest($request)->getRouteObject(); diff --git a/core/lib/Drupal/Core/Authentication/AuthenticationProviderAccessInterface.php b/core/lib/Drupal/Core/Authentication/AuthenticationProviderFilterInterface.php similarity index 75% rename from core/lib/Drupal/Core/Authentication/AuthenticationProviderAccessInterface.php rename to core/lib/Drupal/Core/Authentication/AuthenticationProviderFilterInterface.php index 5fbba20..f1a71e4 100644 --- a/core/lib/Drupal/Core/Authentication/AuthenticationProviderAccessInterface.php +++ b/core/lib/Drupal/Core/Authentication/AuthenticationProviderFilterInterface.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\Authentication\AuthenticationProviderAccessInterface + * Contains \Drupal\Core\Authentication\AuthenticationProviderFilterInterface */ namespace Drupal\Core\Authentication; @@ -14,24 +14,24 @@ * * Some authentication methods should not be available throughout a whole site. * E.g., there are good reasons to restrict insecure methods like HTTP basic - * auth or an URL token authentication method to API-only routes/paths. + * auth or an URL token authentication method to API-only routes. */ -interface AuthenticationProviderAccessInterface { +interface AuthenticationProviderFilterInterface { /** - * Checks whether the authentication method is allowed on a given route/path. + * Checks whether the authentication method is allowed on a given route. * * While authentication itself is run before routing, this method is called * after routing, hence RouteMatch is available and can be used to inspect * route options. * - * @var \Symfony\Component\HttpFoundation\Request + * @param \Symfony\Component\HttpFoundation\Request $request * The request. * * @return bool * TRUE if an authentication method is allowed on the request, otherwise * FALSE. */ - public function access(Request $request); + public function appliesToRoutedRequest(Request $request); } diff --git a/core/lib/Drupal/Core/EventSubscriber/AuthenticationSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/AuthenticationSubscriber.php index 1630911..94d6473 100644 --- a/core/lib/Drupal/Core/EventSubscriber/AuthenticationSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/AuthenticationSubscriber.php @@ -7,7 +7,7 @@ namespace Drupal\Core\EventSubscriber; -use Drupal\Core\Authentication\AuthenticationProviderAccessInterface; +use Drupal\Core\Authentication\AuthenticationProviderFilterInterface; use Drupal\Core\Authentication\AuthenticationProviderChallengeInterface; use Drupal\Core\Authentication\AuthenticationProviderInterface; use Drupal\Core\Session\AccountProxyInterface; @@ -33,11 +33,11 @@ class AuthenticationSubscriber implements EventSubscriberInterface { protected $authenticationProvider; /** - * Authentication access check. + * Authentication provider filter. * - * @var \Drupal\Core\Authentication\AuthenticationAccessProviderInterface|NULL + * @var \Drupal\Core\Authentication\AuthenticationProviderFilterInterface|NULL */ - protected $accessChecker; + protected $filter; /** * Authentication challenge provider. @@ -63,7 +63,7 @@ class AuthenticationSubscriber implements EventSubscriberInterface { */ public function __construct(AuthenticationProviderInterface $authentication_provider, AccountProxyInterface $account_proxy) { $this->authenticationProvider = $authentication_provider; - $this->accessChecker = ($authentication_provider instanceof AuthenticationProviderAccessInterface) ? $authentication_provider : NULL; + $this->filter = ($authentication_provider instanceof AuthenticationProviderFilterInterface) ? $authentication_provider : NULL; $this->challengeProvider = ($authentication_provider instanceof AuthenticationProviderChallengeInterface) ? $authentication_provider : NULL; $this->accountProxy = $account_proxy; } @@ -94,10 +94,10 @@ public function onKernelRequestAuthenticate(GetResponseEvent $event) { * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event * The request event. */ - public function onKernelRequestCheckProviderAccess(GetResponseEvent $event) { - if (isset($this->accessChecker) && $event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) { + public function onKernelRequestFilterProvider(GetResponseEvent $event) { + if (isset($this->filter) && $event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) { $request = $event->getRequest(); - if ($this->authenticationProvider->applies($request) && !$this->accessChecker->access($request)) { + if ($this->authenticationProvider->applies($request) && !$this->filter->appliesToRoutedRequest($request)) { throw new AccessDeniedHttpException(); } } @@ -117,7 +117,7 @@ public function onExceptionSendChallange(GetResponseForExceptionEvent $event) { if (isset($this->challengeProvider) && $event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) { $request = $event->getRequest(); $exception = $event->getException(); - if ($exception instanceof AccessDeniedHttpException && !$this->authenticationProvider->applies($request) && (!isset($this->accessChecker) || $this->accessChecker->access($request))) { + if ($exception instanceof AccessDeniedHttpException && !$this->authenticationProvider->applies($request) && (!isset($this->filter) || $this->filter->appliesToRoutedRequest($request))) { $challenge_exception = $this->challengeProvider->challengeException($request, $exception); if ($challenge_exception) { $event->setException($challenge_exception); @@ -137,7 +137,7 @@ public static function getSubscribedEvents() { $events[KernelEvents::REQUEST][] = ['onKernelRequestAuthenticate', 300]; // Access check must be performed after routing. - $events[KernelEvents::REQUEST][] = ['onKernelRequestCheckProviderAccess', 31]; + $events[KernelEvents::REQUEST][] = ['onKernelRequestFilterProvider', 31]; $events[KernelEvents::EXCEPTION][] = ['onExceptionSendChallange', 75]; return $events; }