diff --git a/core/lib/Drupal/Core/Authentication/AuthenticationCollector.php b/core/lib/Drupal/Core/Authentication/AuthenticationCollector.php index e417f50..60bd62c 100644 --- a/core/lib/Drupal/Core/Authentication/AuthenticationCollector.php +++ b/core/lib/Drupal/Core/Authentication/AuthenticationCollector.php @@ -1,4 +1,5 @@ providers[$provider_id] = $provider; $this->providerOrders[$priority][$provider_id] = $provider; - // Force the builders to be re-sorted. + // Force the providers to be re-sorted. $this->sortedProviders = NULL; if ($global) { @@ -74,7 +73,7 @@ public function getProvider($provider_id) { */ public function getSortedProviders() { if (!isset($this->sortedProviders)) { - // Sort the builders according to priority. + // Sort the providers according to priority. krsort($this->providerOrders); // Merge nested providers from $this->providers into $this->sortedProviders. diff --git a/core/lib/Drupal/Core/Authentication/AuthenticationCollectorInterface.php b/core/lib/Drupal/Core/Authentication/AuthenticationCollectorInterface.php index 76b7fd2..5bf6a08 100644 --- a/core/lib/Drupal/Core/Authentication/AuthenticationCollectorInterface.php +++ b/core/lib/Drupal/Core/Authentication/AuthenticationCollectorInterface.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Authentication; /** - * A collector class for authentication providers. + * Interface for collectors of registered authentication providers. */ interface AuthenticationCollectorInterface { @@ -30,6 +30,9 @@ public function addProvider(AuthenticationProviderInterface $provider, $provider /** * Returns whether a provider is considered global. * + * @param string $provider_id + * The provider ID. + * * @return bool * TRUE if the provider is global, FALSE otherwise. * @@ -41,7 +44,7 @@ public function isGlobal($provider_id); * Returns an authentication provider. * * @param string $provider_id - * THe provider ID. + * The provider ID. * * @return \Drupal\Core\Authentication\AuthenticationProviderInterface|NULL * The authentication provider which matches the ID. @@ -51,9 +54,6 @@ public function getProvider($provider_id); /** * Returns the sorted array of authentication providers. * - * @todo Replace with a list of providers sorted during compile time in - * https://www.drupal.org/node/2432585. - * * @return \Drupal\Core\Authentication\AuthenticationProviderInterface[] * An array of authentication provider objects. */ diff --git a/core/lib/Drupal/Core/Authentication/AuthenticationManager.php b/core/lib/Drupal/Core/Authentication/AuthenticationManager.php index 455e5a6..9f4c841 100644 --- a/core/lib/Drupal/Core/Authentication/AuthenticationManager.php +++ b/core/lib/Drupal/Core/Authentication/AuthenticationManager.php @@ -20,28 +20,7 @@ * * If no provider set an active user then the user is set to anonymous. */ -class AuthenticationManager implements AuthenticationProviderInterface, AuthenticationProviderFilterInterface, AuthenticationProviderChallengeInterface, AuthenticationManagerInterface { - - /** - * Array of all registered authentication providers, keyed by ID. - * - * @var \Drupal\Core\Authentication\AuthenticationProviderInterface[] - */ - protected $providers; - - /** - * Array of all providers and their priority. - * - * @var array - */ - protected $providerOrders = array(); - - /** - * Sorted list of registered providers. - * - * @var \Drupal\Core\Authentication\AuthenticationProviderInterface[] - */ - protected $sortedProviders; +class AuthenticationManager implements AuthenticationProviderInterface, AuthenticationProviderFilterInterface, AuthenticationProviderChallengeInterface { /** * List of providers which implement the filter interface. @@ -58,10 +37,15 @@ class AuthenticationManager implements AuthenticationProviderInterface, Authenti protected $challengers; /** + * The authentication provider collector. + * * @var \Drupal\Core\Authentication\AuthenticationCollectorInterface */ protected $authCollector; + /** + * Creates a new authentication manager instance. + */ public function __construct(AuthenticationCollectorInterface $auth_collector) { $this->authCollector = $auth_collector; diff --git a/core/lib/Drupal/Core/Authentication/AuthenticationManagerInterface.php b/core/lib/Drupal/Core/Authentication/AuthenticationManagerInterface.php deleted file mode 100644 index d17f2ff..0000000 --- a/core/lib/Drupal/Core/Authentication/AuthenticationManagerInterface.php +++ /dev/null @@ -1,15 +0,0 @@ -randomMachineName(); + $priority = rand(-100,100); + $provider = new TestAuthenticationProvider($provider_id); + $providers[$priority] = $provider; + $global[$provider_id] = rand(0,1) > 0.5; + $authentication_collector->addProvider($provider, $provider_id, $priority, $global[$provider_id]); + } + // Sort the $providers array by priority (highest number is lowest priority) + // and compare with AuthenticationCollector::getSortedProviders(). + krsort($providers); + $this->assertEquals(array_values($providers), array_values($authentication_collector->getSortedProviders())); + + // Test AuthenticationCollector::getProvider() and AuthenticationCollector::isGlobal(). + foreach ($providers as $provider) { + $this->assertEquals($provider, $authentication_collector->getProvider($provider->providerId)); + $this->assertEquals($global[$provider->providerId], $authentication_collector->isGlobal($provider->providerId)); + } + } + +} + +class TestAuthenticationProvider implements AuthenticationProviderInterface { + + /** + * The provider id. + * + * @var $provider_id + */ + public $providerId; + + /** + * Constructor. + */ + public function __construct($provider_id) { + $this->providerId = $provider_id; + } + + /** + * {@inheritdoc} + */ + public function applies(Request $request) { + return TRUE; + } + + /** + * {@inheritdoc} + */ + public function authenticate(Request $request) { + return NULL; + } + +}