/**
  * @test
  */
 public function resolveProviderReturnsTheCorrectProviderForACompleteClassName()
 {
     $mockObjectManager = $this->getMockBuilder(ObjectManager::class)->disableOriginalConstructor()->getMock();
     $mockObjectManager->expects($this->any())->method('getCaseSensitiveObjectName')->with('existingProviderClass')->will($this->returnValue('existingProviderClass'));
     $providerResolver = new AuthenticationProviderResolver($mockObjectManager);
     $providerClass = $providerResolver->resolveProviderClass('existingProviderClass');
     $this->assertEquals('existingProviderClass', $providerClass, 'The wrong classname has been resolved');
 }
 /**
  * Builds the provider and token objects based on the given configuration
  *
  * @param array $providerConfigurations The configured provider settings
  * @return void
  * @throws Exception\InvalidAuthenticationProviderException
  * @throws Exception\NoEntryPointFoundException
  */
 protected function buildProvidersAndTokensFromConfiguration(array $providerConfigurations)
 {
     foreach ($providerConfigurations as $providerName => $providerConfiguration) {
         if (isset($providerConfiguration['providerClass'])) {
             throw new Exception\InvalidAuthenticationProviderException('The configured authentication provider "' . $providerName . '" uses the deprecated option "providerClass". Check your settings and use the new option "provider" instead.', 1327672030);
         }
         if (isset($providerConfiguration['options'])) {
             throw new Exception\InvalidAuthenticationProviderException('The configured authentication provider "' . $providerName . '" uses the deprecated option "options". Check your settings and use the new option "providerOptions" instead.', 1327672031);
         }
         if (!is_array($providerConfiguration) || !isset($providerConfiguration['provider'])) {
             throw new Exception\InvalidAuthenticationProviderException('The configured authentication provider "' . $providerName . '" needs a "provider" option!', 1248209521);
         }
         $providerObjectName = $this->providerResolver->resolveProviderClass((string) $providerConfiguration['provider']);
         if ($providerObjectName === null) {
             throw new Exception\InvalidAuthenticationProviderException('The configured authentication provider "' . $providerConfiguration['provider'] . '" could not be found!', 1237330453);
         }
         $providerOptions = [];
         if (isset($providerConfiguration['providerOptions']) && is_array($providerConfiguration['providerOptions'])) {
             $providerOptions = $providerConfiguration['providerOptions'];
         }
         /** @var $providerInstance AuthenticationProviderInterface */
         $providerInstance = new $providerObjectName($providerName, $providerOptions);
         $this->providers[$providerName] = $providerInstance;
         /** @var $tokenInstance TokenInterface */
         $tokenInstance = null;
         foreach ($providerInstance->getTokenClassNames() as $tokenClassName) {
             if (isset($providerConfiguration['token']) && $providerConfiguration['token'] !== $tokenClassName) {
                 continue;
             }
             $tokenInstance = new $tokenClassName();
             $tokenInstance->setAuthenticationProviderName($providerName);
             $this->tokens[] = $tokenInstance;
             break;
         }
         if (isset($providerConfiguration['requestPatterns']) && is_array($providerConfiguration['requestPatterns'])) {
             $requestPatterns = [];
             foreach ($providerConfiguration['requestPatterns'] as $patternName => $patternConfiguration) {
                 // skip request patterns that are set to NULL (i.e. `somePattern: ~` in a YAML file)
                 if ($patternConfiguration === null) {
                     continue;
                 }
                 // The following check is needed for backwards compatibility:
                 // Previously the request pattern configuration was just a key/value where the value was passed to the setPattern() method
                 if (is_string($patternConfiguration)) {
                     $patternType = $patternName;
                     $patternOptions = [];
                 } else {
                     $patternType = $patternConfiguration['pattern'];
                     $patternOptions = isset($patternConfiguration['patternOptions']) ? $patternConfiguration['patternOptions'] : [];
                 }
                 $patternClassName = $this->requestPatternResolver->resolveRequestPatternClass($patternType);
                 $requestPattern = new $patternClassName($patternOptions);
                 if (!$requestPattern instanceof RequestPatternInterface) {
                     throw new Exception\InvalidRequestPatternException(sprintf('Invalid request pattern configuration in setting "TYPO3:Flow:security:authentication:providers:%s": Class "%s" does not implement RequestPatternInterface', $providerName, $patternClassName), 1446222774);
                 }
                 // The following check needed for backwards compatibility:
                 // Previously each pattern had only one option that was set via the setPattern() method. Now options are passed to the constructor.
                 if (is_string($patternConfiguration) && is_callable([$requestPattern, 'setPattern'])) {
                     $requestPattern->setPattern($patternConfiguration);
                 }
                 $requestPatterns[] = $requestPattern;
             }
             if ($tokenInstance !== null) {
                 $tokenInstance->setRequestPatterns($requestPatterns);
             }
         }
         if (isset($providerConfiguration['entryPoint'])) {
             if (is_array($providerConfiguration['entryPoint'])) {
                 $message = 'Invalid entry point configuration in setting "TYPO3:Flow:security:authentication:providers:' . $providerName . '. Check your settings and make sure to specify only one entry point for each provider.';
                 throw new Exception\InvalidAuthenticationProviderException($message, 1327671458);
             }
             $entryPointName = $providerConfiguration['entryPoint'];
             $entryPointClassName = $entryPointName;
             if (!class_exists($entryPointClassName)) {
                 $entryPointClassName = 'Neos\\Flow\\Security\\Authentication\\EntryPoint\\' . $entryPointClassName;
             }
             if (!class_exists($entryPointClassName)) {
                 throw new Exception\NoEntryPointFoundException('An entry point with the name: "' . $entryPointName . '" could not be resolved. Make sure it is a valid class name, either fully qualified or relative to Neos\\Flow\\Security\\Authentication\\EntryPoint!', 1236767282);
             }
             /** @var $entryPoint EntryPointInterface */
             $entryPoint = new $entryPointClassName();
             if (isset($providerConfiguration['entryPointOptions'])) {
                 $entryPoint->setOptions($providerConfiguration['entryPointOptions']);
             }
             $tokenInstance->setAuthenticationEntryPoint($entryPoint);
         }
     }
 }