BasicAuthenticationEntryPoint.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Security\Http\EntryPoint;
  11. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  12. use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpFoundation\Request;
  15. /**
  16. * BasicAuthenticationEntryPoint starts an HTTP Basic authentication.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. class BasicAuthenticationEntryPoint implements AuthenticationEntryPointInterface
  21. {
  22. private $realmName;
  23. public function __construct($realmName)
  24. {
  25. $this->realmName = $realmName;
  26. }
  27. public function start(Request $request, AuthenticationException $authException = null)
  28. {
  29. $response = new Response();
  30. $response->headers->set('WWW-Authenticate', sprintf('Basic realm="%s"', $this->realmName));
  31. $response->setStatusCode(401);
  32. return $response;
  33. }
  34. }