vendor/symfony/src/Symfony/Component/Security/Http/EntryPoint/RetryAuthenticationEntryPoint.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the Symfony package.
       
     5  *
       
     6  * (c) Fabien Potencier <fabien@symfony.com>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 namespace Symfony\Component\Security\Http\EntryPoint;
       
    13 
       
    14 use Symfony\Component\Security\Core\Exception\AuthenticationException;
       
    15 use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
       
    16 use Symfony\Component\HttpFoundation\Response;
       
    17 use Symfony\Component\HttpFoundation\RedirectResponse;
       
    18 use Symfony\Component\HttpFoundation\Request;
       
    19 
       
    20 /**
       
    21  * RetryAuthenticationEntryPoint redirects URL based on the configured scheme.
       
    22  *
       
    23  * This entry point is not intended to work with HTTP post requests.
       
    24  *
       
    25  * @author Fabien Potencier <fabien@symfony.com>
       
    26  */
       
    27 class RetryAuthenticationEntryPoint implements AuthenticationEntryPointInterface
       
    28 {
       
    29     private $httpPort;
       
    30     private $httpsPort;
       
    31 
       
    32     public function __construct($httpPort = 80, $httpsPort = 443)
       
    33     {
       
    34         $this->httpPort = $httpPort;
       
    35         $this->httpsPort = $httpsPort;
       
    36     }
       
    37 
       
    38     public function start(Request $request, AuthenticationException $authException = null)
       
    39     {
       
    40         $scheme = $request->isSecure() ? 'http' : 'https';
       
    41         if ('http' === $scheme && 80 != $this->httpPort) {
       
    42             $port = ':'.$this->httpPort;
       
    43         } elseif ('https' === $scheme && 443 != $this->httpsPort) {
       
    44             $port = ':'.$this->httpsPort;
       
    45         } else {
       
    46             $port = '';
       
    47         }
       
    48 
       
    49         $qs = $request->getQueryString();
       
    50         if (null !== $qs) {
       
    51             $qs = '?'.$qs;
       
    52         }
       
    53 
       
    54         $url = $scheme.'://'.$request->getHost().$port.$request->getBaseUrl().$request->getPathInfo().$qs;
       
    55 
       
    56         return new RedirectResponse($url, 301);
       
    57     }
       
    58 }