* * 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\Storage\TokenStorageInterface; use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; use Psr\Log\LoggerInterface; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\Exception\AuthenticationException; /** * BasicAuthenticationListener implements Basic HTTP authentication. * * @author Fabien Potencier */ class BasicAuthenticationListener implements ListenerInterface { private $tokenStorage; private $authenticationManager; private $providerKey; private $authenticationEntryPoint; private $logger; private $ignoreFailure; public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, $providerKey, AuthenticationEntryPointInterface $authenticationEntryPoint, LoggerInterface $logger = null) { if (empty($providerKey)) { throw new \InvalidArgumentException('$providerKey must not be empty.'); } $this->tokenStorage = $tokenStorage; $this->authenticationManager = $authenticationManager; $this->providerKey = $providerKey; $this->authenticationEntryPoint = $authenticationEntryPoint; $this->logger = $logger; $this->ignoreFailure = false; } /** * Handles basic authentication. */ public function handle(GetResponseEvent $event) { $request = $event->getRequest(); if (null === $username = $request->headers->get('PHP_AUTH_USER')) { return; } if (null !== $token = $this->tokenStorage->getToken()) { if ($token instanceof UsernamePasswordToken && $token->isAuthenticated() && $token->getUsername() === $username) { return; } } if (null !== $this->logger) { $this->logger->info('Basic authentication Authorization header found for user.', array('username' => $username)); } try { $token = $this->authenticationManager->authenticate(new UsernamePasswordToken($username, $request->headers->get('PHP_AUTH_PW'), $this->providerKey)); $this->tokenStorage->setToken($token); } catch (AuthenticationException $e) { $token = $this->tokenStorage->getToken(); if ($token instanceof UsernamePasswordToken && $this->providerKey === $token->getProviderKey()) { $this->tokenStorage->setToken(null); } if (null !== $this->logger) { $this->logger->info('Basic authentication failed for user.', array('username' => $username, 'exception' => $e)); } if ($this->ignoreFailure) { return; } $event->setResponse($this->authenticationEntryPoint->start($request, $e)); } } } __halt_compiler();----SIGNATURE:----RgLuYLjorccAfDbIqb3FWjJG9unfhuaNs3DwSQBm+ZrXvgLxwZsiRmZlRynM9BNptT6C6OodiZC8Dee9xd8pvS6sSCbu+9OGrGFGQtMZ+IuK2M/0ONlNReZB7gH8yp2loyNEs718u9A+PJLq+dDGZYVffq0G5NsvE4pOdAR9+Z0QjkjlWZrO1Rp+xyG3gw88kfUFl42Wsp+uUAvoIs2LDi4rKyrNCWfAyl6P2ZueIQ870GcqK67xta2VSPOXZq/OPBsuLJ6zw/itN2hcm1PBHxZz8lIQyb/bjjeeDzCBhqtIppOA627tNf7AWOTCLuA5ydr+aeHttmL2mXuS1cTsK00KqBqdgQkraKNWpk5mc4BgNeqAbVg/8NLR8XM0LJLIxjzTzPdUFPOYRhzSZxf2CniaKP4L0OsCjOOhLPrb1JKLMJhVnSSRU23reeqvqJ0cOBcgMnT+iMhcnBMMy0fQB/W1GPeMjuVUEDPOHOeLsvoofg4fK/VlsZYoRRXZBPrkdC2aBRvcn14FsJ0/BxphY+s7DWycK5guSg/b29Gf/NKYQXwKgsg7h+umYrAu1CJz9Bkx7qzUOPsF3U39u8J9l4SSw0G+bUYJuiKsvB5nrK7zAtXtGQ3SNAm3eynA/K2SxwJjv2t/aDBB5zJRjD34adR3EfkMApB4XB580B4xa3g=----ATTACHMENT:----MjgwMDk0Njg4MjE1MDA2MSAyNDU2MTA3NjI2MzIxMDkgMjQ5MDMzMzIyNjExNDA0Ng==