* * 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:----jaeGyFZgxhotcfUldqrskX6kpv5jCLSd8zxG0RrcRtDhk2wXODG4nNBvNo2GBNndI54M95l7L92Qi8e2aIHQK0bPNR8Mi6fbn5Amrrzij+683y0w9qwMRXbTfdsyEpX94NrvgEh3iM6p5/0l1wmvoHNEuuZh89GnOVDnsD+ME+5lo143Hhf8rO4Uasl9CqoqG11XOdIZ1ECesIqKnt1pl+J7kOk0DOluup4aRsZtwGHptG7nwzH7bfm3r8uYvGwfcbOzP3Z9WbMu2lK6VkyoGFc43VsaGh92jkRxeh+Y4OfqkoiovxbenGlPzRAsOk4whOc3JitT6rb/ooSe3C4Z+Sx4eiW7J7DjDDwxRnyfZux2MPFtUq/KcXTfVCKdcMQExyacNez3RbNYRYpcRj6PL3MZu3C493/DL0yga+H0kaBveA1BcUVHkTfhDMThDFZInXm53zn45R2pDir2HFVOFUL+5K2II1Pj0LmVs43QPzYkZAFOEav35K9HVu2srQ8VPc18Gkh1WOzta35M2LgBBpb4xzC1Qg0TQkqbGDobsFhH8d+N9RvljpYBtrPeWOGmxS6n/gKAFBaK/hTKQ1PSRKZrMjYBRcnHUPITGVBZPRnTvugYzWnUd2OpmT5fnbb5/IBHL9vUGv3GpUS2/IfJSdDSVKzgtZJFw7YbpmP+Pd0=----ATTACHMENT:----NTY3MTU5MDAxMDg5NTY2NCA5MDUxNjg1NDg0MDk5MzgzIDM1NDY0NjQ3NzU0MjA4NTI=