/** * 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 = array(); 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 = array(); 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 = 'TYPO3\\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 TYPO3\\Flow\\Security\\Authentication\\EntryPoint!', 1236767282); } /** @var $entryPoint \TYPO3\Flow\Security\Authentication\EntryPointInterface */ $entryPoint = new $entryPointClassName(); if (isset($providerConfiguration['entryPointOptions'])) { $entryPoint->setOptions($providerConfiguration['entryPointOptions']); } $tokenInstance->setAuthenticationEntryPoint($entryPoint); } } }
/** * 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 = array(); if (isset($providerConfiguration['providerOptions']) && is_array($providerConfiguration['providerOptions'])) { $providerOptions = $providerConfiguration['providerOptions']; } /** @var $providerInstance \TYPO3\Flow\Security\Authentication\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 = array(); foreach ($providerConfiguration['requestPatterns'] as $patternType => $patternConfiguration) { $patternClassName = $this->requestPatternResolver->resolveRequestPatternClass($patternType); /** @var $requestPattern \TYPO3\Flow\Security\RequestPatternInterface */ $requestPattern = new $patternClassName(); $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 = 'TYPO3\\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 TYPO3\\Flow\\Security\\Authentication\\EntryPoint!', 1236767282); } /** @var $entryPoint \TYPO3\Flow\Security\Authentication\EntryPointInterface */ $entryPoint = new $entryPointClassName(); if (isset($providerConfiguration['entryPointOptions'])) { $entryPoint->setOptions($providerConfiguration['entryPointOptions']); } $tokenInstance->setAuthenticationEntryPoint($entryPoint); } } }