* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Http\Firewall; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; use Symfony\Component\Security\Http\SecurityEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Security\Core\Exception\BadCredentialsException; /** * AbstractPreAuthenticatedListener is the base class for all listener that * authenticates users based on a pre-authenticated request (like a certificate * for instance). * * @author Fabien Potencier */ abstract class AbstractPreAuthenticatedListener implements ListenerInterface { protected $logger; private $tokenStorage; private $authenticationManager; private $providerKey; private $dispatcher; public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, $providerKey, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null) { $this->tokenStorage = $tokenStorage; $this->authenticationManager = $authenticationManager; $this->providerKey = $providerKey; $this->logger = $logger; $this->dispatcher = $dispatcher; } /** * Handles pre-authentication. */ final public function handle(GetResponseEvent $event) { $request = $event->getRequest(); try { list($user, $credentials) = $this->getPreAuthenticatedData($request); } catch (BadCredentialsException $e) { $this->clearToken($e); return; } if (null !== $this->logger) { $this->logger->debug('Checking current security token.', array('token' => (string) $this->tokenStorage->getToken())); } if (null !== $token = $this->tokenStorage->getToken()) { if ($token instanceof PreAuthenticatedToken && $this->providerKey == $token->getProviderKey() && $token->isAuthenticated() && $token->getUsername() === $user) { return; } } if (null !== $this->logger) { $this->logger->debug('Trying to pre-authenticate user.', array('username' => (string) $user)); } try { $token = $this->authenticationManager->authenticate(new PreAuthenticatedToken($user, $credentials, $this->providerKey)); if (null !== $this->logger) { $this->logger->info('Pre-authentication successful.', array('token' => (string) $token)); } $this->tokenStorage->setToken($token); if (null !== $this->dispatcher) { $loginEvent = new InteractiveLoginEvent($request, $token); $this->dispatcher->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $loginEvent); } } catch (AuthenticationException $e) { $this->clearToken($e); } } /** * Clears a PreAuthenticatedToken for this provider (if present). */ private function clearToken(AuthenticationException $exception) { $token = $this->tokenStorage->getToken(); if ($token instanceof PreAuthenticatedToken && $this->providerKey === $token->getProviderKey()) { $this->tokenStorage->setToken(null); if (null !== $this->logger) { $this->logger->info('Cleared security token due to an exception.', array('exception' => $exception)); } } } /** * Gets the user and credentials from the Request. * * @return array An array composed of the user and the credentials */ abstract protected function getPreAuthenticatedData(Request $request); } __halt_compiler();----SIGNATURE:----drh+4JideWejYAYLpf4LilPxk/4JZbc6D6s39dx4bNIFLvupqgX5wm6eVoQ8hI3LDDzcz50hKwceU0fsVHukeJbw9ER5bKmBtE3nNseOxjkaxlRe0Z/Fk0pbWtu+EA1Of2Ng5UnnqWlQWFEZ/orQsbvTLdv1C6Ed/8aiLmZkORuHENhI2PR4RBlJk5Wl+/cXMKoMm374nBTIm5RUKv02j81P2R0VNX3nj1oo6lvSe0ZRWLZXBvcklm7A1AcusR532uNUMACXiobwn5M+gLY3SKmVGddWgpGIwedNhCG2+sFsEXOzS/7lOg7G/lND8p2xQiMLQBkyymdB7wK0h/Gp4l9He9+KKVXhTkHwIYSwAwDIxPD+vL7e+z2CTalfCDC3ugjNShtl1byKU7Dfik8Ej7uT3Jd3as+7ynmPfsOZ7+GYBIYRIQDgCVQIGK8p2KHnceZ94TSW0MjP7+8lvjJIzTPgefBUvVKtxMKLbKEtf7qugEmG2JyCcxo0XnCslBYI8rQs8C/NWS/qs2gKYSTMtS41wMfLbY059gPn4kKaA3DDdkTq7ntjP01HuzPDTP5CCBXPwTxJxN2wjYCxSpsCzsATAiEqHfrR3P3F5i1ZYQoDbL7O7QHogZ5119Xq7fpxjvngzTkqLfGD/aBhUQqh58TvkoToS2cU44cB1KJQ8Do=----ATTACHMENT:----MjIwMTM2NTQxNDEyMjg4NyAxNTc3NzUzMzg2NjI5MDI0IDQ5MjAyODE4ODYxODM2NTU=