* * 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:----AJSVdVH/YrrtSSdEJLj3krT8PlTbvpIN2/zYIiyZMIyYbcx60bYIdYOIg6wsXFGqmhm5rlnUwisBd+R2EkmHBwfeJ6QfKfkMjTpiMhj6r0romb3eB4hFnQQpYdE0MBgM91NT55djDQWTpbR+jbR0OoVdMCf7ixR6SR58Xxh6WbpDDN/sDSjRaZGc/v+0Iz5l3z0uf3c8co4G6WfgWzhk1QMc1ABs4rY2YNPzyCbtH6xbksWP34AzA0X6sfsarbHHYPXcTKLyUnojaT5MYWwuzCxiO+eiEk00BVlaX60i8DatbMppyjIMWhHbdBuGoxK+KLWX48qN5f7/oCRmeFoflGA8TxH++S4Yts9lJgEaRjN3QvVQHMI+7H13dGxlJB8IdyJvrAMUWroulHX0UB6qWNM2ZjEq41u6nMKcAElSyUnxwbbywd+5kU8TsLlDFkUdELvu8IwRSYDXmlme90q8Cd03fpR5Dh3xzeXsERiFiN1LAtKrx0PBpAxmEfn7SFbZ77Lqc1+MWDwmUDpQsowsacf0hYPEnkm4aKUFoqx+zIZZhcsbgFSwPZaxk/JkusU3sgi1HMS8dKetFQ2Wu+9Wihu6YyNK/Tb+PHVkPVwobO4zpETlRh5mgiHCfQGmKamnYopO/ddPaB+EWgXu3AV0lptLLv7Bt/4zIhJ69PFpS6Q=----ATTACHMENT:----OTg2MTExNDk2MzIyODc1MiA4NTYyNTQ4Mzc1MDcxMDY2IDg4MTMxOTY2MTQzMzg1MjQ=