2010-10-19 12:06:43 +01:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-01-26 20:34:11 +00:00
|
|
|
namespace Symfony\Component\Security\Http\EntryPoint;
|
2010-10-19 12:06:43 +01:00
|
|
|
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2011-02-21 17:08:40 +00:00
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
2011-01-26 20:34:11 +00:00
|
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
2011-02-01 20:59:24 +00:00
|
|
|
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
|
2011-02-04 18:10:13 +00:00
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
2010-10-19 12:06:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* FormAuthenticationEntryPoint starts an authentication via a login form.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2010-10-19 12:06:43 +01:00
|
|
|
*/
|
|
|
|
class FormAuthenticationEntryPoint implements AuthenticationEntryPointInterface
|
|
|
|
{
|
2011-03-07 17:17:46 +00:00
|
|
|
private $loginPath;
|
|
|
|
private $useForward;
|
2011-03-18 17:26:55 +00:00
|
|
|
private $httpKernel;
|
2010-10-19 12:06:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2011-03-18 17:26:55 +00:00
|
|
|
* @param HttpKernelInterface $kernel
|
2011-04-23 16:05:44 +01:00
|
|
|
* @param string $loginPath The path to the login form
|
|
|
|
* @param Boolean $useForward Whether to forward or redirect to the login form
|
2010-10-19 12:06:43 +01:00
|
|
|
*/
|
2011-03-18 17:26:55 +00:00
|
|
|
public function __construct(HttpKernelInterface $kernel, $loginPath, $useForward = false)
|
2010-10-19 12:06:43 +01:00
|
|
|
{
|
2011-03-18 17:26:55 +00:00
|
|
|
$this->httpKernel = $kernel;
|
2010-10-19 12:06:43 +01:00
|
|
|
$this->loginPath = $loginPath;
|
|
|
|
$this->useForward = (Boolean) $useForward;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2011-03-18 17:26:55 +00:00
|
|
|
public function start(Request $request, AuthenticationException $authException = null)
|
2010-10-19 12:06:43 +01:00
|
|
|
{
|
2011-06-06 20:38:57 +01:00
|
|
|
$path = str_replace('{_locale}', $request->getSession()->getLocale(), $this->loginPath);
|
2010-10-19 12:06:43 +01:00
|
|
|
if ($this->useForward) {
|
2011-06-08 09:36:14 +01:00
|
|
|
$subRequest = Request::create($path, 'get', array(), $request->cookies->all(), array(), $request->server->all());
|
|
|
|
|
|
|
|
return $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
|
2010-10-19 12:06:43 +01:00
|
|
|
}
|
|
|
|
|
2011-06-06 20:38:57 +01:00
|
|
|
return new RedirectResponse(0 !== strpos($path, 'http') ? $request->getUriForPath($path) : $path, 302);
|
2010-10-19 12:06:43 +01:00
|
|
|
}
|
|
|
|
}
|