* * 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:----UXO8QkNE/ijwCTpbMbGH/J6gWhOCBMQe3uUOWILivSU9Es6BZXZXH4Wr+KHosLMJYhcjFfqv/EALoxrHvXKSrPwDjKyfQtMSUUKFLFnvmgtwHaPT62nr55CLjL2N8v+wnhpvLvf8zpH0u0xV0dVxgmWDErksCUr0dLNQoRpYwHOWzBn+5tQRlntMTtsO9nR+NkFwd20KkX8b1OYmSsufTZ799iSf3g0sDHWTUTZ43JZM69kst6m/iYvEg8aDRXMyN0cuRP56pnFeWO4vfS8E311rD4RyfIA47x/nO6ioZY62tpSK88hrGm2O0/bNHaHICUJxRE69LfqsG2LTkhJ8Y15Xs6JY4E7reYpNN4fRhEHVIs8+X56gzJ88YJ+yaOpmCa7FML9zpK5xxEAzt+W56KtFfb2aidDui+ACJ+9mcXW8L8AB3cIYvePyqlEy8nB7me3vBrMsIDmmPzwUyU1r28Asiv0m8apnO5mXa9Gq8IFELgOGLZYQgQNeHSPytf4DtwJN18safwFDKsKumjriQ9CLVyiZwheXktSTdZjn0AvMKCOaFn5bBV9/UswbhpE/syFhYhHZ3uPz2lhrFZmfQBelAv0n2Fal4R3bkdNpXCJs5t8qC2AFff/84tJu+la1zLe6JjwvdJnzqLt1GAudJGEdFzqIiW6b2+NQIIIk0Qo=----ATTACHMENT:----MjA4Mzk4ODEzMzA1Njg2MyAxODg5MjU2MDQwMTAxODkgODU1NTMyNTE0NTU4MjU3NA==