1: <?php
2:
3: namespace Mapbender\Component;
4: namespace Mapbender\Component;
5:
6: use Symfony\Component\Security\Core\Exception\AuthenticationException;
7: use Symfony\Component\Security\Http\EntryPoint\FormAuthenticationEntryPoint;
8: use Symfony\Component\HttpFoundation\Request;
9: use Symfony\Component\HttpFoundation\RedirectResponse;
10: use Symfony\Component\Security\Http\HttpUtils;
11: use Symfony\Component\HttpKernel\HttpKernelInterface;
12:
13: class UrlSessionFormEntryPoint extends FormAuthenticationEntryPoint {
14: private $loginPath;
15: private $useForward;
16: private $httpKernel;
17: private $httpUtils;
18:
19: public function __construct(HttpKernelInterface $kernel, HttpUtils $httpUtils, $loginPath, $useForward = false) {
20: $this->httpKernel = $kernel;
21: $this->httpUtils = $httpUtils;
22: $this->loginPath = $loginPath;
23: $this->useForward = (Boolean) $useForward;
24:
25: parent::__construct($kernel, $httpUtils, $loginPath, $useForward);
26: }
27:
28: 29: 30:
31: public function start(Request $request,
32: AuthenticationException $authException = null) {
33:
34: if ($this->useForward) {
35: $subRequest = $this->httpUtils->createRequest($request,
36: $this->loginPath);
37:
38: return $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
39: }
40:
41: $response = $this->httpUtils->createRedirectResponse($request, $this->loginPath);
42: $url = $response->headers->get('location');
43: $delim = strpos($url, '?') === False ? '?' : '&';
44: $sid = session_name() . '=' . $request->getSession()->getId();
45: $url .= $delim . $sid;
46:
47: return new RedirectResponse($url);
48: }
49: }
50:
51: