* * 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:----lr54+0NVKrC0C9wTOlqPfr/nQUxYHw+HKrSqsab2zUuH+r+SYcQgo0KbmYj+fVgcJ6/FCBY4bV5Qqt0HLWLIajb7Qum50lQCWiQv1c8L1iOpmc6GCP5V6aGZlYnZ9wxH+7u8C4PjvhnhxlsYUOJPtsZqi38v1Pj/MSmdYgrKMgCoWswj3XQB4XWVUIHQYn5Q5kdiB2OeWNOGGrJWRVGak0DK0jsJZjlUu/y+nm1smpiSB1siOjm9qJ997TcKwOvAG0sOYYtEq0DAio56I3Hfy/hCxSAHy3CCs2C0vrdZ87exBNGtLB+Q6X0XWrW6ksyouZhxGiOed+eGWzAeJNL2VnIbJV9vIpjOXDVWd2P2EdNtLAAsxRnDfcHi+eHgZTKLoJeqCI3g1g06/5qSKEvIUMbloePWgJAktHLlVa1b5os5UP+IpgxuBZuVvkoEK6Kpby2n7DuEMQjoCMMxrO+Skj88M1g2Dx53ow5u+DqPkDM8CRP2uotNp+VCuuXfyLqn9Ds0253ErdAMZ9eA/xJHfEbAIrkQd39yrjKpBVlGqBS6j1F+wnTbWWbn0jemvVjhCVKOy+OUNojiGQkmmIXJ7Dej5IiwnrXkLZq7buFGFYD1hCBzlL4GBR1M/0ob5uzhQBCK5Hf1pIlC4wscL/irooYC2l1InTPaulpL85HP4c8=----ATTACHMENT:----NzQxMzM0NzQzMjI2OTE4OCA5NTgxMDc1NzMxOTY5MzE0IDM5NTM1MzI3NjU1MDM4NQ==