Вход Регистрация
Файл: symfony-2.7/src/Symfony/Component/Security/Http/EntryPoint/FormAuthenticationEntryPoint.php
Строк: 104
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyComponentSecurityHttpEntryPoint;

use 
SymfonyComponentHttpFoundationRequest;
use 
SymfonyComponentSecurityCoreExceptionAuthenticationException;
use 
SymfonyComponentSecurityHttpHttpUtils;
use 
SymfonyComponentHttpKernelHttpKernelInterface;

/**
 * FormAuthenticationEntryPoint starts an authentication via a login form.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class FormAuthenticationEntryPoint implements AuthenticationEntryPointInterface
{
    private 
$loginPath;
    private 
$useForward;
    private 
$httpKernel;
    private 
$httpUtils;

    
/**
     * Constructor.
     *
     * @param HttpKernelInterface $kernel
     * @param HttpUtils           $httpUtils  An HttpUtils instance
     * @param string              $loginPath  The path to the login form
     * @param bool                $useForward Whether to forward or redirect to the login form
     */
    
public function __construct(HttpKernelInterface $kernelHttpUtils $httpUtils$loginPath$useForward false)
    {
        
$this->httpKernel $kernel;
        
$this->httpUtils $httpUtils;
        
$this->loginPath $loginPath;
        
$this->useForward = (bool) $useForward;
    }

    
/**
     * {@inheritdoc}
     */
    
public function start(Request $requestAuthenticationException $authException null)
    {
        if (
$this->useForward) {
            
$subRequest $this->httpUtils->createRequest($request$this->loginPath);

            
$response $this->httpKernel->handle($subRequestHttpKernelInterface::SUB_REQUEST);
            if (
200 === $response->getStatusCode()) {
                
$response->headers->set('X-Status-Code'401);
            }

            return 
$response;
        }

        return 
$this->httpUtils->createRedirectResponse($request$this->loginPath);
    }
}
Онлайн: 0
Реклама